Sha256: 46289fb186e96818814d5358ce743d8d9c2ab21ed2d3f3f0f9370bc23fd7b953

Contents?: true

Size: 737 Bytes

Versions: 1

Compression:

Stored size: 737 Bytes

Contents

class Scip < Solver

  def self.executable
    :scip
  end

  def solve(open_solution=false)
    system("rm #{@outfile}; #{executable} -f #{@filename} -l #{@outfile}")
    `open #{@outfile}` if open_solution
  end

  def store_results(variables)
    results  = IO.read(@outfile)
    start    = results.sub(/.*?primal solution:.*?=+/m, "")
    stripped = start.sub(/Statistics.+/m, "").strip
    rows     = stripped.split("\n")

    objective = rows[0].split(/\s+/)[-1].to_f

    vars_by_name = {}
    rows[1..-1].each do |row|
      cols = row.strip.split(/\s+/)
      vars_by_name[cols[0].to_s] = cols[1].to_f
    end
    variables.each do |var|
      var.value = vars_by_name[var.name.to_s].to_f
    end

    return objective
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rulp-0.0.5 lib/solvers/scip.rb