Sha256: 8282dbccfbb2276137ebc53a3121057d0d6d5b98734dad933f34b5364b736019

Contents?: true

Size: 816 Bytes

Versions: 2

Compression:

Stored size: 816 Bytes

Contents

class Gurobi < Solver
  def solve
    command = "#{executable} ResultFile=#{@outfile} %s %s %s #{@filename}"
    command %= [
      options[:gap] ? "MipGap=#{options[:gap]}":"",
      options[:node_limit] ? "NodeLimit=#{options[:node_limit]}":"",
      ENV['RULP_GUROBI_CMD_ARGS'] ? ENV['RULP_GUROBI_CMD_ARGS'] : ''
    ]
    exec(command)
  end

  def self.executable
    :gurobi_cl
  end

  def store_results(variables)
    rows = IO.read(@outfile).split("\n")
    objective_str = rows[0].split(/\s+/)[-1]
    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.to_s].to_f
    end
    self.unsuccessful = rows.length.zero?
    return objective_str.to_f
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rulp-0.0.41 lib/solvers/gurobi.rb
rulp-0.0.40 lib/solvers/gurobi.rb