module CSP::Solver::ConvenientConstraints
These methods are convenience methods to allow you to set common constraints (predicates) on your Problem
.
Public Instance Methods
all_different(vars)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/csp/solver/convenient_constraints.rb, line 11 def all_same(vars) all_pairs(vars) { |x, y| x == y } end