Localsolver  5.5
localsolver::LSModel Class Reference

Detailed Description

Mathematical optimization model.

A model is composed of expressions (some of which are decisions), organized as a tree. Then, some expressions of the model can be constrained or optimized. Once your optimization model is created and closed, the solver can be launched to resolve it. Note that you cannot modify a model which has been closed: you must reopen-it (with open()) or instantiate another LocalSolver environment to optimize another model.

See Also
LSExpression
LSOperator

Public Member Functions

LSExpression createConstant (lsint value)
 Creates a constant expression representing the given value.
LSExpression createConstant (lsdouble value)
 Creates a constant expression representing the given value.
LSExpression createExpression (LSOperator op)
 Creates an expression of the given type.
template<typename T0 >
LSExpression createExpression (LSOperator op, T0 expr0)
 Creates an expression of the given type, with the given operand.
template<typename T0 , typename T1 >
LSExpression createExpression (LSOperator op, T0 expr0, T1 expr1)
 Creates an expression of the given type, with the given ordered operands.
template<typename T0 , typename T1 , typename T2 >
LSExpression createExpression (LSOperator op, T0 expr0, T1 expr1, T2 expr2)
 Creates an expression of the given type, with the given ordered operands.
LSExpression boolVar ()
 Creates a boolean decision.
LSExpression floatVar (lsdouble min, lsdouble max)
 Creates a float decision.
LSExpression intVar (lsint min, lsint max)
 Creates an integer decision.
LSExpression sum ()
 Creates a sum expression.
template<typename T0 >
LSExpression sum (T0 expr0)
 Creates a sum expression.
template<typename T0 , typename T1 >
LSExpression sum (T0 expr0, T1 expr1)
 Creates a sum expression.
template<typename T0 , typename T1 >
LSExpression sub (T0 expr0, T1 expr1)
 Creates a substraction expression.
LSExpression prod ()
 Creates a product expression.
template<typename T0 >
LSExpression prod (T0 expr0)
 Creates a product expression.
template<typename T0 , typename T1 >
LSExpression prod (T0 expr0, T1 expr1)
 Creates a product expression.
LSExpression max ()
 Creates a maximum expression.
template<typename T0 >
LSExpression max (T0 expr0)
 Creates a maximum expression.
template<typename T0 , typename T1 >
LSExpression max (T0 expr0, T1 expr1)
 Creates a maximum expression.
LSExpression min ()
 Creates a minimum expression.
template<typename T0 >
LSExpression min (T0 expr0)
 Creates a minimum expression.
template<typename T0 , typename T1 >
LSExpression min (T0 expr0, T1 expr1)
 Creates a minimum expression.
LSExpression or_ ()
 Creates an OR expression.
template<typename T0 >
LSExpression or_ (T0 expr0)
 Creates an OR expression.
template<typename T0 , typename T1 >
LSExpression or_ (T0 expr0, T1 expr1)
 Creates an OR expression.
LSExpression and_ ()
 Creates an AND expression.
template<typename T0 >
LSExpression and_ (T0 expr0)
 Creates an AND expression.
template<typename T0 , typename T1 >
LSExpression and_ (T0 expr0, T1 expr1)
 Creates an AND expression.
LSExpression xor_ ()
 Creates a XOR expression.
template<typename T0 >
LSExpression xor_ (T0 expr0)
 Creates a XOR expression.
template<typename T0 , typename T1 >
LSExpression xor_ (T0 expr0, T1 expr1)
 Creates a XOR expression.
template<typename T0 >
LSExpression not_ (T0 expr0)
 Creates a NOT expression.
template<typename T0 , typename T1 >
LSExpression eq (T0 expr0, T1 expr1)
 Creates an equality expression.
template<typename T0 , typename T1 >
LSExpression neq (T0 expr0, T1 expr1)
 Creates a disequality expression.
template<typename T0 , typename T1 >
LSExpression geq (T0 expr0, T1 expr1)
 Creates an inequality expression greater than or equal to.
template<typename T0 , typename T1 >
LSExpression leq (T0 expr0, T1 expr1)
 Creates an inequality expression less than or equal to.
template<typename T0 , typename T1 >
LSExpression gt (T0 expr0, T1 expr1)
 Creates an inequality expression greater than.
template<typename T0 , typename T1 >
LSExpression lt (T0 expr0, T1 expr1)
 Creates an inequality expression less than.
