Class | ConstraintSolver::Domain |
In: |
lib/Domain.rb
|
Parent: | Object |
This class represents the domain of a variable, i.e. a set of values that can be assigned to the variable.
undoStack | [R] | |
values | [R] |
Initialises a new domain. Optionally, a set of initial values can be given.
# File lib/Domain.rb, line 12 def initialize(values=nil) if not (values.nil? or values.kind_of?(Set)) raise ArgumentError, "Values must be a set!" end @values = values.nil? ? Set.new : values @undoStack = Array.new end
# File lib/Domain.rb, line 81 def ==(domain) return false unless domain.kind_of?(Domain) (@values == domain.values) and (@undoStack == domain.undoStack) end
Deletes value from the domain.
# File lib/Domain.rb, line 26 def delete(value) @values.delete(value) end
Prunes the values from the domain.
# File lib/Domain.rb, line 49 def prune(values) if not values.kind_of?(Set) values = Set.new([ values ]) end if values.empty? return end @undoStack.push(@values) @values -= values if @values.empty? self.undoPruning raise DomainWipeoutException end end