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

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

Overview

:nodoc:

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::Constraint

Instance Method Details

#postObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/gecoder/interface/constraints/int_enum/sort.rb', line 104

def post
  lhs, strength, kind, reif_var = 
    @params.values_at(:lhs, :strength, :kind, :reif)
  using_reification = !reif_var.nil?
  
  # We translate the constraint into n-1 relation constraints.
  options = {
    :strength => 
      Gecode::Util::PROPAGATION_STRENGTHS.invert[strength],
    :kind => 
      Gecode::Util::PROPAGATION_KINDS.invert[kind]
  }
  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
    reification_variables.conjunction.must == reif_var
  end
end