Class: SolutionEnumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/whatnot/solution_enumerator.rb

Instance Method Summary collapse

Constructor Details

#initialize(solution_interpreter, dimacs = "") ⇒ SolutionEnumerator

Returns a new instance of SolutionEnumerator.



4
5
6
7
# File 'lib/whatnot/solution_enumerator.rb', line 4

def initialize(solution_interpreter, dimacs="")
  @dimacs = dimacs
  @solution_interpreter = solution_interpreter
end

Instance Method Details

#eachObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/whatnot/solution_enumerator.rb', line 22

def each
  solution = next_solution()

  while solution.start_with?("SAT") do
    clean_up_solution!(solution)

    yield @solution_interpreter.call(solution)

    @dimacs += ("\n" + inverse_of(solution))

    solution = next_solution()
  end
end

#next_solutionObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/whatnot/solution_enumerator.rb', line 9

def next_solution
  infile   = "/tmp/SolutionEnumerator-in.txt"
  outfile  = "/tmp/SolutionEnumerator-out.txt"

  File.open(infile, "w+") do |file|
    file << @dimacs
  end

  `minisat -rnd-init -rnd-seed=#{Time.now.to_i} #{infile} #{outfile} 2>&1 >/dev/null`

  File.read(outfile)
end