Double SimplexLP(TMtx A, TVec b, TVec c, TMtx AFinal, TVec X, TVecInt Indexes, ref TLPSolution SolutionType, Boolean Minimize, TStrings Verbose)
Linear optimization by the (primal) Simplex method, A*x <= b.
| # | Name | Description |
|---|---|---|
| 1 | A | Constraint matrix of the A*x <= b relation |
| 2 | A.Rows = number of constraints (m), A.Cols = number of variables (n). | |
| 3 | b | Right-hand side vector of A*x <= b (length m) |
| 4 | must be nonnegative. | |
| 5 | c | Cost vector in f = c^T x (length n). |
| 6 | AFinal | Returns the final simplex tableau. |
| 7 | X | Returns the optimal values of the decision variables (length n). |
| 8 | Indexes | Returns the indices of the basic variables in AFinal. |
| 9 | SolutionType | Returns the class of the LP solution. |
| 10 | Minimize | If true (default) minimize f, otherwise maximize f. |
| 11 | Verbose | If assigned, each tableau and pivot is logged |
| 12 | a TOptControl allows interruption/monitoring. |
Returns: Double
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
Dew.Math.Units.Optimization.SimplexDual (all rows `>=`) or Dew.Math.Units.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 Dew.Math.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.
using Dew.Math;
using Dew.Math.Units;
namespace Dew.Examples
{
private void Example()
{
Matrix A = new Matrix(0,0);
Matrix Af = new Matrix(0,0);
Vector b = new Vector(0);
Vector c = new Vector(0);
Vector x = new Vector(0);
VectorInt indexes = new VectorInt(0);
TLPSolution sol;
A.SetIt(2,2,false, new double[] {6,4,
1,2});
b.SetIt(new double[] {24,6});
c.SetIt(new double[] {5,4});
double f = Optimization.SimplexLP(A,b,c,Af,x,indexes, out sol, false, null);
// f = 21, x = (3, 1.5)
}
}