abs
abs |
Purpose
This constraint states that a variable y equals the absolute value of another variable x
Synopsis
abs(x) = y with x,y:cpvar
abs(x) op I with x:cpvar and I:integer and op one of =, ≥, ≤, <>
x = abs(y) with x,y:cpvar
I op abs(x) with I:integer and x:cpvar and op one of =, ≥, ≤, <>
Arguments
|
x
|
absolute value variable (of type
cpvar,
cpfloatvar,
cplinexp,
cpnlinexp)
|
|
y
|
value variable (of the same type as
x)
|
|
I
|
integer value
|
Return value
An absolute value constraint over the arguments
Example
The following example shows how to use the absolute value constraint
model "Distance constraints"
uses "kalis"
setparam("KALIS_DEFAULT_LB", -50); setparam("KALIS_DEFAULT_UB", 50)
declarations
x, y, z: cpvar
Dist: cpctr
end-declarations
setname(x,"x")
setname(y,"y")
setname(z,"z")
abs(x) = y
writeln("Absolute value of x: ", x,y,z)
y >= 20
writeln("Bounding y by 20: ", x,y,z)
! abs(y-z) <= 3
! Equivalent version of this constraint:
distance(y,z) <= 3
writeln("Max distance betw. y and z: ", x,y,z)
Dist:= distance(x,z) = 5
if(cp_post(Dist)) then
writeln("Distance between x and z: ", x,y,z)
else
writeln("Problem is infeasible")
end-if
cp_show_prob
end-model
Related topics
