Class: Rglpk::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/rglpk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#iObject

Returns the value of attribute i.



236
237
238
# File 'lib/rglpk.rb', line 236

def i
  @i
end

#pObject

Returns the value of attribute p.



236
237
238
# File 'lib/rglpk.rb', line 236

def p
  @p
end

Instance Method Details

#boundsObject



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

#getObject



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_dualObject



307
308
309
# File 'lib/rglpk.rb', line 307

def get_dual
  Glpk_wrapper.glp_get_row_dual(@p.lp, @i)
end

#get_primObject



303
304
305
# File 'lib/rglpk.rb', line 303

def get_prim
  Glpk_wrapper.glp_get_row_prim(@p.lp, @i)
end

#get_statObject



299
300
301
# File 'lib/rglpk.rb', line 299

def get_stat
  Glpk_wrapper.glp_get_row_stat(@p.lp, @i)
end

#nameObject



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

Raises:

  • (RuntimeError)


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

Raises:

  • (ArgumentError)


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