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.



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

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#solve(cnf, solver_log: false) ⇒ Object



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

def solve( cnf , solver_log: false)
  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
    result, err, status = Open3.capture3("#{@name} #{@input_file.to_path} #{@output_file.to_path}")
    puts result if solver_log
  end

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