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.



315
316
317
318
# File 'lib/rglpk.rb', line 315

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

Instance Attribute Details

#jObject

Returns the value of attribute j.



313
314
315
# File 'lib/rglpk.rb', line 313

def j
  @j
end

#pObject

Returns the value of attribute p.



313
314
315
# File 'lib/rglpk.rb', line 313

def p
  @p
end

Instance Method Details

#boundsObject



343
344
345
346
347
348
349
350
351
352
# File 'lib/rglpk.rb', line 343

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



369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/rglpk.rb', line 369

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



384
385
386
# File 'lib/rglpk.rb', line 384

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

#kindObject



332
333
334
# File 'lib/rglpk.rb', line 332

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

#kind=(kind) ⇒ Object



328
329
330
# File 'lib/rglpk.rb', line 328

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

#mip_valObject



388
389
390
# File 'lib/rglpk.rb', line 388

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

#nameObject



324
325
326
# File 'lib/rglpk.rb', line 324

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

#name=(n) ⇒ Object



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

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

#set(v) ⇒ Object

Raises:

  • (RuntimeError)


354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/rglpk.rb', line 354

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)


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

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