Sha256: 869527de12c40653f684be7de616a710770a77f056608a14f03caf6bef220c4d

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

class Solver
  attr_reader :options, :outfile

  def initialize(filename, options)
    @options = options
    @filename = filename
    @outfile = get_output_filename
    raise StandardError.new("Couldn't find solver #{executable}!") if `which #{executable}`.length == 0
    @solver_exists = true
  end

  def get_output_filename
    "/tmp/rulp-#{Random.rand(0..1000)}.sol"
  end

  def store_results(variables)
    puts "Not yet implemented"
  end

  def executable
    self.class.executable
  end

  def solver_exists?
    @solver_exists || false
  end

  def self.exists?
    return `which #{self.executable}`.length != 0
  end

  def next_pipe
    filename = "./tmp/_rulp_pipe"
    file_index = 1
    file_index += 1 while File.exists?("#{filename}_#{file_index}")
    pipe = "#{filename}_#{file_index}"
    `mkfifo #{pipe}`
    pipe
  end

  def with_pipe(pipe)
    output = open(pipe, 'w+')
    thread = Thread.new{
      yield output
      output.flush
    }
    return thread, output
  end

end

require_relative 'cbc'
require_relative 'scip'
require_relative 'glpk'
require_relative 'gurobi'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rulp-0.0.16 lib/solvers/solver.rb
rulp-0.0.15 lib/solvers/solver.rb