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

Linear relaxations

This set of examples requires Xpress Optimizerin addition to Xpress Kalis.
  • knapsackalld.mos: Knapsack problem with 'alldifferent' constraint solved by automatic linear relaxations
  • knapsackalld2.mos: Configuring linear relaxations
  • knapsackalld3a.mos: Selecting constraints for linear relaxations
  • knapsackalld3b.mos: User-defined linear relaxations
Further explanation of this example: 'Xpress Kalis Mosel User Guide', Chapter 6 Hybridization of CP and MP[download all files]

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


   CP example problems
   file knapsackalld.mos
   Knapsack problem with additional alldifferent 
   constraint solved using linear relaxations.
   - Using default settings for relaxation -

   (c) 2009 Artelys S.A. and Fair Isaac Corporation
       Creation: 2009, rev. Mar. 2013
model "Knapsack with side constraints"
 uses "kalis"

  VALUES = {1,3,8,9,12}
  R = 1..4
  x: array(R) of cpvar              ! Decision variables
  benefit: cpvar                    ! The objective to minimize

! Enable output printing
 setparam("kalis_verbose_level", 1)

! Setting name of variables for pretty printing
 forall(i in R) setname(x(i),"x"+i) 

! Set initial domains for variables
 forall(i in R) setdomain(x(i), VALUES)

! Knapsack constraints
 3*x(1) + 5*x(2) + 2*x(3) <= 50
 2*x(1) + x(3) + 5*x(4) <= 75

! Additional global constraint
 all_different(union(i in R) {x(i)})

! Objective function
 benefit = 5*x(1) + 8*x(2) + 4*x(3) + x(4)

! Initial propagation
 res := cp_propagate

! Display bounds on objective after constraint propagation
 writeln("Constraints propagation objective ", benefit)

! **** Linear relaxation ****

! Enable automatic linear relaxations
 setparam("kalis_auto_relax", true)
! Solve the problem
 if cp_maximize(benefit) then  
  cp_show_sol                      ! Output optimal solution to screen


Back to examples browserPrevious example