Class: Ravensat::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/ravensat/solver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_solver_name = "arcteryx") ⇒ Solver

Returns a new instance of Solver.



6
7
8
# File 'lib/ravensat/solver.rb', line 6

def initialize( default_solver_name = "arcteryx" )
  @name = default_solver_name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ravensat/solver.rb', line 5

def name
  @name
end

Instance Method Details

#solve(cnf) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ravensat/solver.rb', line 10

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