summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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)