all_different
all_different |
Purpose
The all_different constraint states that all variables in this constraint must be pairwise different:
Synopsis
function all_different(vars:set of cpvar, propagation: integer) : cpctr
function all_different(vars:set of cpvar) : cpctr
function all_different(vars:array(range) of cpvar, propagation:integer) : cpctr
function all_different(vars:array(range) of cpvar) : cpctr
function all_different(vars:cpvarlist, propagation:integer) : cpctr
function all_different(vars:cpvarlist) : cpctr
Arguments
vars
|
the list of variables
|
propagation
|
Propagation type selected using a constant
KALIS_FORWARD_CHECKING,
KALIS_GEN_ARC_CONSISTENCY
|
Return value
An all different constraint over vars
Example
Consider the following simple problem where one must determine the arrival positions of a set of six runners:Dominique, Ignace, Naren, Olivier, Philippe and Pascal.
The constraints are the following:
The constraints are the following:
- All runners have different positions
- Olivier is not last
- Dominique, Pascal, and Ignace are before Naren and Olivier
- Dominique is better than third
- Philippe is among the first four
- Ignace is neither second nor third
- Pascal is three places higher than Naren
- Neither Ignace nor Dominique are in fourth position
model "all_different example" uses "kalis" declarations PEOPLE = {"Sebastian", "Frederic", "Jan-Georg", "Krzysztof","Maarten","Luca"} ! Set of speakers x: array(PEOPLE) of cpvar ! Time slot per person end-declarations 3 <= x("Sebastian") ; x("Sebastian") <= 6 3 <= x("Frederic") ; x("Frederic") <= 4 2 <= x("Jan-Georg") ; x("Jan-Georg") <= 5 2 <= x("Krzysztof") ; x("Krzysztof") <= 4 3 <= x("Maarten") ; x("Maarten") <= 4 1 <= x("Luca") ; x("Luca") <= 6 ! A different time slot for every person all_different(x) ! Solve the problem if not(cp_find_next_sol) then writeln("Problem is infeasible") exit(1) end-if ! Solution printout writeln(x) end-model
Related topics