Module: Amb::ClassMethods

Defined in:
lib/amb/amb.rb

Instance Method Summary collapse

Instance Method Details

#solve(failure_message = "No solution.") ⇒ Object

Class convenience method to search for the first solution to the constraints.


152
153
154
155
156
157
158
159
# File 'lib/amb/amb.rb', line 152

def solve(failure_message = "No solution.")
  amb = self.new
  yield(amb)
rescue Amb::ExhaustedError => ex
  puts
  puts "#{amb.branches_count} branches explored." if $DEBUG
  amb.report(failure_message)
end

#solve_all(failure_message = "No more solutions.") ⇒ Object

Class convenience method to search for all the solutions to the constraints.


164
165
166
167
168
169
170
171
172
# File 'lib/amb/amb.rb', line 164

def solve_all(failure_message = "No more solutions.")
  amb = self.new
  yield(amb)
  amb.failure
rescue Amb::ExhaustedError => ex
  puts
  puts "#{amb.branches_count} branches explored." if $DEBUG
  amb.report(failure_message)
end