Class: Gecode::Constraints::CompositeExpression
- Inherits:
-
Expression
- Object
- Expression
- Gecode::Constraints::CompositeExpression
- Defined in:
- lib/gecoder/interface/constraints.rb
Overview
A composite expression which is a expression with a left hand side resulting from a previous constraint.
Direct Known Subclasses
Bool::CompositeExpression, Int::CompositeExpression, Set::CompositeExpression
Instance Method Summary collapse
- #==(expression, options = {}) ⇒ Object
-
#initialize(expression_class, variable_class, new_var_proc, model, params, &block) ⇒ CompositeExpression
constructor
The expression class should be the class of the expression delegated to, the variable class the kind of single variable used in the expression.
-
#method_missing(name, *args) ⇒ Object
Delegate to an instance of the expression class when we get something that we can’t handle.
Constructor Details
#initialize(expression_class, variable_class, new_var_proc, model, params, &block) ⇒ CompositeExpression
The expression class should be the class of the expression delegated to, the variable class the kind of single variable used in the expression. The new var proc should produce a new variable (of the appropriate type) which has an unconstricted domain. The block given should take three parameters. The first is the variable that should be the left hand side. The second is the hash of parameters. The third is a boolean, it it’s true then the block should try to constrain the first variable’s domain as much as possible.
247 248 249 250 251 252 253 254 |
# File 'lib/gecoder/interface/constraints.rb', line 247 def initialize(expression_class, variable_class, new_var_proc, model, params, &block) super(model, params) @expression_class = expression_class @variable_class = variable_class @new_var_proc = new_var_proc @constrain_equal_proc = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Delegate to an instance of the expression class when we get something that we can’t handle.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/gecoder/interface/constraints.rb', line 258 def method_missing(name, *args) if @expression_class.instance_methods.include? name.to_s = {} if args.size >= 2 and args[1].kind_of? Hash = args[1] end # Link a variable to the composite constraint. @params.update Gecode::Constraints::Util.(.clone) variable = @new_var_proc.call @model.add_interaction do @constrain_equal_proc.call(variable, @params, true) end # Perform the operation on the linked variable. int_var_params = @params.clone.update(:lhs => variable) @expression_class.new(@model, int_var_params).send(name, *args) else super end end |
Instance Method Details
#==(expression, options = {}) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/gecoder/interface/constraints.rb', line 280 def ==(expression, = {}) if !@params[:negate] and [:reify].nil? and expression.kind_of? @variable_class # We don't need any additional constraints. @params.update Gecode::Constraints::Util.() @model.add_interaction do @constrain_equal_proc.call(expression, @params, false) end else method_missing(:==, expression, ) end end |