Initializing help system before first use

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:
  1. All runners have different positions
  2. Olivier is not last
  3. Dominique, Pascal, and Ignace are before Naren and Olivier
  4. Dominique is better than third
  5. Philippe is among the first four
  6. Ignace is neither second nor third
  7. Pascal is three places higher than Naren
  8. Neither Ignace nor Dominique are in fourth position
This problem can be modeled as follows. We create one variable per runner, whose value will be his arrival position. The initial domains of the variables will be the available arrival positions (1-6). Since we admit there are no ties, the positions are all pairwise different.
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

© 2001-2025 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.