template<typename T0 , typename T1 , typename T2 >
LSExpression iif (T0 expr0, T1 expr1, T2 expr2)
 Creates a ternary conditional expression.
template<typename T0 >
LSExpression abs (T0 expr0)
 Creates an absolute value expression.
template<typename T0 , typename T1 >
LSExpression dist (T0 expr0, T1 expr1)
 Creates a distance expression.
template<typename T0 , typename T1 >
LSExpression div (T0 expr0, T1 expr1)
 Creates a division expression.
template<typename T0 , typename T1 >
LSExpression mod (T0 expr0, T1 expr1)
 Creates a modulo expression.
LSExpression array ()
 Creates an array expression.
template<typename T0 , typename T1 >
LSExpression array (T0 expr0, T1 expr1)
 Creates an array expression.
template<typename T0 , typename T1 >
LSExpression at (T0 arrayExpr, T1 index1)
 Creates a "at" expression for 1-dimensional array.
template<typename T0 , typename T1 , typename T2 >
LSExpression at (T0 arrayExpr, T1 index1, T2 index2)
 Creates a "at" expression for 2-dimensional array.
template<typename T0 , typename T1 , typename T2 , typename T3 >
LSExpression at (T0 arrayExpr, T1 index1, T2 index2, T3 index3)
 Creates a "at" expression for 3-dimensional array.
template<typename T0 , typename T1 >
LSExpression scalar (T0 expr0, T1 expr1)
 Creates an expression for the scalar product between two arrays.
template<typename T0 >
LSExpression ceil (T0 expr0)
 Creates a ceil expression.
template<typename T0 >
LSExpression floor (T0 expr0)
 Creates a floor expression.
template<typename T0 >
LSExpression round (T0 expr0)
 Creates a rounding expression.
template<typename T0 >
LSExpression sqrt (T0 expr0)
 Creates a square root expression.
template<typename T0 >
LSExpression log (T0 expr0)
 Creates a log expression.
template<typename T0 >
LSExpression exp (T0 expr0)
 Creates an exponential expression.
template<typename T0 , typename T1 >
LSExpression pow (T0 expr0, T1 expr1)
 Creates a power expression.
template<typename T0 >
LSExpression cos (T0 expr0)
 Creates a cosine expression.
template<typename T0 >
LSExpression sin (T0 expr0)
 Creates a sine expression.
template<typename T0 >
LSExpression tan (T0 expr0)
 Creates a tangent expression.
template<typename T0 , typename T1 , typename T2 >
LSExpression piecewise (T0 expr0, T1 expr1, T2 expr2)
 Creates a piecewise linear expression.
LSExpression listVar (lsint a)
 Creates a list decision with the given length.
template<typename T0 >
LSExpression count (T0 expr0)
 Creates a count expression.
template<typename T0 , typename T1 >
LSExpression indexOf (T0 expr0, T1 expr1)
 Creates an indexOf expression.
LSExpression partition ()
 Creates a partition expression.
template<typename T0 , typename T1 >
LSExpression partition (T0 expr0, T1 expr1)
 Creates a partition expression.
LSExpression disjoint ()
 Creates a disjoint expression.
template<typename T0 , typename T1 >
LSExpression disjoint (T0 expr0, T1 expr1)
 Creates a disjoint expression.
int getNbExpressions () const
 Gets the number of expressions added to this model.
LSExpression getExpression (int exprIndex) const
 Gets the expression with the given index in this model.
LSExpression getExpression (const std::string &name) const
 Gets the expression with the given name.
int getNbDecisions () const
 Gets the number of decisions in the model.
LSExpression getDecision (int decisionIndex) const
 Gets the decision with the given index.
void addConstraint (const LSExpression &expr)
 Adds the given expression to the list of constraints.
void constraint (const LSExpression &expr)
 Shortcut for addConstraint(expr).
void removeConstraint (const LSExpression &expr)
 Removes the given expression from the list of constraints.
void removeConstraint (int constraintIndex)
 Removes the constraint at the given position in the list of constraints.
int getNbConstraints () const
 Gets the number of constraints added to this model.
LSExpression getConstraint (int constraintIndex) const
 Gets the constraint with the given index.
void addObjective (const LSExpression &expr, LSObjectiveDirection direction)
 Adds the given expression to the list of objectives to optimize.
void minimize (const LSExpression &expr)
 Shortcut for addObjective(expr, OD_Minimize).
void maximize (const LSExpression &expr)
 Shortcut for addObjective(expr, OD_Maximize).
