Class: MIPPeR::Variable
- Inherits:
-
Object
- Object
- MIPPeR::Variable
- Defined in:
- lib/mipper/variable.rb
Instance Attribute Summary collapse
-
#coefficient ⇒ Object
readonly
Returns the value of attribute coefficient.
-
#constraints ⇒ Object
Returns the value of attribute constraints.
-
#index ⇒ Object
Returns the value of attribute index.
-
#lower_bound ⇒ Object
Returns the value of attribute lower_bound.
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#upper_bound ⇒ Object
Returns the value of attribute upper_bound.
Instance Method Summary collapse
-
#*(coeff) ⇒ Object
Create a LinExpr consisting of a single term which is this variable multiplied by a constant.
- #+(other) ⇒ Object
-
#initialize(lb, ub, coeff, type, name = nil) ⇒ Variable
constructor
A new instance of Variable.
-
#inspect ⇒ Object
Produce the name of the variable and the value if the model is solved.
-
#value ⇒ Object
Get the final value of this variable.
Constructor Details
#initialize(lb, ub, coeff, type, name = nil) ⇒ Variable
Returns a new instance of Variable.
6 7 8 9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Attribute Details
#coefficient ⇒ Object (readonly)
Returns the value of attribute coefficient.
4 5 6 |
# File 'lib/mipper/variable.rb', line 4 def coefficient @coefficient end |
#constraints ⇒ Object
Returns the value of attribute constraints.
3 4 5 |
# File 'lib/mipper/variable.rb', line 3 def constraints @constraints end |
#index ⇒ Object
Returns the value of attribute index.
3 4 5 |
# File 'lib/mipper/variable.rb', line 3 def index @index end |
#lower_bound ⇒ Object
Returns the value of attribute lower_bound.
4 5 6 |
# File 'lib/mipper/variable.rb', line 4 def lower_bound @lower_bound end |
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/mipper/variable.rb', line 3 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/mipper/variable.rb', line 4 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/mipper/variable.rb', line 4 def type @type end |
#upper_bound ⇒ Object
Returns the value of attribute upper_bound.
4 5 6 |
# File 'lib/mipper/variable.rb', line 4 def upper_bound @upper_bound end |
Instance Method Details
#*(coeff) ⇒ Object
Create a LinExpr consisting of a single term which is this variable multiplied by a constant
50 51 52 53 54 |
# File 'lib/mipper/variable.rb', line 50 def *(coeff) fail TypeError unless coeff.is_a? Numeric LinExpr.new({ self => coeff }) end |
#+(other) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# 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 ⇒ Object
Produce the name of the variable and the value if the model is solved
68 69 70 71 72 73 74 75 76 |
# File 'lib/mipper/variable.rb', line 68 def inspect if @model && @model.status == :optimized value = self.value else value = '?' end "#{@name} = #{value}" end |
#value ⇒ Object
Get the final value of this variable
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |