#!/usr/bin/ruby module ConstraintSolver # This class represents a list of constraints. class ConstraintList < Array # Returns the ConstraintList that contains all constraints that involve # variable and have values assigned to not all variables involved. def notAllAssignedWithVariable(variable) ConstraintList.new(self.select { |constraint| constraint.include?(variable) and not constraint.allAssigned? }) end # # Returns the ConstraintList that contains all constraints that involve # variable. def allWithVariable(variable) ConstraintList.new(self.select { |constraint| constraint.include?(variable) }) end def sort(&block) ConstraintList.new(self.sort!(&block)) end def -(element) new = self.to_a - (element.kind_of?(Array) ? element : [ element ]) return ConstraintList.new(new) end end end