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.
238 239 240 241 |
# File 'lib/rglpk.rb', line 238 def initialize(problem, i) @p = problem @i = i end |
Instance Attribute Details
#i ⇒ Object
Returns the value of attribute i.
236 237 238 |
# File 'lib/rglpk.rb', line 236 def i @i end |
#p ⇒ Object
Returns the value of attribute p.
236 237 238 |
# File 'lib/rglpk.rb', line 236 def p @p end |
Instance Method Details
#bounds ⇒ Object
258 259 260 261 262 263 264 265 266 267 |
# File 'lib/rglpk.rb', line 258 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
284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/rglpk.rb', line 284 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
307 308 309 |
# File 'lib/rglpk.rb', line 307 def get_dual Glpk_wrapper.glp_get_row_dual(@p.lp, @i) end |
#get_prim ⇒ Object
303 304 305 |
# File 'lib/rglpk.rb', line 303 def get_prim Glpk_wrapper.glp_get_row_prim(@p.lp, @i) end |
#get_stat ⇒ Object
299 300 301 |
# File 'lib/rglpk.rb', line 299 def get_stat Glpk_wrapper.glp_get_row_stat(@p.lp, @i) end |
#name ⇒ Object
247 248 249 |
# File 'lib/rglpk.rb', line 247 def name Glpk_wrapper.glp_get_row_name(@p.lp, @i) end |
#name=(n) ⇒ Object
243 244 245 |
# File 'lib/rglpk.rb', line 243 def name=(n) Glpk_wrapper.glp_set_row_name(@p.lp, @i, n) end |
#set(v) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/rglpk.rb', line 269 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
251 252 253 254 255 256 |
# File 'lib/rglpk.rb', line 251 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 |