 An Object Oriented Finite Element Library

LPSolver Class Reference

To solve a linear programming problem. More...

`#include <LPSolver.h>`

## 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...

## Detailed Description

To solve a linear programming problem.

```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

## ◆ Setting

 enum Setting

Selects setting option: Objective or Constraints

Enumerator
OBJECTIVE

Objective function coefficients

LE_CONSTRAINT

'Less or Equal' constraint coefficients

GE_CONSTRAINT

'Greater or Equal' constraint coefficients

EQ_CONSTRAINT

'Equality' constraint coefficients

## ◆ LPSolver()

 LPSolver ( int nv, int nb_le, int nb_ge, int nb_eq )

Constructor using Linear Program data.

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

## ◆ getObjective()

 real_t getObjective ( ) const

Return objective.

Once execution is complete, this function returns optimal value of objective

## ◆ run()

 int run ( )

Run the linear program solver.

This function runs the linear programming solver using the Simplex algorithm

Returns
0 if process is complete, >0 otherwise

## ◆ set() [1/2]

 void set ( Setting opt, const Vect< real_t > & a, real_t b = `0.0` )

Set optimization data.

This function enables providing all optimization data. It has to be used for the objectice function and once for each constraint.

Parameters
 [in] opt Option for data, to choose among enumerated values: OBJECTIVE To set objective function to minimize LE_CONSTRAINT To set a '<=' inequality constraint GE_CONSTRAINT To set a '>=' inequality constraint EQ_CONSTRAINT To set an equality constraint [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

## ◆ set() [2/2]

 void set ( Vect< real_t > & x )

vector of optimization variables

Parameters
 [in] x Vector of optimization variables. Its size must be at least equal to number of optimization variables

## ◆ setSize()

 void setSize ( int nv, int nb_le, int nb_ge, int nb_eq )

Set optimization parameters.

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