Class: Gecode::Constraints::IntEnum::Distinct::DistinctConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/gecoder/interface/constraints/int_enum/distinct.rb

Overview

Describes a distinct constraint, which constrains all integer variables in an enumeration to be distinct (different). The constraint can also be used with constant offsets, so that the variables, with specified offsets added, must be distinct.

The constraint does not support negation nor reification.

Examples

# Constrains all variables in +int_enum+ to be assigned different 
# values.
int_enum.must_be.distinct

# The same as above, but also selects that the strength +domain+ should
# be used.
int_enum.must_be.distinct(:strength => :domain)

# Uses the offset to constrain that no number may be the previous number
# incremented by one.
numbers = int_var_array(8, 0..9)
numbers.with_offset((1..numbers.size).to_a.reverse).must_be.distinct

Instance Method Summary collapse

Methods inherited from Constraint

#initialize

Constructor Details

This class inherits a constructor from Gecode::Constraints::Constraint

Instance Method Details

#postObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/gecoder/interface/constraints/int_enum/distinct.rb', line 62

def post
  # Bind lhs.
  @params[:lhs] = @params[:lhs].to_int_var_array
  
  # Fetch the parameters to Gecode.
  params = @params.values_at(:offsets, :lhs)
  params.delete_if{ |x| x.nil? }
  params.concat propagation_options
  Gecode::Raw::distinct(@model.active_space, *params)
end