Class: Gecode::Int::Linear::ExpressionTree

Inherits:
ShortCircuitRelationsOperand show all
Defined in:
lib/gecoder/interface/constraints/int/linear.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ShortCircuitRelationsOperand

#construct_receiver, #to_int_var

Methods included from IntOperand

#*, #+, #-, #abs, #method_missing, #pre_arith_mult, #square_root, #squared

Methods included from Operand

#must, #must_not

Constructor Details

#initialize(left_node, right_node, operation) ⇒ ExpressionTree

Constructs a new expression with the specified operands.



86
87
88
89
90
91
92
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 86

def initialize(left_node, right_node, operation)
  super(left_node.model || right_node.model)
  @left = left_node
  @right = right_node
  @operation = operation
  @model = @left.model || @right.model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Int::IntOperand

Instance Attribute Details

#modelObject (readonly)

:nodoc:



83
84
85
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 83

def model
  @model
end

Instance Method Details

#relation_constraint(relation, int_operand_or_fix, params) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 100

def relation_constraint(relation, int_operand_or_fix, params)
  unless params[:negate]
    relation_type = 
      Gecode::Util::RELATION_TYPES[relation]
  else
    relation_type = 
      Gecode::Util::NEGATED_RELATION_TYPES[relation]
  end

  unless int_operand_or_fix.respond_to? :to_minimodel_lin_exp
    int_operand_or_fix = Linear::ExpressionNode.new(int_operand_or_fix);
  end

  params.update(:lhs => self, :rhs => int_operand_or_fix, 
    :relation_type => relation_type)
  LinearRelationConstraint.new(model, params)
end

#to_minimodel_lin_expObject

Converts the linear expression to an instance of Gecode::Raw::MiniModel::LinExpr



96
97
98
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 96

def to_minimodel_lin_exp
  @left.to_minimodel_lin_exp.send(@operation, @right.to_minimodel_lin_exp)
end