From 75c61877551a8a56dc37cc728c35ac03ac93c7e6 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 7 Jun 2024 16:28:05 +0200 Subject: Improve __str__ methods of constraints --- sumofsquares/constraints.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sumofsquares/constraints.py b/sumofsquares/constraints.py index 844cc37..f287a23 100644 --- a/sumofsquares/constraints.py +++ b/sumofsquares/constraints.py @@ -54,7 +54,7 @@ class EqualToZero(Constraint[E]): @override def __str__(self): - return f"{self.__class__.__qualname__}: {str(self.expression)}" + return f"{str(self.expression)} = 0" @dataclassabc(frozen=True) @@ -82,7 +82,7 @@ class NonNegative(Constraint[E]): @override def __str__(self): - s = f"{self.__class__.__qualname__}: {str(self.expression)}" + s = f"{str(self.expression)} >= 0" if self.domain: s += f"\n\t\t over {self.domain}" return s @@ -93,6 +93,10 @@ class PositiveSemiDefinite(Constraint[E]): """ Constrain a matrix to be positive semidefinite. """ expression: E + @override + def __str__(self): + return f"{str(self.expression)} is PSD" + @dataclassabc(frozen=True) class ExponentialCone(Constraint[E]): @@ -106,6 +110,10 @@ class ExponentialCone(Constraint[E]): """ expression: E + @override + def __str__(self): + return f"{str(self.expression)} in ExpCone" + # TODO: Create missing classes below and add support in # - SOSProblem.apply -- cgit v1.2.1