To solve a linear programming problem. More...
Public Types | |
enum | Setting { OBJECTIVE = 0, LE_CONSTRAINT = 1, GE_CONSTRAINT = 2, EQ_CONSTRAINT = 3 } |
Public Member Functions | |
LPSolver () | |
Default constructor. | |
LPSolver (int nv, int nb_le, int nb_ge, int nb_eq) | |
Constructor using Linear Program data. More... | |
~LPSolver () | |
Destructor. | |
void | setSize (int nv, int nb_le, int nb_ge, int nb_eq) |
Set optimization parameters. More... | |
void | set (Vect< real_t > &x) |
vector of optimization variables More... | |
void | set (Setting opt, const Vect< real_t > &a, real_t b=0.0) |
Set optimization data. More... | |
int | run () |
Run the linear program solver. More... | |
real_t | getObjective () const |
Return objective. More... | |
Friends | |
ostream & | operator<< (ostream &s, const LPSolver &os) |
Output class information. | |
To solve a linear programming problem.
The Linear Program reads:
Minimise: d(1)*x(1) + ... + d(n)*x(n) + e Subject to the constraints: A(i,1)*x(1) + ... + A(i,n)*x(n) <= a(i) i=1,...,n_le B(i,1)*x(1) + ... + B(i,n)*x(n) >= b(i) i=1,...,n_ge C(i,1)*x(1) + ... + C(i,n)*x(n) = c(i) i=1,...,n_eq x(i) >= 0, 1<=i<=n
Solution is held by the Simplex method Reference: "Numerical Recipes By W.H. Press, B. P. Flannery, S.A. Teukolsky and W.T. Vetterling, Cambridge University Press, 1986"
C-implementation copied from J-P Moreau, Paris
enum Setting |
LPSolver | ( | int | nv, |
int | nb_le, | ||
int | nb_ge, | ||
int | nb_eq | ||
) |
Constructor using Linear Program data.
[in] | nv | Number of optimization variables |
[in] | nb_le | Number of '<=' inequality constraints |
[in] | nb_ge | Number of '>=' inequality constraints |
[in] | nb_eq | Number of '=' equality constraints |
real_t getObjective | ( | ) | const |
Return objective.
Once execution is complete, this function returns optimal value of objective
int run | ( | ) |
Run the linear program solver.
This function runs the linear programming solver using the Simplex algorithm
vector of optimization variables
[in] | x | Vector of optimization variables. Its size must be at least equal to number of optimization variables |
Set optimization data.
This function enables providing all optimization data. It has to be used for the objectice function and once for each constraint.
[in] | opt | Option for data, to choose among enumerated values:
|
[in] | a | Vector coefficients if the chosen function. If opt==OBJECTIVE , vector components are the coefficients multiplying the variables in the objective function. if xx_CONSTRAINT , vector components are the coefficients multiplying the variables in the corresponding constraint. |
[in] | b | Constant value in the objective function or in a constraint. Its default value is 0.0 |
void setSize | ( | int | nv, |
int | nb_le, | ||
int | nb_ge, | ||
int | nb_eq | ||
) |
Set optimization parameters.
[in] | nv | Number of optimization variables |
[in] | nb_le | Number of '<=' inequality constraints |
[in] | nb_ge | Number of '>=' inequality constraints |
[in] | nb_eq | Number of '=' equality constraints |