FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserNext example

Generic binary and n-ary constraints

Description
Implementation of user-defined constraints:
  • ac2001.mos: Generic binary constraint
  • gac2001.mos: Generic n-ary 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.
ac2001.mos[download]
gac2001.mos[download]





ac2001.mos

(!****************************************************************
   CP example problems
   ===================
   
   file ac2001.mos
   ```````````````
   Generic binary constraints.

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       Creation: 2005, rev. Jul. 2022
*****************************************************************!)
model "generic_binary_constraint example"
 uses "kalis"

 forward function truth_value(v1:integer, v2:integer): boolean

 declarations 
  x1 : cpvar 
  x2 : cpvar          
  C  : integer
 end-declarations

 C := 4
 0 <= x1 ; x1 <= 10
 0 <= x2 ; x2 <= 5

! Define and post the user constraint
 generic_binary_constraint(x1, x2, ->truth_value)

 cp_show_prob

! Search for all solutions and print them out
 while (cp_find_next_sol)
  writeln("A solution has been found with x1 = ",
          getsol(x1), " and x2 = ", getsol(x2) )

! Implementation of the user constraint
 function truth_value(v1:integer, v2:integer): boolean 
  returned := (v1 = v2 mod C)
 end-function

end-model


Back to examples browserNext example