Optimization.SimplexLP Method

function SimplexLP(const A: TMtx; const b: TVec; const c: TVec; const AFinal: TMtx; const X: TVec; const Indexes: TVecInt; out SolutionType: TLPSolution; Minimize: Boolean; const Verbose: TStrings): Double;

Linear optimization by the (primal) Simplex method, A*x <= b.

#NameDescription
1AConstraint matrix of the A*x <= b relation
2A.Rows = number of constraints (m), A.Cols = number of variables (n).
3bRight-hand side vector of A*x <= b (length m)
4must be nonnegative.
5cCost vector in f = c^T x (length n).
6AFinalReturns the final simplex tableau.
7XReturns the optimal values of the decision variables (length n).
8IndexesReturns the indices of the basic variables in AFinal.
9SolutionTypeReturns the class of the LP solution.
10MinimizeIf true (default) minimize f, otherwise maximize f.
11VerboseIf assigned, each tableau and pivot is logged
12a TOptControl allows interruption/monitoring.

Returns: Double

Remarks:

Solves the standard-form linear programming problem

min (max) f(x)=c^Tx subject to A x <= b, x >= 0,

where the right-hand side vector b must be nonnegative, so that the origin is a feasible starting point. For negative components of b use

Optimization.SimplexDual (all rows `>=`) or
Optimization.SimplexTwoPhase (mixed relations).

Returns f = c^T x at the optimum, the optimal point in X (length A.Cols), the indices of the basic variables in Indexes, the final simplex tableau in AFinal and the solution class in SolutionType:

LPFiniteSolution: a bounded optimum was found.

LPUnboundedObjectiveFunction: the objective is unbounded; X is set to zero and -INF (minimize) or +INF (maximize) is returned. With b >= 0 the feasible region is never empty.

An exception is raised if c.Length differs from A.Cols, if b.Length differs from A.Rows, or if the internal iteration limit is exceeded. The computation runs in the precision of A.

Optionally, you can also assign a TOptControl object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring.

Examples
Uses MtxExpr, MtxExprInt, Optimization, Math387;

procedure Example;
var A, AF: Matrix;
b, c, x: Vector;
indexes: VectorInt;
sol: TLPSolution;
f: double;
begin
    A.SetIt(2,2,false,[6,4,
    1,2]);
    b.SetIt(false,[24,6]);
    c.SetIt(false,[5,4]);
    f := SimplexLP(A,b,c,AF,x,indexes,sol,false,nil);
    // f = 21, x = (3, 1.5)
end;
See Also: Optimization.SimplexDual, Optimization.SimplexTwoPhase, Optimization.CPA