Class: Gecode::Constraints::IntEnum::Sort::SortConstraintWithOptions
- Inherits:
-
Constraint
- Object
- Constraint
- Gecode::Constraints::IntEnum::Sort::SortConstraintWithOptions
- Defined in:
- lib/gecoder/interface/constraints/int_enum/sort.rb
Overview
Describes a sort constraint which constrains a target enumeration of integer variables to be the sorted version of another set of integer variables. Optionally a third enumeration may be used to define the order in which the the variables should be sorted.
Neither negation nor reification is supported.
Example
# Constrains +sorted_numbers+ to be a sorted version of +numbers+.
numbers.must_be.sorted(:as => sorted_numbers)
# Constrains +sorted_numbers+ to be +numbers+ sorted in the order
# described by the integer variable enumeration +order+.
numbers.must_be.sorted(:as => sorted_numbers, :order => order)
Instance Method Summary collapse
Methods inherited from Constraint
Constructor Details
This class inherits a constructor from Gecode::Constraints::Constraint
Instance Method Details
#post ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gecoder/interface/constraints/int_enum/sort.rb', line 72 def post if @params[:target].nil? # We must have a target. lhs = @params[:lhs] @params[:target] = @model.int_var_array(lhs.size, lhs.domain_range) end # Prepare the parameters. params = @params.values_at(:lhs, :target, :order).map do |param| if param.respond_to? :to_int_var_array param.to_int_var_array else param end end.delete_if{ |param| param.nil? } params.concat # Post the constraint. Gecode::Raw::sorted(@model.active_space, *params) end |