Class: Gecode::Constraints::IntEnum::Sort::SortConstraint

Inherits:
ReifiableConstraint show all
Defined in:
lib/gecoder/interface/constraints/int_enum/sort.rb

Overview

Describes a sort constraint.

Instance Method Summary collapse

Methods inherited from ReifiableConstraint

#&, #reification_var, #reification_var=, #|

Methods inherited from Constraint

#initialize

Constructor Details

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

Instance Method Details

#postObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/gecoder/interface/constraints/int_enum/sort.rb', line 75

def post
  lhs, strength, reif_var = @params.values_at(:lhs, :strength, :reif)
  using_reification = !reif_var.nil?
  
  # We translate the constraint into n-1 relation constraints.
  options = {:strength => 
    Gecode::Constraints::Util::PROPAGATION_STRENGTHS.invert[strength]}
  if using_reification
    reification_variables = @model.bool_var_array(lhs.size - 1)
  end
  (lhs.size - 1).times do |i|
    first, second = lhs[i, 2]
    rel_options = options.clone
    if using_reification
      # Reify each relation constraint and then bind them all together.
      rel_options[:reify] = reification_variables[i]
    end
    first.must_be.less_than_or_equal_to(second, rel_options)
  end
  if using_reification
    # TODO use the interface's all constraint when available.
    # reification_variables.all.must == reif_var
    Gecode::Raw::bool_and(@model.active_space, 
      reification_variables.to_bool_var_array, reif_var.bind, strength) 
  end
end