Class: Gecode::Bool::ExpressionTree

Inherits:
Object
  • Object
show all
Includes:
BoolOperand
Defined in:
lib/gecoder/interface/constraints/bool/boolean.rb

Overview

Describes a binary tree of expression nodes which together form a boolean expression.

Instance Method Summary collapse

Methods included from BoolOperand

#&, #*, #+, #-, #^, #implies, #method_missing, #|

Methods included from Operand

#must, #must_not

Methods included from BoolLinearOperations

#*, #+, #-

Constructor Details

#initialize(left_tree, operation, right_tree) ⇒ ExpressionTree

Constructs a new expression with the specified binary operation applied to the specified trees.



196
197
198
199
200
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 196

def initialize(left_tree, operation, right_tree)
  @left = left_tree
  @operation = operation
  @right = right_tree
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Bool::BoolOperand

Instance Method Details

#modelObject

Fetches the space that the expression’s variables is in.



210
211
212
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 210

def model
  @left.model || @right.model
end

#to_bool_varObject



214
215
216
217
218
219
220
221
222
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 214

def to_bool_var
  bool_var = model.bool_var
  tree = ExpressionTree.new(self, :==, ExpressionNode.new(bool_var))
  model.add_interaction do
    tree.to_minimodel_bool_expr.post(model.active_space, true, 
      Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
  end
  return bool_var
end

#to_minimodel_bool_exprObject

Returns a MiniModel boolean expression representing the tree.



203
204
205
206
207
# File 'lib/gecoder/interface/constraints/bool/boolean.rb', line 203

def to_minimodel_bool_expr
  Gecode::Raw::MiniModel::BoolExpr.new(
    @left.to_minimodel_bool_expr, OPERATION_TYPES[@operation], 
    @right.to_minimodel_bool_expr)
end