class RAMS::Solvers::GLPK

Interface to the GNU Linear Programming Kit

Public Instance Methods

solver_command(model_path, solution_path, args) click to toggle source
# File lib/rams/solvers/glpk.rb, line 7
def solver_command(model_path, solution_path, args)
  ['glpsol', '--lp', model_path, '--output', solution_path] + args
end

Private Instance Methods

parse_dual(model, lines) click to toggle source
# File lib/rams/solvers/glpk.rb, line 32
def parse_dual(model, lines)
  start_idx = lines.index { |l| l =~ /Row name/ } + 2
  length = lines[start_idx, lines.length].index { |l| l == '' }
  lines[start_idx, length].map { |l| [model.constraints[l[7, 12].strip], l[-13, 13].to_f] }.to_h
end
parse_objective(_model, lines) click to toggle source
# File lib/rams/solvers/glpk.rb, line 22
def parse_objective(_model, lines)
  lines.select { |l| l =~ /^Objective/ }.first.split[3].to_f
end
parse_primal(model, lines) click to toggle source
# File lib/rams/solvers/glpk.rb, line 26
def parse_primal(model, lines)
  start_idx = lines.index { |l| l =~ /Column name/ } + 2
  length = lines[start_idx, lines.length].index { |l| l == '' }
  lines[start_idx, length].map { |l| [model.variables[l[7, 12].strip], l[23, 13].to_f] }.to_h
end
parse_status(_model, lines) click to toggle source
# File lib/rams/solvers/glpk.rb, line 13
def parse_status(_model, lines)
  status = lines.select { |l| l =~ /^Status/ }.first
  return :optimal if status =~ /optimal/i
  return :feasible if status =~ /feasibe/i
  return :infeasible if status =~ /empty/i
  return :unbounded if status =~ /unbounded/i
  :undefined
end