Linear and integer programming¶
Exact linear and mixed-integer programming over the rationals. Every status is
returned with a certificate that LPResult.verify() re-checks exactly; no
step uses floating point. See the user-guide chapter Exact linear and integer
programming for the certificate conventions.
- alkahest.linprog(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None, bounds=None, sense='min') LPResult¶
Minimise (
sense="max": maximise)c @ xsubject toA_ub @ x <= b_ub,A_eq @ x == b_eqandbounds— SciPy’s calling convention. Coefficients areint,Fraction,"p/q"strings or rationalExpr; a float raisesE-LP-002.boundsis one(lower, upper)pair for all variables or one per variable,None/±inffor no bound, default(0, None).Two-phase dense simplex with Bland’s rule (cannot cycle); the active budget is checked at every pivot.
- Returns:
- Raises:
LinprogError –
E-LP-001,E-LP-002,E-LP-006BudgetExceededError – the active budget tripped
Example:
r = linprog([3, 5], A_ub=[[1, 0], [0, 2], [3, 2]], b_ub=[4, 12, 18], sense="max") r.x, r.fun, r.ineqlin # ([2, 6], 36, [0, Fraction(3, 2), 1])
- alkahest.milp(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None, bounds=None, integrality=None, sense='min', max_nodes=100000) MILPResult¶
Branch and bound on top of
linprog()(depth-first to a first incumbent, then best-bound).integralityis one0/1flag per variable or a single bool; the default makes every variable an integer.- Returns:
MILPResult—"optimal"(closed tree,gap == 0),"infeasible", or"unbounded"(integer point and integral ray)- Raises:
LinprogError –
E-LP-005atmax_nodes(carriesincumbent,incumbent_fun,bound,nodes), plus the codes oflinprog()BudgetExceededError – the budget tripped (same attachments)
Example:
r = milp([10, 13, 7, 8], A_ub=[[4, 6, 3, 5]], b_ub=[12], bounds=(0, 1), sense="max") r.x, r.fun # ([1, 0, 1, 1], 25)
- alkahest.linprog_expr(objective, constraints, vars, sense='min', integer=None, max_nodes=100000) LPResult | MILPResult¶
The same, stated with expressions: an affine
objectiveand a list ofpool.le/pool.ge/pool.pred_eqrelations (or anAndof them). Variables are free unless constrained.integer=Trueor a list of variables solves a MILP.result.solutionmaps variables to values;result.program()shows the rows the relations became.- Raises:
LinprogError –
E-LP-003(not affine / unknown symbol),E-LP-002(float or irrational coefficient),E-LP-004(strict inequality or non-relation)
- class alkahest.LPResult¶
status("optimal"/"infeasible"/"unbounded"),success,x,fun; dual multipliersineqlin,eqlin,lower,upper(optimal, SciPymarginalsconvention);farkas(infeasible: dict of row and bound weights);ray(unbounded);solution;program();verify().
- class alkahest.MILPResult¶
status,success,x,fun,bound,gap(0when optimal),nodes,ray,solution,program(),verify().