Esempio n. 1
0
 def __getitem__li(self, indexes):  # li for ListInt
     if isinstance(indexes, PartialConstraint):
         indexes = auxiliary().replace_partial_constraint(indexes)
     if isinstance(indexes, Variable):
         return PartialConstraint(ConstraintElement(self, indexes))
     if isinstance(indexes, tuple) and len(indexes) > 0:
         indexes = auxiliary().replace_partial_constraints(list(indexes))
         if any(isinstance(i, Variable) for i in indexes):  # this must be a constraint Element-Matrix
             assert is_matrix(self) and len(indexes) == 2, "A matrix is expected, with two indexes"
             if all(isinstance(i, Variable) for i in indexes):
                 return PartialConstraint(ConstraintElementMatrix(self, indexes[0], indexes[1]))
             else:
                 if isinstance(indexes[0], Variable) and isinstance(indexes[1], int):
                     return PartialConstraint(ConstraintElement(self[:, indexes[1]], indexes[0]))
                 elif isinstance(indexes[0], int) and isinstance(indexes[1], Variable):
                     return PartialConstraint(ConstraintElement(self[indexes[0]], indexes[1]))
                 else:
                     assert False
         result = OpOverrider.project_recursive(self, indexes, 0)
         try:
             return ListVar(result)  # TODO is it ListVar or ListInt ?
         except TypeError:
             return result
     result = list.__getitem__(self, indexes)
     try:
         return ListInt(result)
     except TypeError:
         return result
Esempio n. 2
0
 def _range_contains(self, other):  # for being able to use 'in' when expressing conditions of constraints
     if not OpOverrider.activated:
         return range.__contains__(other)
     if isinstance(other, ScalarProduct):
         other = PartialConstraint(ConstraintSum(other.variables, other.coeffs, None))  # functions.Sum(other)
     if isinstance(other, Variable):  # unary table constraint (based on a range)
         queue_in.append((list(self), other))
         return True
     if isinstance(other, PartialConstraint):
         queue_in.append((self, other))
         return True
     return range.__contains__(self, other)
Esempio n. 3
0
 def __ne__(self, other):
     if self is None or other is None:
         return object.__ne__(self, other)
     if isinstance(other, int) and other == 0 and isinstance(self, Node) and self.type == TypeNode.DIST:  # we simplify the expression
         return Node.build(TypeNode.NE, self.sons[0], self.sons[1])
     return PartialConstraint.__ne__(other, self) if isinstance(other, PartialConstraint) else Node.build(TypeNode.NE, self, other)
Esempio n. 4
0
 def __le__(self, other):
     if self is None or other is None:
         return object.__le__(self, other)
     return PartialConstraint.__ge__(other, self) if isinstance(other, PartialConstraint) else Node.build(TypeNode.LE, self, other)
Esempio n. 5
0
 def __sub__(self, other):
     if isinstance(other, PartialConstraint):
         return PartialConstraint.combine_partial_objects(self, TypeNode.SUB, other)
     return Node.build(TypeNode.SUB, self, other)
Esempio n. 6
0
def _wrapping_by_complete_or_partial_constraint(ctr):
    condition = ctr.arguments[TypeCtrArg.CONDITION].content
    return ECtr(ctr) if condition is not None else PartialConstraint(ctr)