Module: CSP::Solver::ConvenientConstraints
- Included in:
- Problem
- Defined in:
- lib/csp/solver/convenient_constraints.rb
Overview
These methods are convenience methods to allow you to set common constraints (predicates) on your Problem.
Instance Method Summary collapse
Instance Method Details
#all_different(vars) ⇒ Object
15 16 17 |
# File 'lib/csp/solver/convenient_constraints.rb', line 15 def all_different(vars) all_pairs(vars) { |x, y| x != y } end |
#all_pairs(vars, &block) ⇒ Object
6 7 8 9 |
# File 'lib/csp/solver/convenient_constraints.rb', line 6 def all_pairs(vars, &block) pairs = vars.repeated_combination(2).reject { |x, y| x == y } pairs.each { |x, y| constrain(x, y, &block) } end |
#all_same(vars) ⇒ Object
11 12 13 |
# File 'lib/csp/solver/convenient_constraints.rb', line 11 def all_same(vars) all_pairs(vars) { |x, y| x == y } end |