Class: Gecode::SetElements::SetElementsConstraintReceiver

Inherits:
ConstraintReceiver show all
Defined in:
lib/gecoder/interface/constraints/set_elements_constraints.rb,
lib/gecoder/interface/constraints/set_elements/relation.rb

Overview

SetElementsConstraintReceiver contains all constraints that can be placed on a SetElementsOperand.

Constraints are placed by calling SetElementsOperand#must (or any other of the variations defined in Operand), which produces a SetElementsConstraintReceiver from which the desired constraint can be used.

Each constraint accepts a number of options. See ConstraintReceiver for more information.

Examples

Constrains all elements in set_operand to be strictly greater than 17 using SetOperand#elements and SetElementsConstraintReceiver#>:

set.elements.must > 17

Constrains all elements in set_operand to be strictly greater than int_operand using SetOperand#elements and SetElementsConstraintReceiver#>:

set.elements.must > int_operand

The same as above, but specifying that strength :domain should be used and that the constraint should be reified with bool_operand:

set.elements.must_be.greater_than(int_operand, :strength => :domain, :reify => bool_operand)

Instance Method Summary collapse

Constructor Details

#initialize(model, params) ⇒ SetElementsConstraintReceiver

Raises TypeError unless the left hand side is set elements operand.



72
73
74
75
76
77
78
# File 'lib/gecoder/interface/constraints/set_elements_constraints.rb', line 72

def initialize(model, params) #:nodoc:
  super

  unless params[:lhs].respond_to? :to_set_elements
    raise TypeError, 'Must have set elements operand as left hand side.'
  end
end

Instance Method Details

#<(operand, options = {}) ⇒ Object

Constrains the set elements to be strictly less than operand (either a constant integer or an integer operand).

Examples

# The elements of +set+ must be strictly less than +int+
set.elements.must < int

# The elements of +set+ must be strictly less than 17
set.elements.must < 17


55
56
57
# File 'lib/gecoder/interface/constraints/set_elements/relation.rb', line 55

def <(operand, options = {})
  comparison(:<, operand, options)
end

#<=(operand, options = {}) ⇒ Object

Constrains the set elements to be less than or equal to operand (either a constant integer or an integer operand).

Examples

# The elements of +set+ must be less than or equal to +int+
set.elements.must <= int

# The elements of +set+ must be less than or equal to 17
set.elements.must <= 17


69
70
71
# File 'lib/gecoder/interface/constraints/set_elements/relation.rb', line 69

def <=(operand, options = {})
  comparison(:<=, operand, options)
end

#==(operand, options = {}) ⇒ Object

Constrains the set elements to equal operand (either a constant integer or an integer operand).

Examples

# The elements of +set+ must equal +int+
set.elements.must == int

# The elements of +set+ must equal 17
set.elements.must == 17


13
14
15
# File 'lib/gecoder/interface/constraints/set_elements/relation.rb', line 13

def ==(operand, options = {})
  comparison(:==, operand, options)
end

#>(operand, options = {}) ⇒ Object

Constrains the set elements to be strictly greater than operand (either a constant integer or an integer operand).

Examples

# The elements of +set+ must be strictly greater than +int+
set.elements.must > int

# The elements of +set+ must be strictly greater than 17
set.elements.must > 17


27
28
29
# File 'lib/gecoder/interface/constraints/set_elements/relation.rb', line 27

def >(operand, options = {})
  comparison(:>, operand, options)
end

#>=(operand, options = {}) ⇒ Object

Constrains the set elements to be greater than or equal to operand (either a constant integer or an integer operand).

Examples

# The elements of +set+ must be greater than or equal to +int+
set.elements.must >= int

# The elements of +set+ must be greater than or equal to 17
set.elements.must >= 17


41
42
43
# File 'lib/gecoder/interface/constraints/set_elements/relation.rb', line 41

def >=(operand, options = {})
  comparison(:>=, operand, options)
end