Class: Gecode::Set::Cardinality::SetSizeOperand

Inherits:
Int::ShortCircuitEqualityOperand show all
Defined in:
lib/gecoder/interface/constraints/set/cardinality.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Int::ShortCircuitEqualityOperand

#model

Instance Method Summary collapse

Methods inherited from Int::ShortCircuitEqualityOperand

#to_int_var

Methods included from Int::IntOperand

#*, #+, #-, #abs, #method_missing, #pre_arith_mult, #square_root, #squared

Methods included from Operand

#model, #must, #must_not

Constructor Details

#initialize(model, set_op) ⇒ SetSizeOperand

Returns a new instance of SetSizeOperand.



29
30
31
32
# File 'lib/gecoder/interface/constraints/set/cardinality.rb', line 29

def initialize(model, set_op)
  super model
  @set = set_op
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Int::IntOperand

Instance Method Details

#constrain_equal(int_operand, constrain, propagation_options) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/gecoder/interface/constraints/set/cardinality.rb', line 34

def constrain_equal(int_operand, constrain, propagation_options)
  set = @set.to_set_var
  if constrain
    int_operand.must_be.in set.lower_bound.size..set.upper_bound.size
  end
  
  Gecode::Raw::cardinality(@model.active_space, set.bind, 
    int_operand.to_int_var.bind)
end

#construct_receiver(params) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gecoder/interface/constraints/set/cardinality.rb', line 45

def construct_receiver(params)
  receiver = pre_cardinality_construct_receiver(params)
  set = @set
  receiver.instance_eval{ @set = set }
  class <<receiver 
    alias_method :in_without_short_circuit, :in
    def in(range, options = {})
      if range.kind_of?(Range) and !@params[:negate] and 
          !options.has_key?(:reify)
        @params.update(:lhs => @set, :range => range)
        @model.add_constraint CardinalityConstraint.new(@model, @params)
      else
        in_without_short_circuit(range, options)
      end
    end
  end
  return receiver
end

#pre_cardinality_construct_receiverObject



44
# File 'lib/gecoder/interface/constraints/set/cardinality.rb', line 44

alias_method :pre_cardinality_construct_receiver, :construct_receiver