class MIPPeR::Variable
Attributes
coefficient[R]
constraints[RW]
index[RW]
lower_bound[R]
model[RW]
name[R]
type[R]
upper_bound[R]
Public Class Methods
new(lb, ub, coeff, type, name = nil)
click to toggle source
# File lib/mipper/variable.rb, line 6 def initialize(lb, ub, coeff, type, name = nil) @lower_bound = lb @upper_bound = ub @coefficient = coeff @type = type @name = name @constraints = [] # These will be populated when this is added to a model @model = nil @index = nil end
Public Instance Methods
*(coeff)
click to toggle source
Create a {LinExpr} consisting of a single term which is this variable multiplied by a constant
# File lib/mipper/variable.rb, line 50 def *(coeff) fail TypeError unless coeff.is_a? Numeric LinExpr.new({ self => coeff }) end
+(other)
click to toggle source
# File lib/mipper/variable.rb, line 56 def +(other) case other when LinExpr other + self * 1.0 when Variable LinExpr.new({self => 1.0, other => 1.0}) else fail TypeError end end
inspect()
click to toggle source
Produce the name of the variable and the value if the model is solved
# File lib/mipper/variable.rb, line 68 def inspect if @model && @model.status == :optimized value = self.value else value = '?' end "#{@name} = #{value}" end
lower_bound=(lb)
click to toggle source
Set the variable lower bound
# File lib/mipper/variable.rb, line 20 def lower_bound=(lb) @model.set_variable_bounds @index, lb, @upper_bound unless @model.nil? @lower_bound = lb end
upper_bound=(ub)
click to toggle source
Set the variable upper bound
# File lib/mipper/variable.rb, line 26 def upper_bound=(ub) @model.set_variable_bounds @index, @lower_bound, ub unless @model.nil? @upper_bound = ub end
value()
click to toggle source
Get the final value of this variable
# File lib/mipper/variable.rb, line 32 def value # Model must be solved to have a value return nil unless @model && @model.status == :optimized value = @model.variable_value self case @type when :integer value.round when :binary [false, true][value.round] else value end end