Class: ConstraintSolver::AbstractConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/AbstractConstraint.rb

Overview

Represents a constraint. To be used as a guidance to see which methods constraints need to implement.

Instance Method Summary collapse

Instance Method Details

#allAssigned?Boolean

Checks whether all variables involved in the constraint have values assigned to them.

Returns:

  • (Boolean)

Raises:

  • (RuntimeError)


15
16
17
# File 'lib/AbstractConstraint.rb', line 15

def allAssigned?
    raise RuntimeError, "must implement allAssigned?"
end

#eachObject

Iterates over all the variables involved in the constraint.

Raises:

  • (RuntimeError)


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.

Returns:

  • (Boolean)

Raises:

  • (RuntimeError)


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.

Returns:

  • (Boolean)

Raises:

  • (RuntimeError)


20
21
22
# File 'lib/AbstractConstraint.rb', line 20

def include?(variable)
    raise RuntimeError, "must implement include?(variable)"
end

#reviseObject

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.

Raises:

  • (RuntimeError)


34
35
36
# File 'lib/AbstractConstraint.rb', line 34

def revise
    raise RuntimeError, "must implement revise"
end

#violationCostObject

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.

Raises:

  • (RuntimeError)


41
42
43
# File 'lib/AbstractConstraint.rb', line 41

def violationCost
    raise RuntimeError, "must implement violationCost"
end