FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

One- and two-dimensional 'element' constraints

Description
Defining one- and two-dimensional 'element' constraints.

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.
element.mos[download]





element.mos

(!****************************************************************
   CP example problems
   ===================
   
   file element.mos
   ````````````````
   Element constraints.

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       Creation: 2005, rev. 2007
*****************************************************************!)
model "Element" 
 uses "kalis"

 declarations
  RY = 43..52
  RX = 1..2
  D: array(RY) of integer     
  D2: array(RX,RY) of integer     
  x,y,d_of_y,d_of_x_y: cpvar
 end-declarations

 D :: (43..52)[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9] 
         
 D2:: (1..2,43..52)[10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
                    20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
 
 setname(x, "x")
 setname(y, "y")
 setname(d_of_y, "d_of_y")
 setname(d_of_x_y, "d_of_x_y")
 
 writeln("Original domains: ", x, y, d_of_y, d_of_x_y)
 
 element(D,y) = d_of_y 
 element(D2,x,y) = d_of_x_y  

 writeln("After propagation: ", x, y, d_of_y, d_of_x_y)

! Solve the problem
 while (cp_find_next_sol) do
  nbSolutions += 1    
  writeln("Solution ", nbSolutions, ": x:", getsol(x),
	  " y:", getsol(y), " d_of_y:", getsol(d_of_y),
	  " d_of_x_y:", getsol(d_of_x_y)) 	
 end-do
 writeln("done!")

end-model


Back to examples browserPrevious exampleNext example