diff options
author | Nao Pross <np@0hm.ch> | 2024-06-04 18:05:23 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-06-04 18:05:23 +0200 |
commit | 9dabb70d887fc9ab1a1aad870af88ec9385d3646 (patch) | |
tree | be2e589df7bc168e070616c7ae0059f7e256a9e5 | |
parent | Update variables to use symbols, see polymatrix dependency (diff) | |
download | sumofsquares-9dabb70d887fc9ab1a1aad870af88ec9385d3646.tar.gz sumofsquares-9dabb70d887fc9ab1a1aad870af88ec9385d3646.zip |
Make make_problem add PSatz automatically if necessary
Diffstat (limited to '')
-rw-r--r-- | sumofsquares/__init__.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/sumofsquares/__init__.py b/sumofsquares/__init__.py index e6af1e7..bd5ec6a 100644 --- a/sumofsquares/__init__.py +++ b/sumofsquares/__init__.py @@ -53,9 +53,9 @@ Class diagram: Arrows denote inheritance, diamonds indicate composition. ┃ ┃ ┃ ┌─.canon───────────────────────────────────────────────────┐ ┌─.variable─────────────────┐ ┃ ┏━━━polymatrix package━━━━━━━━━┓ ┃ │ │ │ │ ┃ ┃ ┃ - ┃ │ ┌────────────────────┐ │ │ ┌───────────┐ │ ┃ ┃ ┌──────────┐ ┌──────────┐ ┃ - ┃ │ │ Canonicalization │ │ │ │OptVariable│──────────┼──╋───╋─▶│ Variable │ │Expression│ ┃ - ┃ │ └────────────────────┘ │ │ └───────────┘ │ ┃ ┃ └──────────┘ └──────────┘ ┃ + ┃ │ ┌────────────────────┐ │ │ ┌───────────┐ │ ┃ ┃ ┌────────┐ ┌──────────┐ ┃ + ┃ │ │ Canonicalization │ │ │ │OptSymbol │──────────┼──╋───╋─▶│ Symbol │ │Expression│ ┃ + ┃ │ └────────────────────┘ │ │ └───────────┘ │ ┃ ┃ └────────┘ └──────────┘ ┃ ┃ │ ▲ │ │ ▲ │ ┃ ┃ │ ┃ ┃ │ ├────────────────────┐ │ │ │ │ ┃ ┃ ┌─────────┘ ┃ ┃ │ │ │ │ │ │ │ ┃ ┃ ◇ ┃ @@ -97,7 +97,7 @@ def make_problem( cost: Expression | None = None, constraints: Iterable[Constraint] = (), solver: Solver = Solver.CVXOPT, - psatz: type[Canonicalization] | None = None, + psatz: type[Canonicalization] = PutinarPSatz, ) -> SOSProblem: """ Create a sum-of-squares optimization problem. @@ -108,7 +108,13 @@ def make_problem( cost = poly.from_number(0) prob = SOSProblem(cost, constraints, solver) - if psatz is not None: + + needs_psatz = any(c.domain is not None + for c in (constr + for constr in constraints + if isinstance(constr, NonNegative))) + + if needs_psatz: return psatz(SOSProblem(cost, constraints, solver)) return prob |