Class: Rglpk::Row
- Inherits:
-
Object
- Object
- Rglpk::Row
- Defined in:
- lib/rglpk.rb
Instance Attribute Summary collapse
-
#i ⇒ Object
Returns the value of attribute i.
-
#p ⇒ Object
Returns the value of attribute p.
Instance Method Summary collapse
- #bounds ⇒ Object
- #get ⇒ Object
- #get_dual ⇒ Object
- #get_prim ⇒ Object
- #get_stat ⇒ Object
-
#initialize(problem, i) ⇒ Row
constructor
A new instance of Row.
- #name ⇒ Object
- #name=(n) ⇒ Object
- #set(v) ⇒ Object
- #set_bounds(type, lb, ub) ⇒ Object
Constructor Details
#initialize(problem, i) ⇒ Row
Returns a new instance of Row.
244 245 246 247 |
# File 'lib/rglpk.rb', line 244 def initialize(problem, i) @p = problem @i = i end |
Instance Attribute Details
#i ⇒ Object
Returns the value of attribute i.
242 243 244 |
# File 'lib/rglpk.rb', line 242 def i @i end |
#p ⇒ Object
Returns the value of attribute p.
242 243 244 |
# File 'lib/rglpk.rb', line 242 def p @p end |
Instance Method Details
#bounds ⇒ Object
264 265 266 267 268 269 270 271 272 273 |
# File 'lib/rglpk.rb', line 264 def bounds t = Glpk_wrapper.glp_get_row_type(@p.lp, @i) lb = Glpk_wrapper.glp_get_row_lb(@p.lp, @i) ub = Glpk_wrapper.glp_get_row_ub(@p.lp, @i) lb = (t == GLP_FR or t == GLP_UP) ? nil : lb ub = (t == GLP_FR or t == GLP_LO) ? nil : ub [t, lb, ub] end |
#get ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/rglpk.rb', line 290 def get ind = Glpk_wrapper.new_intArray(@p.cols.size + 1) val = Glpk_wrapper.new_doubleArray(@p.cols.size + 1) len = Glpk_wrapper.glp_get_mat_row(@p.lp, @i, ind, val) row = Array.new(@p.cols.size, 0) len.times do |i| v = Glpk_wrapper.doubleArray_getitem(val, i + 1) j = Glpk_wrapper.intArray_getitem(ind, i + 1) row[j - 1] = v end Glpk_wrapper.delete_intArray(ind) Glpk_wrapper.delete_doubleArray(val) row end |
#get_dual ⇒ Object
313 314 315 |
# File 'lib/rglpk.rb', line 313 def get_dual Glpk_wrapper.glp_get_row_dual(@p.lp, @i) end |
#get_prim ⇒ Object
309 310 311 |
# File 'lib/rglpk.rb', line 309 def get_prim Glpk_wrapper.glp_get_row_prim(@p.lp, @i) end |
#get_stat ⇒ Object
305 306 307 |
# File 'lib/rglpk.rb', line 305 def get_stat Glpk_wrapper.glp_get_row_stat(@p.lp, @i) end |
#name ⇒ Object
253 254 255 |
# File 'lib/rglpk.rb', line 253 def name Glpk_wrapper.glp_get_row_name(@p.lp, @i) end |
#name=(n) ⇒ Object
249 250 251 |
# File 'lib/rglpk.rb', line 249 def name=(n) Glpk_wrapper.glp_set_row_name(@p.lp, @i, n) end |
#set(v) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/rglpk.rb', line 275 def set(v) raise RuntimeError unless v.size == @p.cols.size ind = Glpk_wrapper.new_intArray(v.size + 1) val = Glpk_wrapper.new_doubleArray(v.size + 1) 1.upto(v.size){|x| Glpk_wrapper.intArray_setitem(ind, x, x)} v.each_with_index{|x, y| Glpk_wrapper.doubleArray_setitem(val, y + 1, x)} Glpk_wrapper.glp_set_mat_row(@p.lp, @i, v.size, ind, val) Glpk_wrapper.delete_intArray(ind) Glpk_wrapper.delete_doubleArray(val) end |
#set_bounds(type, lb, ub) ⇒ Object
257 258 259 260 261 262 |
# File 'lib/rglpk.rb', line 257 def set_bounds(type, lb, ub) raise ArgumentError unless TypeConstants.include?(type) lb = 0.0 if lb.nil? ub = 0.0 if ub.nil? Glpk_wrapper.glp_set_row_bnds(@p.lp, @i, type, lb.to_f, ub.to_f) end |