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

Branching strategies

Description
Branching schemes for the enumeration of decision variables (discrete or continuous), disjunctive constraints, or tasks can be configured to use built-in or user-defined variable / constraint / task and value selection heuristics.
  • branching.mos: branching strategies using the branching schemes 'assign_and_forbid', 'assign_var', and 'split_domain'; user-defined variable and value selection heuristics.
  • probeac2001.mos, probeac2001_nary.mos: branching scheme 'probe_assign_var' and definition of generic binary or nary constraints; solving the Euler knight tour problem.
  • [probe]settledisjunction.mos: branching schemes 'probe_settle_disjunction' and 'settle_disjunction'; same problem as in "disjunctive.mos" but modeled by pairs of individual disjunctions (using 'or').
  • groupserializer.mos: defining a task group based branching strategy for the problem of "producer_consumer.mos"
  • taskserializer.mos: defining a task-based branching strategy for the problem of "producer_consumer.mos" (two versions showing definition of callbacks via subroutine references or by name)
  • altresource_scheduling.mos: defining a task-based branching strategy with user-defined resource selection criterion
  • altresource_scheduling_softbreaks.mos: like altresource_scheduling.mos with additional soft breaks (pre-emptive breaks) on resources
Further explanation of this example: 'Xpress Kalis Mosel Reference Manual'

branchingka.zip[download all files]

Source Files





probeac2001.mos

(!****************************************************************
   CP example problems
   ===================
   
   file probeac2001.mos
   ````````````````````
   Euler knight tour problem implemented with user-defined
   binary constraints.

   *** This model cannot be run with a Community Licence 
       for the default data instance ***

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

 parameters
  S = 8                                  ! No. of rows/columns
 end-parameters
 
 N:= S * S                               ! Total number of cells
 setparam("KALIS_DEFAULT_LB", 0)
 setparam("KALIS_DEFAULT_UB", N-1)

 forward function valid_knight_move(a:integer, b:integer): boolean

 declarations
  PATH = 1..N                            ! Cells on the board
  pos: array(PATH) of cpvar              ! Position p in tour
 end-declarations

! Setting names of decision variables
 forall(i in PATH) setname(pos(i), "Position"+i)  

! Fix the start position
 pos(1) = 0

! Each cell is visited once
 all_different(pos, KALIS_GEN_ARC_CONSISTENCY)

! The knight's path obeys the chess rules for valid knight moves
 forall(i in 1..N-1)
  generic_binary_constraint(pos(i), pos(i+1), ->valid_knight_move)
 generic_binary_constraint(pos(N), pos(1), ->valid_knight_move)

! Setting enumeration parameters
 cp_set_branching(probe_assign_var(KALIS_SMALLEST_MIN, 
                  KALIS_MAX_TO_MIN, pos, 14))

! Search for up to NBSOL solutions
 solct:= 0
 if not cp_find_next_sol then
  writeln("No solution")
 else
  writeln(pos)
 end-if

! **** Test whether the move from a to b is admissible ****
 function valid_knight_move(a:integer, b:integer): boolean
  declarations
   xa,ya,xb,yb,delta_x,delta_y: integer
  end-declarations
  xa := a div S
  ya := a mod S
  xb := b div S
  yb := b mod S
  delta_x := abs(xa-xb)
  delta_y := abs(ya-yb)
  returned := (delta_x<=2) and (delta_y<=2) and (delta_x+delta_y=3)
 end-function

end-model

Back to examples browserPrevious exampleNext example