summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-06-16 19:37:54 +0200
committerNao Pross <np@0hm.ch>2024-06-16 19:44:14 +0200
commitd93913bd46f7778e66e801ca3f62231536537bfc (patch)
treee05d7725a4638161f4bc2331e939126c97414d7f
parentImprove error message and comments (diff)
downloadsumofsquares-d93913bd46f7778e66e801ca3f62231536537bfc.tar.gz
sumofsquares-d93913bd46f7778e66e801ca3f62231536537bfc.zip
Fix sign bug in solvers
-rw-r--r--sumofsquares/solver/cvxopt.py10
-rw-r--r--sumofsquares/solver/scs.py11
2 files changed, 9 insertions, 12 deletions
diff --git a/sumofsquares/solver/cvxopt.py b/sumofsquares/solver/cvxopt.py
index cf0dc4e..11b7797 100644
--- a/sumofsquares/solver/cvxopt.py
+++ b/sumofsquares/solver/cvxopt.py
@@ -85,8 +85,8 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
if A_rows:
# b is multiplied by -1 because it is on the RHS
- b = cvxopt.matrix(np.vstack(b_rows)) * -1
- A = cvxopt.matrix(np.vstack(A_rows))
+ b = cvxopt.matrix(np.vstack(b_rows))
+ A = cvxopt.matrix(np.vstack(A_rows)) * -1
# Inequality, second order and PSD constraints
G_rows, h_rows = [], []
@@ -107,9 +107,9 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
# pprint(f"{h_rows = }")
if G_rows:
- # h is multiplied by -1 because it is on the RHS
- h = cvxopt.matrix(np.vstack(h_rows)) * -1
- G = cvxopt.matrix(np.vstack(G_rows))
+ # multiplied by -1 because it is on the RHS
+ h = cvxopt.matrix(np.vstack(h_rows))
+ G = cvxopt.matrix(np.vstack(G_rows)) * -1
# Format dims for CVXOPT
diff --git a/sumofsquares/solver/scs.py b/sumofsquares/solver/scs.py
index 7217b2c..1e474da 100644
--- a/sumofsquares/solver/scs.py
+++ b/sumofsquares/solver/scs.py
@@ -97,12 +97,10 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
q = prob.q
for (linear, constant) in prob.constraints["z"]:
- # -1 because RHS
- b_rows.append(-constant)
+ b_rows.append(constant)
A_rows.append(np.hstack(tuple(m for m in linear)))
for (linear, constant) in prob.constraints["l"]:
- # -1 because RHS
b_rows.append(-constant)
A_rows.append(np.hstack(tuple(m for m in linear)))
@@ -113,14 +111,13 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
raise NotImplementedError
for (linear, constant) in prob.constraints["s"]:
- # -1 because RHS
- b_rows.append(vec(-constant))
+ b_rows.append(vec(constant))
A_rows.append(np.hstack(tuple(vec(m) for m in linear)))
for (linear, constant) in prob.constraints["e"]:
for i in range(3):
b_rows.append(constant[i])
- A_rows.append(np.hstack(tuple(-m[i] for m in linear)))
+ A_rows.append(np.hstack(tuple(m[i] for m in linear)))
if prob.constraints["e*"]:
raise NotImplementedError
@@ -133,7 +130,7 @@ def solve_cone(prob: ConicProblem, verbose: bool = False,
assert q is None or P is None or len(A_rows) > 0, "Problem is unconstrained! Something is very wrong"
- A = np.vstack(A_rows)
+ A = np.vstack(A_rows) * -1
b = np.vstack(b_rows)
data = {