Class: Gecode::Bool::Linear::ExpressionTree
- Inherits:
-
Int::ShortCircuitRelationsOperand
- Object
- Int::ShortCircuitRelationsOperand
- Gecode::Bool::Linear::ExpressionTree
- Includes:
- BoolLinearOperations
- Defined in:
- lib/gecoder/interface/constraints/bool/linear.rb
Overview
Describes a binary tree of expression nodes which together form a linear expression.
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #construct_receiver(params) ⇒ Object
-
#initialize(left_node, right_node, operation) ⇒ ExpressionTree
constructor
Constructs a new expression with the specified operands.
- #pre_bool_construct_receiver ⇒ Object
- #relation_constraint(relation, bool_operand_or_fix, params) ⇒ Object
-
#to_minimodel_lin_exp ⇒ Object
Converts the linear expression to an instance of Gecode::Raw::MiniModel::LinExpr.
Methods included from BoolLinearOperations
Methods inherited from Int::ShortCircuitRelationsOperand
Methods included from Int::IntOperand
#*, #+, #-, #abs, #method_missing, #pre_arith_mult, #square_root, #squared
Methods included from Operand
Constructor Details
#initialize(left_node, right_node, operation) ⇒ ExpressionTree
Constructs a new expression with the specified operands.
125 126 127 128 129 130 131 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 125 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
#model ⇒ Object (readonly)
Returns the value of attribute model.
122 123 124 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 122 def model @model end |
Instance Method Details
#construct_receiver(params) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 140 def construct_receiver(params) receiver = pre_bool_construct_receiver(params) lhs = self receiver.instance_eval{ @lhs = lhs } class <<receiver alias_method :pre_bool_equality, :== def ==(op, = {}) if op.respond_to? :to_bool_var (@lhs - op).must.equal(0, ) else pre_bool_equality(op, ) end end alias_comparison_methods end return receiver end |
#pre_bool_construct_receiver ⇒ Object
139 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 139 alias_method :pre_bool_construct_receiver, :construct_receiver |
#relation_constraint(relation, bool_operand_or_fix, params) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 158 def relation_constraint(relation, bool_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 bool_operand_or_fix.respond_to? :to_minimodel_lin_exp bool_operand_or_fix = Linear::ExpressionNode.new(bool_operand_or_fix); end params.update(:rhs => bool_operand_or_fix, :relation_type => relation_type) LinearRelationConstraint.new(model, params) end |
#to_minimodel_lin_exp ⇒ Object
Converts the linear expression to an instance of Gecode::Raw::MiniModel::LinExpr
135 136 137 |
# File 'lib/gecoder/interface/constraints/bool/linear.rb', line 135 def to_minimodel_lin_exp @left.to_minimodel_lin_exp.send(@operation, @right.to_minimodel_lin_exp) end |