cplinctr
cplinctr |
Purpose
Linear constraints are arithmetic constraints over decision variables. Linear constraints are defined with linear expressions combined by arithmetic operators such as =, ≠, ≤, and ≥.
Objects of type cplinexp are linear expressions of decision variables. Typically, these objects result as intermediate objects in the definition of linear constraints.
Linear expressions of decision variables are obtained by applying the operators +, - and * to decision variables and integer 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 linear expressions to change this order. The following are examples of valid linear expressions:
Objects of type cplinexp are linear expressions of decision variables. Typically, these objects result as intermediate objects in the definition of linear constraints.
Linear expressions of decision variables are obtained by applying the operators +, - and * to decision variables and integer 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 linear expressions to change this order. The following are examples of valid linear expressions:
declarations A, B: integer x, y: cpvar z: array(1..10) of cpfloatvar end-declarations A*x*B -x + 2*A*y B*(x-y) (abs(A) + ceil(2.9) + round(-3.4)) * x sum(i in 1..10) z(i)The following definitions are not valid for objects of type cplinexp:
x*y ln(2) * x y/3
Synopsis
x op I with x:cpvar and I:integer and op one of =, ≥, ≤, <>
x op y with x,y:cpvar and op one of =, ≥, ≤, <>
z op R with z:cplinexp and R:real and op one of =, ≥, ≤, <>
z op x with z:cplinexp and x:cpvar and op one of =, ≥, ≤, <>
z op w with z,w:cplinexp and op one of =, ≥, ≤, <>
I op x with I:integer and x:cpvar and op one of =, ≥, ≤
R op z with R:real and z:cplinexp and op one of =, ≥, ≤, <>
x op z with x:cpvar and z:cplinexp and op one of =, ≥, ≤, <>
I <> z with I:integer and z:cplinexp
x op R with x:cpfloatvar and R:real and op one of ≥, ≤
Return value
A linear constraint combining the two arguments
Example
The following example shows how to state different kinds of linear constraints:
model "Linear constraints" uses "kalis" declarations N = 3 R = 1..N x: array(R) of cpvar c1: cpctr end-declarations forall(i in R) do 0 <= x(i); x(i) <= 50 setname(x(i), "x"+i) end-do ! Automated post+propagation x(1) >= x(3) + 5 writeln(x(1), " ", x(3)) ! Named constraint (explicit post) c1:= x(3) >= x(2) + 10 if cp_post(c1) then writeln("With constraint c1: ", x) else exit(1) end-if ! Stop automated propagation setparam("kalis_auto_propagate", false) ! Automated post w/o propagation x(2) >= 10 writeln("new bound for x2: ", x) if cp_propagate then writeln("after propagation: ", x) end-if ! Minimize the value of x(1) if cp_minimize(x(1)) then write("Solution: ") forall(i in R) write(getsol(x(i)), " ") writeln end-if end-model
Related topics