void removeObjective (int objectiveIndex) const
 Removes the objective at the given position in the list of objectives.
int getNbObjectives () const
 Gets the number of objectives added to this model.
LSExpression getObjective (int objectiveIndex) const
 Gets the objective with the given index.
LSObjectiveDirection getObjectiveDirection (int objectiveIndex) const
 Gets the direction of the objective with the given index.
int getNbOperands () const
 Gets the number of operands in the model.
void close ()
 Closes the model.
void open ()
 Opens or reopens the model.
bool isClosed () const
 Returns true if the model is closed, false otherwise.
std::string toString () const
 Returns a string representation of this model.
 ~LSModel ()
 LSModel ()
 LSModel (const LSModel &other)
LSModeloperator= (const LSModel &other)

Constructor & Destructor Documentation

localsolver::LSModel::~LSModel ( )
inline
localsolver::LSModel::LSModel ( )
inline
localsolver::LSModel::LSModel ( const LSModel other)
inline

Member Function Documentation

LSExpression localsolver::LSModel::createConstant ( lsint  value)
inline

Creates a constant expression representing the given value.

Only allowed in state S_Modeling. Note that if a constant has been already created with the same value, this method can return the same expression, but it is not guaranteed. The exact behavior is implementation defined.

Parameters
valueValue of the constant.
Returns
Created constant expression.
LSExpression localsolver::LSModel::createConstant ( lsdouble  value)
inline

Creates a constant expression representing the given value.

Only allowed in state S_Modeling. Note that if a constant has been already created with the same value, this method can return the same expression, but it is not guaranteed. The exact behavior is implementation defined.

Parameters
valueValue of the constant
Returns
Created constant expression.
LSExpression localsolver::LSModel::createExpression ( LSOperator  op)
inline

Creates an expression of the given type.

The expression is created without operand. Only allowed in state S_Modeling. This method cannot be used to create constants: use createConstant(lsint) or createConstant(lsdouble) instead.

Parameters
opType of expression to create.
Returns
Created expression.
template<typename T0 >
LSExpression localsolver::LSModel::createExpression ( LSOperator  op,
T0  expr0 
)
inline

Creates an expression of the given type, with the given operand.

Only allowed in state S_Modeling. Useful for creating unary expressions. The operand can be a double, an integer or a previously declared LSExpression.

Template Parameters
T0type of the operand to add. Types allowed: constant types or LSExpression.
Parameters
opType of expression to create.
expr0Operand 0.
Returns
Created expression.
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::createExpression ( LSOperator  op,
T0  expr0,
T1  expr1 
)
inline

Creates an expression of the given type, with the given ordered operands.

Only allowed in state S_Modeling. Useful for creating binary expressions.

The operands can be doubles, integers or previously declared LSExpressions. It is also possible to use this method with iterators. In that case, expr0 and expr1 must be iterators of the same type, pointing respectively to the initial and final positions of the operands

Template Parameters
T0type of the operand to add. Types allowed: constant types, LSExpression or iterator.
T1type of the operand to add. Types allowed: constant types, LSExpression or iterator.
Parameters
opType of expression to create.
expr0Operand 0.
expr1Operand 1.
Returns
Created expression.
template<typename T0 , typename T1 , typename T2 >
LSExpression localsolver::LSModel::createExpression ( LSOperator  op,
T0  expr0,
T1  expr1,
T2  expr2 
)
inline

Creates an expression of the given type, with the given ordered operands.

Only allowed in state S_Modeling. Useful for creating ternary expressions (in particular, O_If expressions). The operands can be doubles, integers or previously declared LSExpressions.

Template Parameters
T0type of the operand to add. Types allowed: constant types or LSExpression.
T1type of the operand to add. Types allowed: constant types or LSExpression.
T2type of the operand to add. Types allowed: constant types or LSExpression.
Parameters
opType of expression to create.
expr0Operand 0.
expr1Operand 1.
expr2Operand 2.
Returns
Created expression.
LSExpression localsolver::LSModel::boolVar ( )
inline

Creates a boolean decision.

Binary decision variable with domain [0.1].

See Also
O_Bool
Since
5.5
LSExpression localsolver::LSModel::floatVar ( lsdouble  min,
lsdouble  max 
)
inline

Creates a float decision.

Decision variable with domain [min,max].

See Also
O_Float
Since
5.5
LSExpression localsolver::LSModel::intVar ( lsint  min,
lsint  max 
)
inline

Creates an integer decision.

