Class: Gecode::Constraints::Set::Domain::DomainConstraint

Inherits:
ReifiableConstraint show all
Defined in:
lib/gecoder/interface/constraints/set/domain.rb

Overview

Describes a domain constraint which constrains a set to have a specific relation to a constant set. A constant set may be specified in three ways

Fixnum

Represents a singleton set.

Range

Represents a set containing all elements in the range. This represents the set more efficiently than when another enumeration with the same elements are used.

Enumeration of Fixnum

Represents a set containing the enumeration’s elements.

The relations allowed are the same as in Set::Relation::RelationConstraint.

Examples

# +set+ must be subset of [1,2,5]
set.must_be.subset_of [1,2,5]

# +set+ must be disjoint with 1..67
set.must_be.disjoint_with 1..67

# +set+ must not be a superset of [0].
set.must_not_be.superset_of 0

# +set+ must be subset of [1,3,5,7]. The constraint is reified with
# the boolean varaible +only_constains_odd_values+.
set.must_be.subset_of([1.3.5.7], :reify => only_contains_odd_values)

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



96
97
98
99
100
101
102
103
104
105
# File 'lib/gecoder/interface/constraints/set/domain.rb', line 96

def post
  var, domain, reif_var, relation = @params.values_at(:lhs, :rhs, :reif, 
    :relation)
  
  (params = []) << var.bind
  params << Gecode::Constraints::Util::SET_RELATION_TYPES[relation]
  params << Gecode::Constraints::Util.constant_set_to_params(domain)
  params << reif_var.bind if reif_var.respond_to? :bind
  Gecode::Raw::dom(@model.active_space, *params.flatten)
end