Double SimplexTwoPhase(TMtx A, TVec b, TVec c, String Relations, TMtx AFinal, TVec X, TVecInt Indexes, ref TLPSolution SolutionType, Boolean Minimize, TStrings Verbose)
Linear optimization by the Two-Phase Simplex algorithm (mixed relations).
| # | Name | Type | Description |
|---|---|---|---|
| 1 | A | TMtx | source TMtx |
| 2 | b | TVec | source TVec |
| 3 | c | TVec | source TVec |
| 4 | Relations | String | |
| 5 | AFinal | TMtx | source TMtx |
| 6 | X | TVec | source TVec |
| 7 | Indexes | TVecInt | source TVecInt |
| 8 | SolutionType | TLPSolution (ref) | |
| 9 | Minimize | Boolean | |
| 10 | Verbose | TStrings |
Returns: Double
Solves the general linear programming problem
min (max) f(x)=c^Tx subject to A x rel b, x >= 0,
where every row of the constraint system may use its own relation and the components of b may have any sign. The Relations string holds one sign per constraint row, in row order: '<' for <=, '=' for equality, and '>' for >=. For example, the relation string '<=>' means: first row <=, second row =, third row >=. All variables are constrained to be nonnegative. This is the general linear programming routine: Dew.Math.Units.Optimization.SimplexLP requires all rows to be <= with nonnegative b, and Dew.Math.Units.Optimization.SimplexDual requires all rows to be >=.
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.
LPEmptyFeasableRegion: no point satisfies the constraint system; X is set to zero and NAN is returned.
LPUnboundedObjectiveFunction: the objective is unbounded; X is set to zero and -INF (minimize) or +INF (maximize) is returned.
An exception is raised if c.Length differs from A.Cols, if b.Length or the length of Relations 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 AFinal = 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(4,4,false,new double[] {1,1,0,0,
0,2,0,-8,
0,1,-2,1,
1,1,1,1});
b.SetIt(new double[] {700,0,1,1});
c.SetIt(new double[] {1,1,2,-2});
double f = Optimization.SimplexTwoPhase(A,b,c,"<<>=",AFinal,x,indexes, out sol, true,null);
// f = -2, x = (0, 0, 0, 1)
}
}