Class: Gecode::Constraints::IntEnum::Channel::ChannelConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- Gecode::Constraints::IntEnum::Channel::ChannelConstraint
- Defined in:
- lib/gecoder/interface/constraints/int_enum/channel.rb
Overview
Describes a channel constraint which “channels” two enumerations of integer variables or one enumeration of integer variables and one enumeration of set variables. Channel constraints are used to give access to multiple viewpoints when modelling.
The channel constraint can be thought of as constraining the arrays to be each other’s inverses. I.e. if the i:th value in the first enumeration is j, then the j:th value in the second enumeration is constrained to be i.
Neither reification nor negation is supported.
Example
Lets say that we’re modelling a sequence of numbers that must be distinct and that we want access to the following two view simultaneously.
First view
The sequence is modelled as an array of integer variables where the first variable holds the value of the first position in the sequence, the second the value of the second position and so on.
# n variables with values from 0 to n-1.
elements = int_var_array(n, 0...n)
elements.must_be.distinct
That way elements
will contain the actual sequence when the problem has been solved.
Second view
The sequence is modelled as the positions of each value in 0..(n-1) in the sequence. That way the first variable would hold the positions of 0 in the sequence, the second variable would hold the positions of 1 in the sequence and so on.
positions = int_var_array(n, 0...n)
positions.must_be.distinct
Connecting the views
In essence the relationship between the two arrays elements
and positions
is that
elements.map{ |e| e.val }[i] == positions.map{ |p| p.val }.index(i)
for all i in 0..(n-1). This relationship is enforced by the channel constraint as follows.
elements.must.channel positions
Instance Method Summary collapse
Methods inherited from Constraint
Constructor Details
This class inherits a constructor from Gecode::Constraints::Constraint