Sha256: 5513f2885161dcb4ca8840faac47247b2dbe69e00dad84677a147cc2c65c54aa

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 Bytes

Contents

require 'tempfile'

module Ravensat
  class Solver
    attr_accessor :name
    def initialize( default_solver_name = "arcteryx" )
      @name = default_solver_name
      # @cnf = Array.new
      # @nr_vars
      # @nr_clses
    end

    # def <<( clause )
    #   'this is << method'
    # end

    def solve( cnf )
      encoder = DimacsEncoder.new
      @input_file = Tempfile.open(["ravensat",".cnf"])
      @output_file = Tempfile.open(["ravensat",".mdl"])

      @input_file.write encoder.to_dimacs(cnf)
      @input_file.flush

      case @name
      when "arcteryx"
        Arcteryx.solve(@input_file.to_path, @output_file.to_path)
      else
        system("#{@name} #{@input_file.to_path} #{@output_file.to_path}")
      end

      decoder = DimacsDecoder.new
      model = @output_file.read.split("\n")
      decoder.decode(model, encoder.name_table)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ravensat-0.3.0 lib/ravensat/solver.rb
ravensat-0.2.2 lib/ravensat/solver.rb
ravensat-0.2.1 lib/ravensat/solver.rb