#!/usr/bin/ruby module ConstraintSolver # Represents a constraint. To be used as a guidance to see which methods # constraints need to implement. class AbstractConstraint # Checks whether the constraint holds for the current assignments of the # involved variables. def holds? raise RuntimeError, "must implement holds?" end # Checks whether all variables involved in the constraint have values # assigned to them. def allAssigned? raise RuntimeError, "must implement allAssigned?" end # Checks whether the constraint includes variable. def include?(variable) raise RuntimeError, "must implement include?(variable)" end # Iterates over all the variables involved in the constraint. def each raise RuntimeError, "must implement each" end # 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. def revise raise RuntimeError, "must implement revise" end # 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. def violationCost raise RuntimeError, "must implement violationCost" end end end