cpnlinctr
cpnlinctr |
Purpose
Non-linear constraints are arithmetic constraints over decision variables. Non-linear constraints are defined with non-linear expressions combined by arithmetic operators such as =, ≤, and ≥. Non-linear expressions of decision variables have the type cpnlinexp. Typically, these objects result as intermediate objects in the definition of non-linear constraints.
Non-linear expressions of decision variables are obtained by applying the operators +, -, *, div, or functions like ln, exp, abs to decision variables and numeric values. The standard priority rules used by Mosel apply to the evaluation order of the arithmetic operators. Brackets may be used in the definition of non-linear expressions to change this order. The following are examples of valid non-linear expressions:
Non-linear expressions of decision variables are obtained by applying the operators +, -, *, div, or functions like ln, exp, abs to decision variables and numeric values. The standard priority rules used by Mosel apply to the evaluation order of the arithmetic operators. Brackets may be used in the definition of non-linear expressions to change this order. The following are examples of valid non-linear expressions:
declarations y: cpvar x1,x2,x3,x4,x5: cpfloatvar end-declarations 0.4*x3*x5 + 0.1*x3*x4 >= 10.7 x1^2 = y exp(x3-x4) 2 ln(x5) = 1 (x1*x2^2) div (x4-x3) = 3
Synopsis
X op v with X:cpnlinexp and v:cpfloatvar and op one of =, ≥, ≤
X op r with X:cpnlinexp and r:real and op one of =, ≥, ≤
X op v with X:cpnlinexp and v:cpvar and op one of =, ≥, ≤
X op l with X:cpnlinexp and l:cplinexp and op one of =, ≥, ≤
Return value
A non-linear constraint combining the two arguments
Example
The following example shows how to state different kinds of non-linear constraints:
model "Non-linear constraints"
uses "kalis"
parameters
PREC = 1e-10
end-parameters
! Setting default precision of continuous variables
setparam("KALIS_DEFAULT_PRECISION_VALUE", PREC)
declarations
ISET = 1..8
x: array(ISET) of cpfloatvar
end-declarations
! Setting variable names
forall(i in ISET) x(i).name:= "x"+i
! Setting variable bounds
forall(i in ISET) do
x(i) >= -100; x(i) <= 100
end-do
! Defining and posting non-linear constraints
x(1) + x(2)*(x(1)+x(3)) + x(4)*(x(3)+x(5)) + x(6)*(x(5)+x(7)) -
(x(8)*((1/8)-x(7))) = 0
x(2) + x(3)*(x(1)+x(5)) + x(4)*(x(2)+x(6)) + x(5)*x(7) -
(x(8)*((2/8)-x(6))) = 0
x(3)*(1 + x(6)) + x(4)*(x(1)+x(7)) + x(2)*x(5) -
(x(8)*((3/8)-x(5))) = 0
x(4) + x(1)*x(5) + x(2)*x(6) + x(3)*x(7) - (x(8)*((4/8)-x(4))) = 0
x(5) + x(1)*x(6) + x(2)*x(7) - (x(8)*((5/8)-x(3))) = 0
x(6) + x(1)*x(7) - (x(8)*((6/8)-x(2))) = 0
x(7) - (x(8)*((7/8)-x(1))) = 0
sum(i in ISET) x(i) = -1
! Set the enumeration strategy
cp_set_branching(split_domain(KALIS_WIDEST_DOMAIN, KALIS_MIDDLE_VALUE,
x, true, 0))
! Find one solution
if (cp_find_next_sol) then
writeln("Solution number 1" )
cp_show_sol
cp_show_stats
end-if
end-model
Related topics
