+ def __str__(self):
+ """
+ Output a human-readable description of myself.
+ """
+ tpl = 'Cartesian product of dimension {:d} with {:d} factors:'
+ tpl += '\n * {!s}' * len(self.factors())
+ format_args = [self.dimension(), len(self.factors())]
+ format_args += list(self.factors())
+ return tpl.format(*format_args)
+
+ def __contains__(self, point):
+ """
+ Return whether or not ``point`` belongs to this cone.
+
+ INPUT:
+
+ An instance of the ``cvxopt.base.matrix`` class having
+ dimensions ``(n,1)`` where ``n`` is the dimension of this cone.
+
+ EXAMPLES:
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> matrix([1,2,3,1,0.5,0.5]) in K
+ True
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> matrix([0,0,0,1,0,1]) in K
+ True
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> matrix([1,1,1,1,1,1]) in K
+ False
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> matrix([1,-1,1,1,0,1]) in K
+ False
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> [1,2,3,4,5,6] in K
+ Traceback (most recent call last):
+ ...
+ TypeError: the given point is not a cvxopt.base.matrix
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> matrix([1,2]) in K
+ Traceback (most recent call last):
+ ...
+ TypeError: the given point has the wrong dimensions
+
+ """
+ if not isinstance(point, matrix):
+ raise TypeError('the given point is not a cvxopt.base.matrix')
+ if not point.size == (self.dimension(), 1):
+ raise TypeError('the given point has the wrong dimensions')
+
+ for factor in self.factors():
+ # Split off the components of ``point`` corresponding to
+ # ``factor``.
+ factor_part = point[0:factor.dimension()]
+ if not factor_part in factor:
+ return False
+ point = point[factor.dimension():]
+
+ return True
+
+
+ def contains_strict(self, point):
+ """
+ Return whether or not ``point`` belongs to the interior
+ of this cone.
+
+ INPUT:
+
+ An instance of the ``cvxopt.base.matrix`` class having
+ dimensions ``(n,1)`` where ``n`` is the dimension of this cone.
+
+ EXAMPLES:
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> K.contains_strict(matrix([1,2,3,1,0.5,0.5]))
+ True
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> K.contains_strict(matrix([1,2,3,1,0,1]))
+ False
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> K.contains_strict(matrix([0,1,1,1,0.5,0.5]))
+ False
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> K.contains_strict(matrix([1,1,1,1,1,1]))
+ False
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> K.contains_strict(matrix([1,-1,1,1,0,1]))
+ False
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> K.contains_strict([1,2,3,4,5,6])
+ Traceback (most recent call last):
+ ...
+ TypeError: the given point is not a cvxopt.base.matrix
+
+ >>> K = CartesianProduct(NonnegativeOrthant(3), IceCream(3))
+ >>> K.contains_strict(matrix([1,2]))
+ Traceback (most recent call last):
+ ...
+ TypeError: the given point has the wrong dimensions
+
+ """
+ if not isinstance(point, matrix):
+ raise TypeError('the given point is not a cvxopt.base.matrix')
+ if not point.size == (self.dimension(), 1):
+ raise TypeError('the given point has the wrong dimensions')
+
+ for factor in self.factors():
+ # Split off the components of ``point`` corresponding to
+ # ``factor``.
+ factor_part = point[0:factor.dimension()]
+ if not factor.contains_strict(factor_part):
+ return False
+ point = point[factor.dimension():]
+
+ return True
+
+