1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
# (c) 2000-2001 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307
# USA.
__revision__ = '$Id: interfaces.py,v 1.12 2005/07/12 15:07:59 alf Exp $'
class ConstraintInterface:
"""The interface that all constraints should implement"""
def isVariableRelevant(self, variable):
"""Returns true if changes in the domaine of the variable
should trigger an evaluation of the constraint"""
raise NotImplementedError
def affectedVariables(self):
""" Return a list of all variables affected by this constraint """
raise NotImplementedError
def estimateCost(self, domains):
""" Return an estimate of the cost of the narrowing of the constraint"""
raise NotImplementedError
def narrow(self, domains):
"""ensures that the domains are consistent with the constraint
Calls domain.removeValue to remove values from a domain
raises ConsistencyFailure if the narrowing fails
Returns 1 if the constraint is entailed, and 0 otherwise"""
raise NotImplementedError
class DomainInterface:
"""The interface that all domains should implement"""
def resetFlags(self):
"""resets the hasChanged flag"""
raise NotImplementedError
def hasChanged(self):
"""returns true if values have been removed from the domain
since the last call to resetFlags"""
raise NotImplementedError
def removeValue(self, value):
"""Removes a value from the domain"""
raise NotImplementedError
def size(self):
"""returns the number of values in the domain"""
raise NotImplementedError
def getValues(self):
"""returns a tuple containing all the values in the domain
These values should not be modified!"""
raise NotImplementedError
class DistributorInterface:
"""The interface that all distributors should implement"""
def distribute(self, domains, verbose=0):
"""domains is a dictionnary of variable -> Domain objects
This method returns a list of dictionnaries similar to the domain argument
This list should be a partition of the initial domains"""
raise NotImplementedError
## class VariableInterface:
## """The interface that all variables should implement"""
## def getDomain(self):
## """returns the domain of the variable"""
## raise NotImplementedError
## def setDomain(self, domain):
## """sets a new domain to the variable"""
## raise NotImplementedError
## # Magic methods for various operations
## def __add__(self, other):
## raise NotImplementedError
## def __sub__(self, other):
## raise NotImplementedError
## def __mul__(self, other):
## raise NotImplementedError
## def __div__(self, other):
## raise NotImplementedError
## def __radd__(self, other):
## raise NotImplementedError
## def __rsub__(self, other):
## raise NotImplementedError
## def __rmul__(self, other):
## raise NotImplementedError
## def __rdiv__(self, other):
## raise NotImplementedError
## def __abs__(self):
## raise NotImplementedError
## def __neg__(self):
## raise NotImplementedError
## def __pos__(self):
## raise NotImplementedError
## def __lt__(self, other):
## raise NotImplementedError
## def __le__(self, other):
## raise NotImplementedError
## def __gt__(self, other):
## raise NotImplementedError
## def __ge__(self, other):
## raise NotImplementedError
## def __eq__(self, other):
## raise NotImplementedError
## def __ne__(self, other):
## raise NotImplementedError
## def __len__(self):
## raise NotImplementedError
## def __getitem__(self, size):
## raise NotImplementedError
|