summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sumofsquares/solver/cvxopt.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/sumofsquares/solver/cvxopt.py b/sumofsquares/solver/cvxopt.py
index e41633f..455ee5b 100644
--- a/sumofsquares/solver/cvxopt.py
+++ b/sumofsquares/solver/cvxopt.py
@@ -77,8 +77,11 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
# Equality constraints
A_rows, b_rows = [], []
for (linear, constant) in prob.constraints["z"]:
- b_rows.append(constant)
- A_rows.append(np.hstack(tuple(vectorize_matrix(m) for m in linear)).T)
+ b_rows.append(vectorize_matrix(constant))
+ A_rows.append(np.hstack(tuple(vectorize_matrix(m) for m in linear)))
+
+ # pprint(f"{A_rows = }")
+ # pprint(f"{b_rows = }")
if A_rows:
# b is multiplied by -1 because it is on the RHS
@@ -90,12 +93,13 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
for (linear, constant) in prob.constraints["l"]:
h_rows.append(constant)
- G_rows.append(np.hstack(tuple(m for m in linear)).T)
+ G_rows.append(np.hstack(tuple(m for m in linear)))
if prob.constraints["q"]:
raise NotImplementedError("SOC constraints are not implemented yet.")
for (linear, constant) in prob.constraints["s"]:
+ # b is multiplied by -1 because it is on the RHS
h_rows.append(vectorize_matrix(constant))
G_rows.append(np.hstack(tuple(vectorize_matrix(m) for m in linear)))
@@ -104,10 +108,17 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
if G_rows:
# h is multiplied by -1 because it is on the RHS
- h = cvxopt.matrix(np.vstack(h_rows).reshape((-1, 1))) * -1
+ h = cvxopt.matrix(np.vstack(h_rows)) * -1
G = cvxopt.matrix(np.vstack(G_rows))
+ # Format dims for CVXOPT
+ dims = {
+ "l": sum(prob.dims["l"]),
+ "q": prob.dims["q"],
+ "s": prob.dims["s"]
+ }
+
# Solve the problem
# pprint({"A": A, "b": b, "G": G, "h": h})
@@ -115,7 +126,7 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
if prob.is_qp:
assert P is not None, "Solving LP with QP solver! Something has gone wrong"
info = cvxopt.solvers.coneqp(P=P, q=q, G=G, h=h, A=A, b=b,
- dims=prob.dims, *args, **kwargs)
+ dims=dims, *args, **kwargs)
else:
assert q is not None, "LP has no objective! Something is very wrong"
info = cvxopt.solvers.conelp(c=q, G=G, h=h, A=A, b=b,