Skip to content

Commit 353f552

Browse files
authored
[_dq_quadprog_solver.py] Generalizing all cases for Aeq and A.
1 parent 9b101b8 commit 353f552

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

dqrobotics/solvers/_dq_quadprog_solver.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,35 @@ def solve_quadratic_program(self, H, f, A, b, Aeq, beq):
6262
:param beq: the m x 1 value for the inequality constraints.
6363
:return: the optimal x
6464
"""
65-
A_internal = A if A is not None else Aeq
66-
b_internal = b if b is not None else beq
67-
if A is not None and b is not None and Aeq is not None and beq is not None:
65+
if A is None and b is None and Aeq is None and beq is None:
66+
raise ValueError("A, b, Aeq, beq, cannot all be None.")
67+
if (A is None and b is not None) or (b is None and A is not None):
68+
raise ValueError(f"A={A} and b={b} must both be None or both not None.")
69+
if (Aeq is None and beq is not None) or (beq is None and Aeq is not None):
70+
raise ValueError(f"Aeq={Aeq} and beq={beq} must both be None or both not None.")
71+
72+
# Turn equality into a bounded inequality
73+
if Aeq is not None: # beq is None already checked by the ValueError
6874
if Aeq.shape == (0, 0) or beq.shape == 0:
6975
pass
7076
else:
71-
A_internal = np.vstack([A, Aeq, -Aeq])
77+
Aeq = np.vstack([Aeq, -Aeq])
7278
beq = beq.reshape(-1)
73-
b_internal = np.concatenate([b.reshape(-1), beq + self.equality_constraints_tolerance,
74-
-beq + self.equality_constraints_tolerance])
75-
else:
76-
raise ValueError("A, b, Aeq, beq, cannot all be None.")
79+
beq = np.concatenate([beq + self.equality_constraints_tolerance, -beq + self.equality_constraints_tolerance])
80+
81+
# Use (A,b), (Aeq,beq), or both.
82+
if Aeq is None:
83+
A_internal = A
84+
b_internal = b
85+
if A is None:
86+
A_internal = Aeq
87+
b_internal = beq
88+
if Aeq is not None and A is not None:
89+
A_internal = np.vstack([A, Aeq])
90+
b_internal = np.concatenate([b.reshape(-1), beq])
91+
92+
# Calls from DQRobotics CPP will trigger this condition
7793
if A_internal.shape == (0, 0) or b_internal.shape == 0:
78-
# Calls from DQRobotics CPP will trigger this condition
7994
A_internal = np.zeros((1, H.shape[0]))
8095
b_internal = np.zeros(1)
8196

0 commit comments

Comments
 (0)