Method: ConstraintSolver::AllDifferentConstraint#holds?

Defined in:
lib/AllDifferentConstraint.rb

#holds?Boolean

Checks whether all the variables have different values assigned to them.

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/AllDifferentConstraint.rb', line 26

def holds?
    assigned = @variables.select { |var| var.assigned? }
    assigned.each { |variable|
  assigned.eachAfter(variable) { |otherVariable|
      if variable.value == otherVariable.value
    return false
      end
  }
    }
    return true
end