Class: Gecode::Set::ShortCircuitRelationsOperand

Inherits:
Object
  • Object
show all
Includes:
SetOperand
Defined in:
lib/gecoder/interface/constraints/set_var_constraints.rb

Overview

An operand that short circuits set non-negated and non-reified versions of the relation constraints.

Direct Known Subclasses

Operation::OperationSetOperand

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SetOperand

#disjoint_union, #elements, #intersection, #method_missing, #minus, #size, #union

Methods included from Operand

#must, #must_not

Constructor Details

#initialize(model) ⇒ ShortCircuitRelationsOperand

Returns a new instance of ShortCircuitRelationsOperand.



123
124
125
# File 'lib/gecoder/interface/constraints/set_var_constraints.rb', line 123

def initialize(model)
  @model = model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Set::SetOperand

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



121
122
123
# File 'lib/gecoder/interface/constraints/set_var_constraints.rb', line 121

def model
  @model
end

Instance Method Details

#construct_receiver(params) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/gecoder/interface/constraints/set_var_constraints.rb', line 127

def construct_receiver(params)
  params.update(:lhs => self)
  receiver = SetConstraintReceiver.new(@model, params)
  op = self
  receiver.instance_eval{ @short_circuit = op }
  class <<receiver
    Gecode::Util::SET_RELATION_TYPES.keys.each do |comp|
      eval <<-end_code
        alias_method :alias_#{comp.to_i}_without_short_circuit, :#{comp}
        def #{comp}(operand, options = {})
          if !@params[:negate] && !options.has_key?(:reify) && 
              (operand.respond_to?(:to_set_var) or 
              Gecode::Util::constant_set?(operand))
            # Short circuit the constraint.
            @params.update Gecode::Set::Util.decode_options(options)
            @model.add_constraint(
              @short_circuit.relation_constraint(
                :#{comp}, operand, @params))
          else
            alias_#{comp.to_i}_without_short_circuit(operand, options)
          end
        end
      end_code
    end
    alias_comparison_methods
  end

  return receiver
end

#relation_constraint(relation, set_operand_or_constant_set, params) ⇒ Object

Returns a constraint that constrains this operand to have relation relation to set_operand_or_constant_set, which is either a set operand or a constant set, given the specified hash params of parameters. The constraints are never negated nor reified.

Raises:

  • (NotImplementedError)


169
170
171
# File 'lib/gecoder/interface/constraints/set_var_constraints.rb', line 169

def relation_constraint(relation, set_operand_or_constant_set, params)
  raise NotImplementedError, 'Abstract method has not been implemented.'
end

#to_set_varObject



157
158
159
160
161
162
163
# File 'lib/gecoder/interface/constraints/set_var_constraints.rb', line 157

def to_set_var
  variable = model.set_var
  params = {:lhs => self}
  params.update Gecode::Set::Util.decode_options({})
  model.add_constraint relation_constraint(:==, variable, params)
  return variable
end