Localsolver
5.5
|
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.
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. | |
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. | |
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. | |
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 | 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. |
|
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.
value | Value of the constant. |
|
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.
value | Value of the constant |
|
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.
op | Type of expression to create. |
|
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.
T0 | type of the operand to add. Types allowed: constant types or LSExpression. |
op | Type of expression to create. |
expr0 | Operand 0. |
|
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
T0 | type of the operand to add. Types allowed: constant types, LSExpression or iterator. |
T1 | type of the operand to add. Types allowed: constant types, LSExpression or iterator. |
op | Type of expression to create. |
expr0 | Operand 0. |
expr1 | Operand 1. |
|
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.
T0 | type of the operand to add. Types allowed: constant types or LSExpression. |
T1 | type of the operand to add. Types allowed: constant types or LSExpression. |
T2 | type of the operand to add. Types allowed: constant types or LSExpression. |
op | Type of expression to create. |
expr0 | Operand 0. |
expr1 | Operand 1. |
expr2 | Operand 2. |
|
inline |
Creates a boolean decision.
Binary decision variable with domain [0.1].
|
inline |
Creates a float decision.
Decision variable with domain [min,max].
|
inline |
Creates an integer decision.
Decision variable with domain [min,max].
|
inline |
Creates a sum expression.
|
inline |
Creates a sum expression.
|
inline |
Creates a sum expression.
|
inline |
Creates a substraction expression.
|
inline |
Creates a product expression.
|
inline |
Creates a product expression.
|
inline |
Creates a product expression.
|
inline |
Creates a maximum expression.
|
inline |
Creates a maximum expression.
|
inline |
Creates a maximum expression.
|
inline |
Creates a minimum expression.
|
inline |
Creates a minimum expression.
|
inline |
Creates a minimum expression.
|
inline |
Creates an OR expression.
|
inline |
Creates an OR expression.
|
inline |
Creates an AND expression.
|
inline |
Creates an AND expression.
|
inline |
Creates a XOR expression.
|
inline |
Creates a XOR expression.
|
inline |
Creates a NOT expression.
|
inline |
Creates an equality expression.
|
inline |
Creates a disequality expression.
|
inline |
Creates an inequality expression greater than or equal to.
|
inline |
Creates an inequality expression less than or equal to.
|
inline |
Creates an inequality expression greater than.
|
inline |
Creates an inequality expression less than.
|
inline |
Creates a ternary conditional expression.
|
inline |
Creates an absolute value expression.
|
inline |
Creates a distance expression.
|
inline |
Creates a division expression.
|
inline |
Creates a modulo expression.
|
inline |
Creates an array expression.
|
inline |
Creates a "at" expression for 1-dimensional array.
|
inline |
Creates a "at" expression for 2-dimensional array.
|
inline |
Creates a "at" expression for 3-dimensional array.
|
inline |
Creates an expression for the scalar product between two arrays.
|
inline |
Creates a ceil expression.
|
inline |
Creates a floor expression.
|
inline |
Creates a rounding expression.
|
inline |
Creates a square root expression.
|
inline |
Creates a log expression.
|
inline |
Creates an exponential expression.
|
inline |
Creates a power expression.
|
inline |
Creates a cosine expression.
|
inline |
Creates a sine expression.
|
inline |
Creates a tangent expression.
|
inline |
Creates a piecewise linear expression.
|
inline |
Creates a list decision with the given length.
|
inline |
Creates a count expression.
|
inline |
Creates an indexOf expression.
|
inline |
Creates a partition expression.
|
inline |
Creates a partition expression.
|
inline |
Creates a disjoint expression.
|
inline |
Creates a disjoint expression.
|
inline |
Gets the number of expressions added to this model.
|
inline |
Gets the expression with the given index in this model.
exprIndex | Index of the expression. |
|
inline |
Gets the expression with the given name.
Throws an exception if no expression with the given name exists.
name | Name. |
|
inline |
Gets the number of decisions in the model.
This corresponds to the number of decision variables declared in the model.
|
inline |
Gets the decision with the given index.
decisionIndex | Index of the decision. |
|
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).
expr | Expression. |
|
inline |
|
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.
expr | Expression. |
|
inline |
Removes the constraint at the given position in the list of constraints.
Only allowed in state S_Modeling.
constraintIndex | position of the constraint to remove. |
|
inline |
Gets the number of constraints added to this model.
|
inline |
Gets the constraint with the given index.
constraintIndex | Index of the constraint. |
|
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.
expr | Expression. |
direction | Optimization direction of this objective. |
|
inline |
Shortcut for addObjective(expr, OD_Minimize).
expr | Expression. |
|
inline |
Shortcut for addObjective(expr, OD_Maximize).
expr | Expression. |
|
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.
objectiveIndex | position of the objective to remove. |
|
inline |
Gets the number of objectives added to this model.
|
inline |
Gets the objective with the given index.
objectiveIndex | Index of the objective. |
|
inline |
Gets the direction of the objective with the given index.
objectiveIndex | Index of the objective. |
|
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.
|
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.
|
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.
|
inline |
Returns true if the model is closed, false otherwise.
|
inline |
Returns a string representation of this model.
This representation provides: