 FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home   Defining, posting and propagating linear constraints

Description
• linctr.mos - Posting and propagating linear constraints
• scalar_product.mos - Using 'dot' for the formulation of the scalar/dot product between an array of decision variables and an array of reals or integers
Further explanation of this example: 'Xpress Kalis Mosel Reference Manual'

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.

linctr.mos

(!****************************************************************
CP example problems
===================

file linctr.mos

Posting and propagating linear constraints.

(c) 2008 Artelys S.A. and Fair Isaac Corporation
Creation: 2005, rev. Mar. 2013
*****************************************************************!)
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

`   