Class: Gecode::Constraints::Bool::CompositeExpression

Inherits:
CompositeExpression show all
Defined in:
lib/gecoder/interface/constraints/bool_var_constraints.rb

Overview

A composite expression which is an bool expression with a left hand side resulting from a previous constraint.

Instance Method Summary collapse

Methods inherited from CompositeExpression

#==, #method_missing

Constructor Details

#initialize(model, params, &block) ⇒ CompositeExpression

The block given should take three parameters. The first is the variable that should be the left hand side, if it’s nil then a new one should be created. The second is the has of parameters. The block should return the variable used as left hand side.



28
29
30
31
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 28

def initialize(model, params, &block)
  super(Expression, Gecode::FreeBoolVar, lambda{ model.bool_var }, model,
    params, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Constraints::CompositeExpression

Instance Method Details

#false(options = {}) ⇒ Object

Override to also deal with constant booleans.



43
44
45
46
47
48
49
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 43

def false(options = {})
  # We don't need any additional constraints.
  @params.update Gecode::Constraints::Util.decode_options(options)
  @model.add_interaction do
    @constrain_equal_proc.call(@params[:negate], @params)
  end
end

#true(options = {}) ⇒ Object

Override to also deal with constant booleans.



34
35
36
37
38
39
40
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 34

def true(options = {})
  # We don't need any additional constraints.
  @params.update Gecode::Constraints::Util.decode_options(options)
  @model.add_interaction do
    @constrain_equal_proc.call(!@params[:negate], @params)
  end
end