Class: Gecode::Set::Connection::SetSumOperand

Inherits:
Int::ShortCircuitEqualityOperand show all
Defined in:
lib/gecoder/interface/constraints/set/connection.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Int::ShortCircuitEqualityOperand

#model

Instance Method Summary collapse

Methods inherited from Int::ShortCircuitEqualityOperand

#construct_receiver, #to_int_var

Methods included from Int::IntOperand

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

Methods included from Operand

#model, #must, #must_not

Constructor Details

#initialize(model, set_op, subs) ⇒ SetSumOperand

Returns a new instance of SetSumOperand.



106
107
108
109
110
# File 'lib/gecoder/interface/constraints/set/connection.rb', line 106

def initialize(model, set_op, subs)
  super model
  @set = set_op
  @subs = subs
end

Dynamic Method Handling

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

Instance Method Details

#constrain_equal(int_operand, constrain, propagation_options) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/gecoder/interface/constraints/set/connection.rb', line 112

def constrain_equal(int_operand, constrain, propagation_options)
  set = @set.to_set_var
  lub = set.upper_bound.to_a
  lub.delete_if{ |e| @subs[e].nil? }
  substituted_lub = lub.map{ |e| @subs[e] }
  if constrain
    # Compute the theoretical bounds of the weighted sum. This is slightly
    # sloppy since we could also use the contents of the greatest lower 
    # bound.
    min = substituted_lub.find_all{ |e| e < 0}.inject(0){ |x, y| x + y }
    max = substituted_lub.find_all{ |e| e > 0}.inject(0){ |x, y| x + y }
    int_operand.must_be.in min..max
  end

  Gecode::Raw::weights(@model.active_space, lub, substituted_lub, 
    set.bind, int_operand.to_int_var.bind)
end