Sha256: 0907129e07e5721b370ef01b4fcc2d976196f7189bd92a35de14be9b792226ac

Contents?: true

Size: 743 Bytes

Versions: 12

Compression:

Stored size: 743 Bytes

Contents

class Gurobi < Solver
  def solve
    command = "#{executable} ResultFile=#{@outfile} %s %s #{@filename}"
    command %= [
      options[:gap] ? "MipGap=#{options[:gap]}":"",
      options[:node_limit] ? "NodeLimit=#{options[:node_limit]}":""
    ]
    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

12 entries across 12 versions & 1 rubygems

Version Path
rulp-0.0.39 lib/solvers/gurobi.rb
rulp-0.0.38 lib/solvers/gurobi.rb
rulp-0.0.37 lib/solvers/gurobi.rb
rulp-0.0.36 lib/solvers/gurobi.rb
rulp-0.0.35 lib/solvers/gurobi.rb
rulp-0.0.34 lib/solvers/gurobi.rb
rulp-0.0.33 lib/solvers/gurobi.rb
rulp-0.0.32 lib/solvers/gurobi.rb
rulp-0.0.29 lib/solvers/gurobi.rb
rulp-0.0.27 lib/solvers/gurobi.rb
rulp-0.0.26 lib/solvers/gurobi.rb
rulp-0.0.25 lib/solvers/gurobi.rb