Initializing help system before first use

A simple hybrid example

Consider the following knapsack problem with an additional non linear constraint: all-different

minimize 5·x1 + 8·x2 + 4·x3
s.t. 3·x1 + 5·x2 + 2·x3 ≥ 30
all-different(x1, x2, x3)
xj ∈ {1,3,8,12} for j = 1,2,3

A pure and straightforward CP approach for formulating and solving this problem is shown below:

model "Knapsack with side constraints"
 uses "kalis"

 declarations
  x1,x2,x3: cpvar                   ! Decision variables
  benefit : cpvar                   ! The objective to minimize
 end-declarations

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

! Setting name of variables for pretty printing
 setname(x1,"x1"); setname(x2,"x2"); setname(x3,"x3")
 setname(benefit,"benefit")

! Set initial domains for variables
 setdomain(x1, {1,3,8,12})
 setdomain(x2, {1,3,8,12})
 setdomain(x3, {1,3,8,12})

! Knapsack constraint
 3*x1 + 5*x2 + 2*x3 >= 30

! Additional global constraint
 all_different({x1,x2,x3})

! Objective function
 benefit = 5*x1 + 8*x2 + 4*x3

! Initial propagation
 res := cp_propagate

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

! Solve the problem
 if (cp_minimize(benefit)) then
  cp_show_sol                      ! Output optimal solution to screen
 end-if

end-model

This model formulation can be augmented by the definition of a linear relaxation.

We start by getting an automatic relaxation of the problem by a call to the function cp_get_linrelax. The resulting relaxation can be displayed (printed to the standard output) with a call to the procedure cp_show_relax.

From the linear relaxation a linear relaxation solver is built with a call to the get_linrelax_solver method. Note that the KALIS_TOPNODE_RELAX_SOLVER argument passed to the method indicates that we just want to solve the linear relaxation at the top node of the CP search tree.

Having obtained the linear relaxation solver, we need to add it to the search process by a call to cp_add_linrelax_solver. Of course, Xpress Kalis is not limited to one relaxation so several solvers can be defined and added to the search process.

The model definition is completed by specifying a 'MIP style' branching scheme that branches first on the variables with largest reduced cost and tests first the values nearest to the optimal solution of the relaxation. The invocation ot the search and solution display remain the same as in the CP model.

This is the full hybrid model:

model "Knapsack with side constraints"
 uses "kalis"

 declarations
  x1,x2,x3: cpvar                   ! Decision variables
  benefit : cpvar                   ! The objective to minimize
 end-declarations

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

! Setting name of variables for pretty printing
 setname(x1,"x1"); setname(x2,"x2"); setname(x3,"x3")
 setname(benefit,"benefit")

! Set initial domains for variables
 setdomain(x1, {1,3,8,12})
 setdomain(x2, {1,3,8,12})
 setdomain(x3, {1,3,8,12})

! Knapsack constraint
 3*x1 + 5*x2 + 2*x3 >= 30

! Additional global constraint
 all_different({x1,x2,x3})

! Objective function
 benefit = 5*x1 + 8*x2 + 4*x3

! Initial propagation
 res := cp_propagate

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


 declarations
  myrelaxall: cplinrelax
 end-declarations
	
! Build an automatic 'LP' oriented linear relaxation
 myrelaxall:= cp_get_linrelax(0)

! Output the relaxation to the screen
 cp_show_relax(myrelaxall)

 mysolver:= get_linrelax_solver(myrelaxall, benefit, KALIS_MINIMIZE,
                KALIS_SOLVE_AS_MIP, KALIS_TOPNODE_RELAX_SOLVER)

! Define the linear relaxation
 cp_add_linrelax_solver(mysolver)

! Define a 'MIP' style branching scheme using the solution of the
! optimal relaxation
 cp_set_branching(assign_var(KALIS_LARGEST_REDUCED_COST(mysolver),
                             KALIS_NEAREST_RELAXED_VALUE(mysolver)))

! Solve the problem
 if (cp_minimize(benefit)) then
  cp_show_sol                      ! Output optimal solution to screen
 end-if

end-model

You will find below the list of relaxation related functions and procedures defined within Xpress Kalis:

cp_add_linrelax_solver
Add a linear relaxation solver to the linear relaxation solver list
cp_clear_linrelax_solver
Clear the linear relaxation solver list
cp_get_linrelax
Returns an automatic relaxation of the cp problem
cp_remove_linrelax_solver
Remove a linear relaxation solver from the linear relaxation solver list
cp_show_relax
Pretty printing of a linear relaxation
export_prob
Export the linear relaxation in LP format
fix_to_relaxed
Fix the continuous variables to their optimal value in the relaxation solver passed in argument
generate_cuts
Generate and add cuts to the relaxation passed in parameters
get_indicator
Get an indicator variable for a given variable and a value.
get_linrelax
Get the linear relaxation for a constraint
get_linrelax_solver
Returns a linear relaxation solver from a linear relaxation, an objective variables and some configuration parameters
get_reduced_cost
Get a reduced cost value from a linear relaxation solver
get_relaxed_value
Returns the optimal relaxed value for a variable in a relaxation
KALIS_LARGEST_REDUCED_COST
Get a largest reduced cost variable selector from a linear relaxation solver
KALIS_NEAREST_RELAXED_VALUE
Get a nearest relaxed value selector from a linear relaxation solver
lp_optimize
Launch LP/MIP solver without CP branching.
set_integer
Set integrality flag for a variable in a linear relaxation
set_linrelax_solver_attribute
Parameter setting for a linear relaxation solver.
set_verbose_level
Set the verbose level for a specific linear relaxation solver

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.