Decision variable with domain [min,max].

See Also
O_Int
Since
5.5
LSExpression localsolver::LSModel::sum ( )
inline

Creates a sum expression.

See Also
O_Sum
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::sum ( T0  expr0)
inline

Creates a sum expression.

See Also
O_Sum
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::sum ( T0  expr0,
T1  expr1 
)
inline

Creates a sum expression.

See Also
O_Sum
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::sub ( T0  expr0,
T1  expr1 
)
inline

Creates a substraction expression.

See Also
O_Sub
Since
5.5
LSExpression localsolver::LSModel::prod ( )
inline

Creates a product expression.

See Also
O_Prod
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::prod ( T0  expr0)
inline

Creates a product expression.

See Also
O_Prod
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::prod ( T0  expr0,
T1  expr1 
)
inline

Creates a product expression.

See Also
O_Prod
Since
5.5
LSExpression localsolver::LSModel::max ( )
inline

Creates a maximum expression.

See Also
O_Max
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::max ( T0  expr0)
inline

Creates a maximum expression.

See Also
O_Max
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::max ( T0  expr0,
T1  expr1 
)
inline

Creates a maximum expression.

See Also
O_Max
Since
5.5
LSExpression localsolver::LSModel::min ( )
inline

Creates a minimum expression.

See Also
O_Min
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::min ( T0  expr0)
inline

Creates a minimum expression.

See Also
O_Min
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::min ( T0  expr0,
T1  expr1 
)
inline

Creates a minimum expression.

See Also
O_Min
Since
5.5
LSExpression localsolver::LSModel::or_ ( )
inline

Creates an OR expression.

See Also
O_Or
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::or_ ( T0  expr0)
inline

Creates an OR expression.

See Also
O_Or
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::or_ ( T0  expr0,
T1  expr1 
)
inline

Creates an OR expression.

See Also
O_Or
Since
5.5
LSExpression localsolver::LSModel::and_ ( )
inline

Creates an AND expression.

See Also
O_And
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::and_ ( T0  expr0)
inline

Creates an AND expression.

See Also
O_And
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::and_ ( T0  expr0,
T1  expr1 
)
inline

Creates an AND expression.

See Also
O_And
Since
5.5
LSExpression localsolver::LSModel::xor_ ( )
inline

Creates a XOR expression.

See Also
O_Xor
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::xor_ ( T0  expr0)
inline

Creates a XOR expression.

See Also
O_Xor
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::xor_ ( T0  expr0,
T1  expr1 
)
inline

Creates a XOR expression.

See Also
O_Xor
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::not_ ( T0  expr0)
inline

Creates a NOT expression.

See Also
O_Not
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::eq ( T0  expr0,
T1  expr1 
)
inline

Creates an equality expression.

See Also
O_Eq
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::neq ( T0  expr0,
T1  expr1 
)
inline

Creates a disequality expression.

See Also
O_Neq
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::geq ( T0  expr0,
T1  expr1 
)
inline

Creates an inequality expression greater than or equal to.

See Also
O_Geq
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::leq ( T0  expr0,
T1  expr1 
)
inline

Creates an inequality expression less than or equal to.

See Also
O_Leq
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::gt ( T0  expr0,
T1  expr1 
)
inline

Creates an inequality expression greater than.

See Also
O_Gt
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::lt ( T0  expr0,
T1  expr1 
)
inline

Creates an inequality expression less than.

See Also
O_Lt
Since
5.5
template<typename T0 , typename T1 , typename T2 >
LSExpression localsolver::LSModel::iif ( T0  expr0,
T1  expr1,
T2  expr2 
)
inline

Creates a ternary conditional expression.

See Also
O_If
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::abs ( T0  expr0)
inline

Creates an absolute value expression.

See Also
O_Abs
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::dist ( T0  expr0,
T1  expr1 
)
inline

Creates a distance expression.

See Also
O_Dist
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::div ( T0  expr0,
T1  expr1 
)
inline

Creates a division expression.

See Also
O_Div
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::mod ( T0  expr0,
T1  expr1 
)
inline

Creates a modulo expression.

See Also
O_Mod
Since
5.5
LSExpression localsolver::LSModel::array ( )
inline

Creates an array expression.

See Also
O_Array
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::array ( T0  expr0,
T1  expr1 
)
inline

Creates an array expression.

See Also
O_Array
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::at ( T0  arrayExpr,
T1  index1 
)
inline

Creates a "at" expression for 1-dimensional array.

