Class: ConstraintSolver::AbstractConstraint
- Inherits:
-
Object
- Object
- ConstraintSolver::AbstractConstraint
- Defined in:
- lib/AbstractConstraint.rb
Overview
Represents a constraint. To be used as a guidance to see which methods constraints need to implement.
Direct Known Subclasses
AllDifferentConstraint, BinaryConstraint, OneOfEqualsConstraint, TupleConstraint
Instance Method Summary collapse
-
#allAssigned? ⇒ Boolean
Checks whether all variables involved in the constraint have values assigned to them.
-
#each ⇒ Object
Iterates over all the variables involved in the constraint.
-
#holds? ⇒ Boolean
Checks whether the constraint holds for the current assignments of the involved variables.
-
#include?(variable) ⇒ Boolean
Checks whether the constraint includes variable.
-
#revise ⇒ Object
Prunes the values from the domains of the involved variables that cannot be assigned to the respective variables because the constraint would be violated.
-
#violationCost ⇒ Object
Returns the cost of violating the constraint.
Instance Method Details
#allAssigned? ⇒ Boolean
Checks whether all variables involved in the constraint have values assigned to them.
15 16 17 |
# File 'lib/AbstractConstraint.rb', line 15 def allAssigned? raise RuntimeError, "must implement allAssigned?" end |
#each ⇒ Object
Iterates over all the variables involved in the constraint.
25 26 27 |
# File 'lib/AbstractConstraint.rb', line 25 def each raise RuntimeError, "must implement each" end |
#holds? ⇒ Boolean
Checks whether the constraint holds for the current assignments of the involved variables.
9 10 11 |
# File 'lib/AbstractConstraint.rb', line 9 def holds? raise RuntimeError, "must implement holds?" end |
#include?(variable) ⇒ Boolean
Checks whether the constraint includes variable.
20 21 22 |
# File 'lib/AbstractConstraint.rb', line 20 def include?(variable) raise RuntimeError, "must implement include?(variable)" end |
#revise ⇒ Object
Prunes the values from the domains of the involved variables that cannot be assigned to the respective variables because the constraint would be violated. Returns a list of the variables whose domains were pruned, the number of times the constraint was checked, and whether a domain wipeout occured.
34 35 36 |
# File 'lib/AbstractConstraint.rb', line 34 def revise raise RuntimeError, "must implement revise" end |
#violationCost ⇒ Object
Returns the cost of violating the constraint. This should be infinity (or reasonably close to it) for hard constraints and a positive number for soft constraints.
41 42 43 |
# File 'lib/AbstractConstraint.rb', line 41 def violationCost raise RuntimeError, "must implement violationCost" end |