class TypeAnnArg(AbstractType): TYPE = auto() STATIC, RANDOM, MIN, MAX = auto(4) LC = auto() ORDER = auto() CONSISTENCY, BRANCHING, CUTOFF, FACTOR = auto(4) START_INDEX, START_ROW_INDEX, START_COL_INDEX = auto(3)
class TypeNode(Enum): def __init__(self, id, min_arity, max_arity): self.id = id self.min_arity = min_arity self.max_arity = max_arity self.lowercase_name = self.name.lower() def __str__(self): return self.lowercase_name ''' 0-ary ''' VAR, PAR, INT, RATIONAL, DECIMAL, SYMBOL, PARTIAL = ((id, 0, 0) for id in auto(7)) ''' Unary''' NEG, ABS, SQR, NOT, CARD, HULL, CONVEX, SQRT, EXP, LN, SIN, COS, TAN, ASIN, ACOS, ATAN, SINH, COSH, TANH = ( (id, 1, 1) for id in auto(19)) ''' Binary ''' SUB, DIV, MOD, POW, DIST, LT, LE, GE, GT, IN, NOTIN, IMP, DIFF, DJOINT, SUBSET, SUBSEQ, SUPSEQ, SUPSET, FDIV, FMOD, = ( (id, 2, 2) for id in auto(20)) ''' Ternary ''' IF = (auto(), 3, 3) ''' N-ary (2 to infinity)''' ADD, MUL, MIN, MAX, NE, EQ, AND, OR, XOR, IFF, UNION, INTER, SDIFF = ( (id, 2, float("inf")) for id in auto(13)) SET = (auto(), 0, float("inf")) SPECIAL = (auto(), 0, float("inf")) def is_leaf(self): return self == TypeNode.SPECIAL or (self.min_arity == self.max_arity == 0) def is_valid_arity(self, k): return self.min_arity <= k <= self.max_arity def is_logical_operator(self): return self in { TypeNode.NOT, TypeNode.AND, TypeNode.OR, TypeNode.XOR, TypeNode.IFF, TypeNode.IMP } def is_relational_operator(self): return self in { TypeNode.LT, TypeNode.LE, TypeNode.GE, TypeNode.GT, TypeNode.EQ, TypeNode.NE } def is_predicate_operator(self): return self.is_logical_operator() or self.is_relational_operator( ) or self in {TypeNode.IN, TypeNode.NOTIN}
class TypeRestart(AbstractType): LUBY, GEOMETRIC = auto(2)
class TypeBranching(AbstractType): TWO_WAY, D_WAY = auto(2) def __str__(self): return self.name.replace("_", "-").replace("TWO", "2").lower()
class TypeConsistency(AbstractType): FC, BC, AC, SAC, FPWC, PC, CDC, FDAC, EDAC, VAC = auto(10) def __str__(self): return self.name
class TypeValHeuristic(AbstractType): CONFLICTS, VALUE = auto(2)
class TypeVarHeuristic(AbstractType): LEXICO, DOM, DEG, DDEG, WDEG, IMPACT, ACTIVITY = auto(7)
class TypeNode(Enum): def __init__(self, id, min_arity, max_arity): self.id = id self.min_arity = min_arity self.max_arity = max_arity self.lowercase_name = self.name.lower() def __str__(self): return self.lowercase_name ''' 0-ary ''' VAR, INT, RATIONAL, DECIMAL, SYMBOL, PARTIAL, COL = ((id, 0, 0) for id in auto(7)) ''' Unary''' NEG, ABS, SQR, NOT, CARD, HULL, CONVEX, SQRT, EXP, LN, SIN, COS, TAN, ASIN, ACOS, ATAN, SINH, COSH, TANH = ( (id, 1, 1) for id in auto(19)) ''' Binary ''' SUB, DIV, MOD, POW, DIST, LT, LE, GE, GT, IN, NOTIN, IMP, DIFF, DJOINT, SUBSET, SUBSEQ, SUPSEQ, SUPSET, FDIV, FMOD, = ( (id, 2, 2) for id in auto(20)) ''' Ternary ''' IF = (auto(), 3, 3) ''' N-ary (2 to infinity)''' ADD, MUL, MIN, MAX, NE, EQ, AND, OR, XOR, IFF, UNION, INTER, SDIFF = ( (id, 2, float("inf")) for id in auto(13)) SET = (auto(), 0, float("inf")) SPECIAL = (auto(), 0, float("inf")) def is_leaf(self): return self == TypeNode.SPECIAL or (self.min_arity == self.max_arity == 0) def is_valid_arity(self, k): return self.min_arity <= k <= self.max_arity def is_logical_operator(self): return self in { TypeNode.NOT, TypeNode.AND, TypeNode.OR, TypeNode.XOR, TypeNode.IFF, TypeNode.IMP } def is_relational_operator(self): return self in { TypeNode.LT, TypeNode.LE, TypeNode.GE, TypeNode.GT, TypeNode.EQ, TypeNode.NE } def is_predicate_operator(self): return self.is_logical_operator() or self.is_relational_operator( ) or self in {TypeNode.IN, TypeNode.NOTIN} @staticmethod def value_of(v): if isinstance(v, TypeNode): return v if isinstance(v, TypeOrderedOperator): v = str(v) # so as to be intercepted just below if isinstance(v, str): if v in ("<", "lt"): return TypeNode.LT if v in ("<=", "le"): return TypeNode.LE if v in (">=", "ge"): return TypeNode.GE if v in (">", "gt"): return TypeNode.GT if v in ("=", "==", "eq"): return TypeNode.EQ if v in ("!=", "<>", "ne"): return TypeNode.NE return TypeNode[v.upper()] if isinstance(v, TypeConditionOperator): return TypeNode[str(v).upper()] return None # other cases to handle?