LSModel Class¶
-
class LSModel¶
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:
- See:
Summary¶
Creates a constant expression representing the given value. |
|
Creates a constant expression representing the given value. |
|
Creates an expression of the given type, with the given ordered operands. |
|
Creates an integer external function. |
|
Creates a double external function. |
|
Creates an integer array external function. |
|
Creates a double array external function. |
|
Creates an external function. |
|
Creates an external function. |
|
Creates a lambda function. |
|
Creates a boolean decision. |
|
Creates a float decision. |
|
Creates an integer decision. |
|
Creates an interval decision included in [minStart, maxEnd). |
|
Creates a hull expression. |
|
Creates a hull expression. |
|
Creates a start expression. |
|
Creates an end expression. |
|
Creates a length expression. |
|
Creates a sum expression. |
|
Creates a substraction expression. |
|
Creates a call expression. |
|
Creates a product expression. |
|
Creates a maximum expression. |
|
Creates a minimum expression. |
|
Creates a OR expression. |
|
Creates an AND expression. |
|
Creates a XOR expression. |
|
Creates a NOT expression. |
|
Creates an equality expression. |
|
Creates a disequality expression. |
|
Creates an inequality expression greater than or equal to. |
|
Creates an inequality expression less than or equal to. |
|
Creates an inequality expression greater than. |
|
Creates an inequality expression less than. |
|
Creates a ternary conditional expression. |
|
Creates an absolute value expression. |
|
Creates a distance expression. |
|
Creates a division expression. |
|
Creates a modulo expression. |
|
Creates an array expression. |
|
Creates an AT expression for N-dimensional array. |
|
Creates an expression for the scalar product between two arrays. |
|
Creates a ceil expression. |
|
Creates a floor expression. |
|
Creates a rounding expression. |
|
Creates a square root expression. |
|
Creates a log expression. |
|
Creates an exponential expression. |
|
Creates a power expression. |
|
Creates a cosine expression. |
|
Creates a sine expression. |
|
Creates a tangent expression. |
|
Creates a piecewise linear expression. |
|
Creates a list decision with the given length. |
|
Creates a set decision with the given length. |
|
Creates a count expression. |
|
Creates an indexOf expression. |
|
Creates a distinct expression. |
|
Creates a distinct expression. |
|
Creates an intersection expression. |
|
Creates a contains expression. |
|
Creates a partition expression. |
|
Creates a partition expression. |
|
Creates a disjoint expression. |
|
Creates a disjoint expression. |
|
Creates a cover expression. |
|
Creates a cover expression. |
|
Creates a find expression. |
|
Creates a sort expression. |
|
Creates a sort expression. |
|
Creates an external function expression. |
|
Creates an external function expression. |
|
Creates an external function expression. |
|
Creates a lambda function expression. |
|
Creates a range expression, where expr0 is the lower bound (inclusive) and expr1 is the upper bound (exclusive). |
|
Gets the number of expressions added to this model. |
|
Gets the expression with the given index in this model. |
|
Gets the expression with the given name. |
|
Gets the number of decisions in the model. |
|
Gets the decision with the given index. |
|
Adds the given expression to the list of constraints. |
|
Shortcut for addConstraint(expr). |
|
Removes the given expression from the list of constraints. |
|
Removes the constraint at the given position in the list of constraints. |
|
Gets the number of constraints added to this model. |
|
Gets the constraint with the given index. |
|
Adds the given expression to the list of objectives to optimize. |
|
Shortcut for addObjective(expr, OD_Minimize). |
|
Shortcut for addObjective(expr, OD_Maximize). |
|
Removes the objective at the given position in the list of objectives. |
|
Gets the number of objectives added to this model. |
|
Gets the objective with the given index. |
|
Gets the direction of the objective with the given index. |
|
Gets the number of operands in the model. |
|
Closes the model. |
|
Reopens the model. |
|
Returns true if the model is closed, false otherwise. |
|
Returns a string representation of this model. |
Functions¶
-
LSExpression LSModel::createConstant(lsint value)¶
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:
value – Value of the constant.
- Returns:
Created constant expression.
-
LSExpression LSModel::createConstant(lsdouble value)¶
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:
value – Value of the constant
- Returns:
Created constant expression.
-
template<typename ...TN>
LSExpression createExpression(LSOperator op, TN... operands)¶ Creates an expression of the given type, with the given ordered operands. Only allowed in state
S_Modeling
. The operands can be doubles, integers or previously declared LSExpressions. It is also possible to use this method with iterators. In that case, you have to call this method with 2 operands exactly that must be iterators of the same type, pointing respectively to the initial and final positions of the operands.- Parameters:
TN – types of the operands to add. Types allowed: constant types, LSExpression or iterators.
op – Type of expression to create.
operands – Operands.
- Returns:
Created expression.
-
LSExpression LSModel::createExternalFunction(LSExternalFunction<lsint> *func)¶
Creates an integer external function. The argument must be derived from
LSExternalFunction
. When the external function is called, the argument values will be made accessible to your function through theLSExternalArgumentValues
.Once you have instantiated it, you have to use
call()
to call it in your model.- Parameters:
func – External function to call.
- Returns:
The expression associated to the function.
- See:
- See:
- Since:
9.5
-
LSExpression LSModel::createExternalFunction(LSExternalFunction<lsdouble> *func)¶
Creates a double external function. The argument must be derived from
LSExternalFunction
. When the external function is called, the argument values will be made accessible to your function through theLSExternalArgumentValues
.Once you have instantiated it, you have to use
call()
to call it in your model.- Parameters:
func – External function to call.
- Returns:
The expression associated to the function.
- See:
- See:
- Since:
9.5
-
LSExpression LSModel::createExternalFunction(LSArrayExternalFunction<lsint> *func)¶
Creates an integer array external function. The argument must be derived from
LSArrayExternalFunction
. When the external function is called, the argument values will be made accessible to your function through theLSExternalArgumentValues
.Once you have instantiated it, you have to use
call()
to call it in your model.- Parameters:
func – External function to call.
- Returns:
The expression associated to the function.
- See:
- See:
- Since:
11.0
-
LSExpression LSModel::createExternalFunction(LSArrayExternalFunction<lsdouble> *func)¶
Creates a double array external function. The argument must be derived from
LSArrayExternalFunction
. When the external function is called, the argument values will be made accessible to your function through theLSExternalArgumentValues
.Once you have instantiated it, you have to use
call()
to call it in your model.- Parameters:
func – External function to call.
- Returns:
The expression associated to the function.
- See:
- See:
- Since:
11.0
-
template<typename T, typename ...ARGS>
LSExpression LSModel::createExternalFunction(const std::function<T(ARGS...)> &func)¶ Creates an external function. The argument must be a std::function taking any combination of lsint and lsdouble arguments. When the external function is called, the argument values will be passed to your function as its arguments.
Once you have instantiated it, you have to use
call()
to call it in your model.- Parameters:
func – std::function to call. It must only accept lsint and lsdouble arguments.
- Returns:
The expression associated to the function.
- See:
- See:
- Since:
9.5
-
template<typename T>
LSExpression LSModel::createExternalFunction(const std::function<T(const LSExternalArgumentValues&)> &func)¶ Creates an external function. The argument must be a std::function taking a
LSExternalArgumentValues
as its argument. When the external function is called, the argument values will be made accessible to your function through this object.Once you have instantiated it, you have to use
call()
to call it in your model.- Parameters:
func – External function to call.
- Returns:
The expression associated to the function.
- See:
- See:
- Since:
9.5
-
template<typename A>
LSExpression LSModel::createLambdaFunction(const A &functor)¶ Creates a lambda function. A lambda function is a particular expression composed of two parts:
The arguments of the function (which are also LSExpressions of type
O_Argument
)The body of the function. The body is an LSExpression that will be used to evaluate the result of the function. The body can be any LSExpression composed of any operands and operators supported by LocalSolver. Thus, the body expression can use the arguments of the function but can also capture and refer to expressions declared outside of the function.
You have to provide the body of the function as a std::function (C++ function or lambda). Please note that the provided std::function will not be used directly during the solving process, but will be evaluated once by the API with a number of LSExpression of type
O_Argument
that corresponds to the number of arguments your std::function expects. The returned LSExpression resulting of this evaluation will be used as the body of the LocalSolver functionO_LambdaFunction
.- Parameters:
functor – Functor called to create the function.
- Returns:
The expression associated to the function.
- Since:
9.5
-
LSExpression LSModel::boolVar()¶
Creates a boolean decision. Binary decision variable with domain { 0, 1 }. This method is a shortcut for
createExpression(O_Bool)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
LSExpression LSModel::floatVar(lsdouble lb, lsdouble ub)¶
Creates a float decision. Decision variable with domain [lb, ub]. This method is a shortcut for
createExpression(O_Float, lb, ub)
.- Parameters:
lb – Lower bound of the decision variable.
ub – Upper bound of the decision variable.
- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
LSExpression LSModel::intVar(lsint lb, lsint ub)¶
Creates an integer decision. Decision variable with domain [lb, ub]. This method is a shortcut for
createExpression(O_Int, lb, ub)
.- Parameters:
lb – Lower bound of the decision variable.
ub – Upper bound of the decision variable.
- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
LSExpression LSModel::intervalVar(lsint minStart, lsint maxEnd)¶
Creates an interval decision included in [minStart, maxEnd). Start is inclusive and end is exclusive. This method is a shortcut for
createExpression(O_Interval, minStart, maxEnd)
.- Parameters:
minStart – Min start of the decision variable.
maxEnd – Max end of the decision variable.
- See:
- See:
LSModel::createExpression()
- Since:
12.0
-
template<typename ...TN>
LSExpression LSModel::hull(TN... operands)¶ Creates a hull expression. This method is a shortcut for
createExpression(O_Hull, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
13.0
-
template<typename T0>
LSExpression LSModel::hull(T0 array)¶ Creates a hull expression. This method is a shortcut for
createExpression(O_Hull, array)
.- See:
- See:
LSModel::createExpression()
- Since:
13.0
-
template<typename T0>
LSExpression LSModel::start(T0 expr0)¶ Creates a start expression. This method is a shortcut for
createExpression(O_Start, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
12.0
-
template<typename T0>
LSExpression LSModel::end(T0 expr0)¶ Creates an end expression. This method is a shortcut for
createExpression(O_End, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
12.0
-
template<typename T0>
LSExpression LSModel::length(T0 expr0)¶ Creates a length expression. This method is a shortcut for
createExpression(O_Length, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
12.0
-
template<typename ...TN>
LSExpression LSModel::sum(TN... operands)¶ Creates a sum expression. This method is a shortcut for
createExpression(O_Sum, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::sub(T0 expr0, T1 expr1)¶ Creates a substraction expression. This method is a shortcut for
createExpression(O_Sub, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename ...TN>
LSExpression LSModel::call(TN... operands)¶ Creates a call expression. The first operand must be an LSExpression of type
O_LambdaFunction
orO_ExternalFunction
. The other operands may be LSExpressions, booleans, integers, and doubles. They are passed to the function as arguments.This method is a shortcut for
createExpression(O_Call, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
6.0
-
template<typename ...TN>
LSExpression LSModel::prod(TN... operands)¶ Creates a product expression. This method is a shortcut for
createExpression(O_Prod, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename ...TN>
LSExpression LSModel::max(TN... operands)¶ Creates a maximum expression. This method is a shortcut for
createExpression(O_Max, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename ...TN>
LSExpression LSModel::min(TN... operands)¶ Creates a minimum expression. This method is a shortcut for
createExpression(O_Min, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename ...TN>
LSExpression LSModel::or_(TN... operands)¶ Creates a OR expression. This method is a shortcut for
createExpression(O_Or, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename ...TN>
LSExpression LSModel::and_(TN... operands)¶ Creates an AND expression. This method is a shortcut for
createExpression(O_And, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename ...TN>
LSExpression LSModel::xor_(TN... operands)¶ Creates a XOR expression. This method is a shortcut for
createExpression(O_Xor, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSModel::LSExpression not_(T0 expr0)¶ Creates a NOT expression. This method is a shortcut for
createExpression(O_Not, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::eq(T0 expr0, T1 expr1)¶ Creates an equality expression. This method is a shortcut for
createExpression(O_Eq, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::neq(T0 expr0, T1 expr1)¶ Creates a disequality expression. This method is a shortcut for
createExpression(O_Neq, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::geq(T0 expr0, T1 expr1)¶ Creates an inequality expression greater than or equal to. This method is a shortcut for
createExpression(O_Geq, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::leq(T0 expr0, T1 expr1)¶ Creates an inequality expression less than or equal to. This method is a shortcut for
createExpression(O_Leq, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::gt(T0 expr0, T1 expr1)¶ Creates an inequality expression greater than. This method is a shortcut for
createExpression(O_Gt, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::lt(T0 expr0, T1 expr1)¶ Creates an inequality expression less than. This method is a shortcut for
createExpression(O_Lt, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1, typename T2>
LSExpression LSModel::iif(T0 condExpr, T1 trueExpr, T2 falseExpr)¶ Creates a ternary conditional expression. This method is a shortcut for
createExpression(O_If, condExpr, trueExpr, falseExpr)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::abs(T0 expr0)¶ Creates an absolute value expression. This method is a shortcut for
createExpression(O_Abs, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::dist(T0 expr0, T1 expr1)¶ Creates a distance expression. This method is a shortcut for
createExpression(O_Dist, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::div(T0 expr0, T1 expr1)¶ Creates a division expression. This method is a shortcut for
createExpression(O_Div, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::mod(T0 expr0, T1 expr1)¶ Creates a modulo expression. This method is a shortcut for
createExpression(O_Mod, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename ...TN>
LSExpression LSModel::array(TN... operands)¶ Creates an array expression. This method is a shortcut for
createExpression(O_Array, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename ...TN>
LSExpression LSModel::at(T0 arrayExpr, TN... operands)¶ Creates an AT expression for N-dimensional array. This method is a shortcut for
createExpression(O_At, arrayExpr, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::scalar(T0 expr0, T1 expr1)¶ Creates an expression for the scalar product between two arrays. This method is a shortcut for
createExpression(O_Scalar, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::ceil(T0 expr0)¶ Creates a ceil expression. This method is a shortcut for
createExpression(O_Ceil, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::floor(T0 expr0)¶ Creates a floor expression. This method is a shortcut for
createExpression(O_Floor, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::round(T0 expr0)¶ Creates a rounding expression. This method is a shortcut for
createExpression(O_Round, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::sqrt(T0 expr0)¶ Creates a square root expression. This method is a shortcut for
createExpression(O_Sqrt, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::log(T0 expr0)¶ Creates a log expression. This method is a shortcut for
createExpression(O_Log, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::exp(T0 expr0)¶ Creates an exponential expression. This method is a shortcut for
createExpression(O_Exp, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::pow(T0 expr0, T1 expr1)¶ Creates a power expression. This method is a shortcut for
createExpression(O_Pow, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::cos(T0 expr0)¶ Creates a cosine expression. This method is a shortcut for
createExpression(O_Cos, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::sin(T0 expr0)¶ Creates a sine expression. This method is a shortcut for
createExpression(O_Sin, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::tan(T0 expr0)¶ Creates a tangent expression. This method is a shortcut for
createExpression(O_Tan, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1, typename T2>
LSExpression LSModel::piecewise(T0 expr0, T1 expr1, T2 expr2)¶ Creates a piecewise linear expression. This method is a shortcut for
createExpression(O_Piecewise, expr, expr1, expr2)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
LSExpression LSModel::listVar(lsint n)¶
Creates a list decision with the given length. A list is a ordered collection of integers within a domain [0, n-1]. This method is a shortcut for
createExpression(O_List, n)
.- Parameters:
n – Collection size.
- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
LSExpression LSModel::setVar(lsint n)¶
Creates a set decision with the given length. A set is a unordered collection of integers within a domain [0, n-1]. This method is a shortcut for
createExpression(O_Set, n)
.- Parameters:
n – Collection size.
- See:
- See:
LSModel::createExpression()
- Since:
8.0
-
template<typename T0>
LSExpression LSModel::count(T0 expr0)¶ Creates a count expression. This method is a shortcut for
createExpression(O_Count, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0, typename T1>
LSExpression LSModel::indexOf(T0 expr0, T1 expr1)¶ Creates an indexOf expression. This method is a shortcut for
createExpression(O_IndexOf, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::distinct(T0 array)¶ Creates a distinct expression. This method is a shortcut for
createExpression(O_Distinct, array)
.- See:
- See:
LSModel::createExpression()
- Since:
12.5
-
template<typename T0, typename T1>
LSExpression LSModel::distinct(T0 it, T1 func)¶ Creates a distinct expression. This method is a shortcut for
createExpression(O_Distinct, it, func)
.- See:
- See:
LSModel::createExpression()
- Since:
12.5
-
template<typename T0, typename T1>
LSExpression LSModel::intersection(T0 expr0, T1 expr1)¶ Creates an intersection expression. This method is a shortcut for
createExpression(O_Intersection, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
12.5
-
template<typename T0, typename T1>
LSExpression LSModel::contains(T0 e1, T1 e2)¶ Creates a contains expression. This method is a shortcut for
createExpression(O_Contains, e1, e2)
.- See:
- See:
LSModel::createExpression()
- Since:
7.5
-
template<typename ...TN>
LSExpression LSModel::partition(TN... operands)¶ Creates a partition expression. This method is a shortcut for
createExpression(O_Partition, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::partition(T0 array)¶ Creates a partition expression. This method is a shortcut for
createExpression(O_Partition, array)
.- See:
- See:
LSModel::createExpression()
- Since:
10.5
-
template<typename ...TN>
LSExpression LSModel::disjoint(TN... operands)¶ Creates a disjoint expression. This method is a shortcut for
createExpression(O_Disjoint, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
5.5
-
template<typename T0>
LSExpression LSModel::disjoint(T0 array)¶ Creates a disjoint expression. This method is a shortcut for
createExpression(O_Disjoint, array)
.- See:
- See:
LSModel::createExpression()
- Since:
10.5
-
template<typename ...TN>
LSExpression LSModel::cover(TN... operands)¶ Creates a cover expression. This method is a shortcut for
createExpression(O_Cover, operands)
.- See:
- See:
LSModel::createExpression()
- Since:
10.5
-
template<typename T0>
LSExpression LSModel::cover(T0 array)¶ Creates a cover expression. This method is a shortcut for
createExpression(O_Cover, array)
.- See:
- See:
LSModel::createExpression()
- Since:
10.5
-
template<typename T0, typename T1>
LSExpression LSModel::find(T0 expr0, T1 expr1)¶ Creates a find expression. This method is a shortcut for
createExpression(O_Find, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
10.5
-
template<typename T0>
LSExpression LSModel::sort(T0 expr0)¶ Creates a sort expression. This method is a shortcut for
createExpression(O_Sort, expr0)
.- See:
- See:
LSModel::createExpression()
- Since:
11.0
-
template<typename T0>
LSExpression LSModel::sort(T0 expr0, expr1)¶ Creates a sort expression. This method is a shortcut for
createExpression(O_Sort, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
12.5
-
template<typename T>
LSExpression LSModel::externalFunction(LSExternalFunction<T> *func)¶ Creates an external function expression. This method is a shortcut for
createExternalFunction(func)
.- See:
- See:
- Since:
9.5
-
template<typename T, typename ...ARGS>
LSExpression LSModel::externalFunction(const std::function<T(ARGS...)> &func)¶ Creates an external function expression. This method is a shortcut for
createExternalFunction(func)
.- See:
- See:
- Since:
9.5
-
template<typename T>
LSExpression LSModel::externalFunction(const std::function<T(const LSExternalArgumentValues&)> &func)¶ Creates an external function expression. This method is a shortcut for
createExternalFunction(func)
.- See:
- See:
- Since:
9.5
-
template<typename T>
LSExpression LSModel::lambdaFunction(T functor)¶ Creates a lambda function expression. This method is a shortcut for
createLambdaFunction(functor)
.- See:
- See:
- Since:
9.5
-
template<typename T0, typename T1>
LSExpression LSModel::range(T0 expr0, T1 expr1)¶ Creates a range expression, where expr0 is the lower bound (inclusive) and expr1 is the upper bound (exclusive). This method is a shortcut for
createExpression(O_Range, expr0, expr1)
.- See:
- See:
LSModel::createExpression()
- Since:
7.0
-
int LSModel::getNbExpressions() const¶
Gets the number of expressions added to this model.
- Returns:
Number of expressions.
-
LSExpression LSModel::getExpression(int exprIndex) const¶
Gets the expression with the given index in this model.
- Parameters:
exprIndex – Index of the expression.
- Returns:
Expression with the given index.
-
LSExpression LSModel::getExpression(const std::string &name) const¶
Gets the expression with the given name. Throws an exception if no expression with the given name exists.
- Parameters:
name – Name.
- Returns:
Expression with the given name.
-
int LSModel::getNbDecisions() const¶
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 LSModel::getDecision(int decisionIndex) const¶
Gets the decision with the given index.
- Parameters:
decisionIndex – Index of the decision.
- Returns:
Decision with the given index.
-
void LSModel::addConstraint(const LSExpression &expr)¶
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.- param expr:
Expression.
-
void LSModel::constraint(const LSExpression &expr)¶
Shortcut for
addConstraint(expr)
.- See:
- Parameters:
expr – Expression.
- Since:
5.5
-
void LSModel::removeConstraint(const LSExpression &expr)¶
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:
expr – Expression.
-
void LSModel::removeConstraint(int constraintIndex)¶
Removes the constraint at the given position in the list of constraints. Only allowed in state
S_Modeling
.- Since:
5.0
- Parameters:
constraintIndex – position of the constraint to remove.
-
int LSModel::getNbConstraints() const¶
Gets the number of constraints added to this model.
- Returns:
Number of constraints.
-
LSExpression LSModel::getConstraint(int constraintIndex) const¶
Gets the constraint with the given index.
- Parameters:
constraintIndex – Index of the constraint.
- Returns:
Constraint with the given index.
-
void LSModel::addObjective(const LSExpression &expr, LSObjectiveDirection direction)¶
Adds the given expression to the list of objectives to optimize. The 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:
expr – Expression.
direction – Optimization direction of this objective.
-
void LSModel::minimize(const LSExpression &expr)¶
Shortcut for
addObjective(expr, OD_Minimize)
.- See:
- Parameters:
expr – Expression.
- Since:
5.5
-
void LSModel::maximize(const LSExpression &expr)¶
Shortcut for
addObjective(expr, OD_Maximize)
.- See:
- Parameters:
expr – Expression.
- Since:
5.5
-
void LSModel::removeObjective(int objectiveIndex) const¶
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 (withLSPhase::setEnabled()
). Only allowed in stateS_Modeling
.- Since:
5.0
- Parameters:
objectiveIndex – position of the objective to remove.
-
LSExpression LSModel::getObjective(int objectiveIndex) const¶
Gets the objective with the given index.
- Parameters:
objectiveIndex – Index of the objective.
- Returns:
Objective with the given index.
-
LSObjectiveDirection LSModel::getObjectiveDirection(int objectiveIndex) const¶
Gets the direction of the objective with the given index.
- Parameters:
objectiveIndex – Index of the objective.
- Returns:
Objective direction.
-
int LSModel::getNbOperands() const¶
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 LSModel::close()¶
Closes the model. Only allowed in state
S_Modeling
. When this method is called, the solver is placed in stateS_Stopped
.Once the model is closed, no expressions, constraints or objectives can be added or removed unless the model is reopened. The model must be closed before starting its resolution.
-
void LSModel::open()¶
Reopens the model. Only allowed in state
S_Stopped
. When this method is called, the solver is placed in stateS_Modeling
.In this state, the model can be modified: it is possible to add new expressions, constraints or objectives, modify expression operands, and remove existing constraints and objectives. However, existing expressions cannot be deleted.