See Also
O_At
Since
5.5
template<typename T0 , typename T1 , typename T2 >
LSExpression localsolver::LSModel::at ( T0  arrayExpr,
T1  index1,
T2  index2 
)
inline

Creates a "at" expression for 2-dimensional array.

See Also
O_At
Since
5.5
template<typename T0 , typename T1 , typename T2 , typename T3 >
LSExpression localsolver::LSModel::at ( T0  arrayExpr,
T1  index1,
T2  index2,
T3  index3 
)
inline

Creates a "at" expression for 3-dimensional array.

See Also
O_At
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::scalar ( T0  expr0,
T1  expr1 
)
inline

Creates an expression for the scalar product between two arrays.

See Also
O_Scalar
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::ceil ( T0  expr0)
inline

Creates a ceil expression.

See Also
O_Ceil
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::floor ( T0  expr0)
inline

Creates a floor expression.

See Also
O_Floor
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::round ( T0  expr0)
inline

Creates a rounding expression.

See Also
O_Round
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::sqrt ( T0  expr0)
inline

Creates a square root expression.

See Also
O_Sqrt
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::log ( T0  expr0)
inline

Creates a log expression.

See Also
O_Log
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::exp ( T0  expr0)
inline

Creates an exponential expression.

See Also
O_Exp
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::pow ( T0  expr0,
T1  expr1 
)
inline

Creates a power expression.

See Also
O_Pow
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::cos ( T0  expr0)
inline

Creates a cosine expression.

See Also
O_Cos
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::sin ( T0  expr0)
inline

Creates a sine expression.

See Also
O_Sin
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::tan ( T0  expr0)
inline

Creates a tangent expression.

See Also
O_Tan
Since
5.5
template<typename T0 , typename T1 , typename T2 >
LSExpression localsolver::LSModel::piecewise ( T0  expr0,
T1  expr1,
T2  expr2 
)
inline

Creates a piecewise linear expression.

See Also
O_Piecewise
Since
5.5
LSExpression localsolver::LSModel::listVar ( lsint  a)
inline

Creates a list decision with the given length.

See Also
O_List
Since
5.5
template<typename T0 >
LSExpression localsolver::LSModel::count ( T0  expr0)
inline

Creates a count expression.

See Also
O_Count
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::indexOf ( T0  expr0,
T1  expr1 
)
inline

Creates an indexOf expression.

See Also
O_IndexOf
Since
5.5
LSExpression localsolver::LSModel::partition ( )
inline

Creates a partition expression.

See Also
O_Partition
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::partition ( T0  expr0,
T1  expr1 
)
inline

Creates a partition expression.

See Also
O_Partition
Since
5.5
LSExpression localsolver::LSModel::disjoint ( )
inline

Creates a disjoint expression.

See Also
O_Disjoint
Since
5.5
template<typename T0 , typename T1 >
LSExpression localsolver::LSModel::disjoint ( T0  expr0,
T1  expr1 
)
inline

Creates a disjoint expression.

See Also
O_Disjoint
Since
5.5
int localsolver::LSModel::getNbExpressions ( ) const
inline

Gets the number of expressions added to this model.

Returns
Number of expressions.
LSExpression localsolver::LSModel::getExpression ( int  exprIndex) const
inline

Gets the expression with the given index in this model.

Parameters
exprIndexIndex of the expression.
Returns
Expression with the given index.
LSExpression localsolver::LSModel::getExpression ( const std::string &  name) const
inline

Gets the expression with the given name.

Throws an exception if no expression with the given name exists.

Parameters
nameName.
Returns
Expression with the given name.
int localsolver::LSModel::getNbDecisions ( ) const
inline

Gets the number of decisions in the model.

This corresponds to the number of decision variables declared in the model.

Returns
Number of decisions.
LSExpression localsolver::LSModel::getDecision ( int  decisionIndex) const
inline

Gets the decision with the given index.

Parameters
decisionIndexIndex of the decision.
Returns
Decision with the given index.
void localsolver::LSModel::addConstraint ( const LSExpression expr)
inline

Adds the given expression to the list of constraints.

It means that the value of this expression must be constrained to be equal to 1 in any solution found by the solver. Hence, only boolean expressions (that is, expressions whose value is boolean) can be constrained. Only allowed in state S_Modeling. If the expression is already a constraint, this method does nothing and returns immediately.

