Class: Gecode::Set::ShortCircuitRelationsOperand
- Inherits:
-
Object
- Object
- Gecode::Set::ShortCircuitRelationsOperand
- 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
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #construct_receiver(params) ⇒ Object
-
#initialize(model) ⇒ ShortCircuitRelationsOperand
constructor
A new instance of ShortCircuitRelationsOperand.
-
#relation_constraint(relation, set_operand_or_constant_set, params) ⇒ Object
Returns a constraint that constrains this operand to have relation
relationtoset_operand_or_constant_set, which is either a set operand or a constant set, given the specified hashparamsof parameters. - #to_set_var ⇒ Object
Methods included from SetOperand
#disjoint_union, #elements, #intersection, #max, #method_missing, #min, #minus, #size, #sum, #union
Methods included from Operand
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
#model ⇒ Object (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 " alias_method :alias_\#{comp.to_i}_without_short_circuit, :\#{comp}\n def \#{comp}(operand, options = {})\n if !@params[:negate] && !options.has_key?(:reify) && \n (operand.respond_to?(:to_set_var) or \n Gecode::Util::constant_set?(operand))\n # Short circuit the constraint.\n @params.update Gecode::Set::Util.decode_options(options)\n @model.add_constraint(\n @short_circuit.relation_constraint(\n :\#{comp}, operand, @params))\n else\n alias_\#{comp.to_i}_without_short_circuit(operand, options)\n end\n end\n end_code\n end\n alias_comparison_methods\n end\n\n return receiver\nend\n" |
#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.
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_var ⇒ Object
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.({}) model.add_constraint relation_constraint(:==, variable, params) return variable end |