Class: Rglpk::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(problem, i) ⇒ Column

Returns a new instance of Column.



321
322
323
324
# File 'lib/rglpk.rb', line 321

def initialize(problem, i)
  @p = problem
  @j = i
end

Instance Attribute Details

#jObject

Returns the value of attribute j.



319
320
321
# File 'lib/rglpk.rb', line 319

def j
  @j
end

#pObject

Returns the value of attribute p.



319
320
321
# File 'lib/rglpk.rb', line 319

def p
  @p
end

Instance Method Details

#boundsObject



349
350
351
352
353
354
355
356
357
358
# File 'lib/rglpk.rb', line 349

def bounds
  t = Glpk_wrapper.glp_get_col_type(@p.lp, @j)
  lb = Glpk_wrapper.glp_get_col_lb(@p.lp, @j)
  ub = Glpk_wrapper.glp_get_col_ub(@p.lp, @j)
  
  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



375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/rglpk.rb', line 375

def get
  ind = Glpk_wrapper.new_intArray(@p.rows.size + 1)
  val = Glpk_wrapper.new_doubleArray(@p.rows.size + 1)
  len = Glpk_wrapper.glp_get_mat_col(@p.lp, @j, ind, val)
  col = Array.new(@p.rows.size, 0)
  len.times do |i|
    v = Glpk_wrapper.doubleArray_getitem(val, i + 1)
    j = Glpk_wrapper.intArray_getitem(ind, i + 1)
    col[j - 1] = v
  end
  Glpk_wrapper.delete_intArray(ind)
  Glpk_wrapper.delete_doubleArray(val)
  col
end

#get_primObject



390
391
392
# File 'lib/rglpk.rb', line 390

def get_prim
  Glpk_wrapper.glp_get_col_prim(@p.lp, @j)
end

#kindObject



338
339
340
# File 'lib/rglpk.rb', line 338

def kind
  Glpk_wrapper.glp_get_col_kind(@p.lp, @j)
end

#kind=(kind) ⇒ Object



334
335
336
# File 'lib/rglpk.rb', line 334

def kind=(kind)
  Glpk_wrapper.glp_set_col_kind(@p.lp, j, kind)
end

#mip_valObject



394
395
396
# File 'lib/rglpk.rb', line 394

def mip_val
  Glpk_wrapper.glp_mip_col_val(@p.lp, @j)
end

#nameObject



330
331
332
# File 'lib/rglpk.rb', line 330

def name
  Glpk_wrapper.glp_get_col_name(@p.lp, @j)
end

#name=(n) ⇒ Object



326
327
328
# File 'lib/rglpk.rb', line 326

def name=(n)
  Glpk_wrapper.glp_set_col_name(@p.lp, @j, n)
end

#set(v) ⇒ Object

Raises:

  • (RuntimeError)


360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/rglpk.rb', line 360

def set(v)
  raise RuntimeError unless v.size == @p.rows.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_col(@p.lp, @j, v.size, ind, val)
  
  Glpk_wrapper.delete_intArray(ind)
  Glpk_wrapper.delete_doubleArray(val)
end

#set_bounds(type, lb, ub) ⇒ Object

Raises:

  • (ArgumentError)


342
343
344
345
346
347
# File 'lib/rglpk.rb', line 342

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_col_bnds(@p.lp, @j, type, lb, ub)
end