Try to avoid hard constraints as much as possible, because LocalSolver (and more generally local search) is not suited for solving hardly constrained problems. In particular, banish constraints that are not surely satisfied in practice. Ideally, only combinatorial constraints (which induce the combinatorial structure of your problem) have to be set. All the other constraints can be relaxed as primary objectives in order to be "softly" satisfied (goal programming). For instance, constraint a <= b can be transformed into minimize max(b-a, 0).

Parameters
exprExpression.
void localsolver::LSModel::constraint ( const LSExpression expr)
inline

Shortcut for addConstraint(expr).

See Also
addConstraint
Parameters
exprExpression.
Since
5.5
void localsolver::LSModel::removeConstraint ( const LSExpression expr)
inline

Removes the given expression from the list of constraints.

If the expression was not constrained, this method does nothing and returns immediately. Only allowed in state S_Modeling.

Since
5.0
Parameters
exprExpression.
void localsolver::LSModel::removeConstraint ( int  constraintIndex)
inline

Removes the constraint at the given position in the list of constraints.

Only allowed in state S_Modeling.

Since
5.0
Parameters
constraintIndexposition of the constraint to remove.
int localsolver::LSModel::getNbConstraints ( ) const
inline

Gets the number of constraints added to this model.

Returns
Number of constraints.
LSExpression localsolver::LSModel::getConstraint ( int  constraintIndex) const
inline

Gets the constraint with the given index.

Parameters
constraintIndexIndex of the constraint.
Returns
Constraint with the given index.
void localsolver::LSModel::addObjective ( const LSExpression expr,
LSObjectiveDirection  direction 
)
inline

Adds the given expression to the list of objectives to optimize.

A same expression can be added more than once. Only allowed in state S_Modeling. Note that the objectives will be optimized in the order in which they have been added to the model. It is useful for lexicographic multiobjective optimization, and more particularly for goal programming.

Parameters
exprExpression.
directionOptimization direction of this objective.
void localsolver::LSModel::minimize ( const LSExpression expr)
inline

Shortcut for addObjective(expr, OD_Minimize).

See Also
addObjective
Parameters
exprExpression.
Since
5.5
void localsolver::LSModel::maximize ( const LSExpression expr)
inline

Shortcut for addObjective(expr, OD_Maximize).

See Also
addObjective
Parameters
exprExpression.
Since
5.5
void localsolver::LSModel::removeObjective ( int  objectiveIndex) const
inline

Removes the objective at the given position in the list of objectives.

Note that the objectives created after the removed one have their index decreased by 1. Phases are not modified when an objective is removed. It is the user's responsibility to change the objective index of each phase to keep it coherent (with LSPhase#setOptimizedObjective), or to disable it (with LSPhase#setEnabled). Only allowed in state S_Modeling.

Since
5.0
Parameters
objectiveIndexposition of the objective to remove.
int localsolver::LSModel::getNbObjectives ( ) const
inline

Gets the number of objectives added to this model.

Returns
Number of objectives.
LSExpression localsolver::LSModel::getObjective ( int  objectiveIndex) const
inline

Gets the objective with the given index.

Parameters
objectiveIndexIndex of the objective.
Returns
Objective with the given index.
LSObjectiveDirection localsolver::LSModel::getObjectiveDirection ( int  objectiveIndex) const
inline

Gets the direction of the objective with the given index.

Parameters
objectiveIndexIndex of the objective.
Returns
Objective direction.
int localsolver::LSModel::getNbOperands ( ) const
inline

Gets the number of operands in the model.

This corresponds to the number of operands for all expressions declared in the model. It is an analog of the number of non zeros in matrix model encountered in mathematical programming: it gives an hint about the size and the density of your model.

Returns
Number of operands.
void localsolver::LSModel::close ( )
inline

Closes the model.

Only allowed in state S_Modeling. Once the model is closed, no expression, constraints or objectives can be added. The model must be closed before starting its resolution.

void localsolver::LSModel::open ( )
inline

Opens or reopens the model.

When this method is called, the solver is placed in state S_Modeling. Only allowed in state S_Stopped.

bool localsolver::LSModel::isClosed ( ) const
inline

Returns true if the model is closed, false otherwise.

Returns
True if the model is closed.
std::string localsolver::LSModel::toString ( ) const
inline

Returns a string representation of this model.

This representation provides:

  • The number of expressions, decisions, constraints, and objectives.
  • The density of the model. Useful for debugging or logging purposes.
Returns
String representation.
LSModel& localsolver::LSModel::operator= ( const LSModel other)
inline