summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-05-27 12:11:57 +0200
committerNao Pross <np@0hm.ch>2024-05-27 12:41:06 +0200
commit14627bc7087be16dd0dbe0d64ea853e0ab2c1b4d (patch)
tree26d769805fb6879e5a933fe6f660dbeedc963476
parentTemporary fix of ConicResult.value_of(v) for v that have shapes that are expr... (diff)
downloadsumofsquares-14627bc7087be16dd0dbe0d64ea853e0ab2c1b4d.tar.gz
sumofsquares-14627bc7087be16dd0dbe0d64ea853e0ab2c1b4d.zip
Fix bug when LP has no cost function
-rw-r--r--sumofsquares/__init__.py7
-rw-r--r--sumofsquares/problems.py4
2 files changed, 10 insertions, 1 deletions
diff --git a/sumofsquares/__init__.py b/sumofsquares/__init__.py
index 5d9f432..44dad85 100644
--- a/sumofsquares/__init__.py
+++ b/sumofsquares/__init__.py
@@ -96,7 +96,7 @@ def make_set(*polynomials: Iterable[Expression]):
def make_problem(
- cost: Expression,
+ cost: Expression | None = None,
constraints: Iterable[Constraint] = (),
solver: Solver = Solver.CVXOPT,
psatz: type[Canonicalization] = PutinarPSatz
@@ -104,6 +104,11 @@ def make_problem(
"""
Create a sum-of-squares optimization problem.
"""
+ if cost is None and not constraints:
+ raise ValueError("Problem is empty, is has neither a cost nor any constraints!")
+ elif cost is None:
+ cost = poly.from_number(0)
+
return psatz(SOSProblem(cost, constraints, solver))
diff --git a/sumofsquares/problems.py b/sumofsquares/problems.py
index 2800423..d884899 100644
--- a/sumofsquares/problems.py
+++ b/sumofsquares/problems.py
@@ -286,6 +286,10 @@ class InternalSOSProblem(Problem):
if q is not None:
q = q.reshape((-1, 1))
+ elif not is_qp:
+ # Allow LP without cost function
+ q = np.zeros((len(variable_indices), 1))
+
# cost quadratic term
if is_qp:
n = len(variable_indices)