Skip to content

Commit 4b94661

Browse files
committed
allowing equality at other places when EqualityFirst is true
1 parent a405a11 commit 4b94661

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/GoldfarbIdnaniSolver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ internal::InitTermination GoldfarbIdnaniSolver::init_()
8181
processInitialActiveSetWithEqualityOnly();
8282
initializeComputationData();
8383
initializePrimalDualPoints();
84+
85+
// Adding remaining equality constraints
86+
initActiveSet();
8487
}
8588
else
8689
{
@@ -286,7 +289,7 @@ void GoldfarbIdnaniSolver::resize_(int nbVar, int /*nbCstr*/, bool /*useBounds*/
286289

287290
void GoldfarbIdnaniSolver::initActiveSet()
288291
{
289-
for(int i = 0; i < A_.nbCstr(); ++i)
292+
for(int i = A_.nbActiveCstr(); i < A_.nbCstr(); ++i)
290293
{
291294
if(pb_.bl[i] == pb_.bu[i])
292295
{

tests/OptionsTest.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ TEST_CASE("Test EqualityFirst")
5858
for(int i = 0; i < 10; ++i)
5959
{
6060
const int neq = 3;
61-
auto pb = QPProblem(randomProblem(ProblemCharacteristics(7, 7, neq, 8)));
61+
auto pb = QPProblem(randomProblem(ProblemCharacteristics(7, 7, neq, 11-neq)));
6262
pb.C.transposeInPlace();
6363

6464
for(int i = 0; i < neq; ++i)
6565
{
6666
REQUIRE_EQ(pb.l[i], pb.u[i]);
6767
}
6868

69+
Eigen::MatrixXd G = pb.G;
6970
auto llt = pb.G.llt();
7071
Eigen::MatrixXd L = llt.matrixL();
7172
Eigen::MatrixXd invL = L.inverse();
@@ -74,7 +75,7 @@ TEST_CASE("Test EqualityFirst")
7475
options.gFactorization(jrl::qp::GFactorization::NONE);
7576
options.equalityFirst(false);
7677
solver.options(options);
77-
solver.solve(pb.G, pb.a, pb.C, pb.l, pb.u, pb.xl, pb.xu);
78+
solver.solve(G, pb.a, pb.C, pb.l, pb.u, pb.xl, pb.xu);
7879
Eigen::VectorXd x0 = solver.solution();
7980

8081
options.equalityFirst(true);
@@ -104,6 +105,44 @@ TEST_CASE("Test EqualityFirst")
104105
}
105106
}
106107

108+
TEST_CASE("Test EqualityFirst with additional equalities")
109+
{
110+
jrl::qp::GoldfarbIdnaniSolver solver0(7, 11, false);
111+
jrl::qp::GoldfarbIdnaniSolver solver1(7, 11, false);
112+
jrl::qp::SolverOptions options;
113+
114+
for(int i = 0; i < 10; ++i)
115+
{
116+
const int neq = 4;
117+
auto pb = QPProblem(randomProblem(ProblemCharacteristics(7, 7, neq, 11 - neq)));
118+
pb.C.transposeInPlace();
119+
120+
for(int i = 0; i < neq; ++i)
121+
{
122+
REQUIRE_EQ(pb.l[i], pb.u[i]);
123+
}
124+
125+
//reorganize equality constraints
126+
pb.C.col(neq - 2).swap(pb.C.col(9));
127+
std::swap(pb.l[neq - 2], pb.l[9]);
128+
std::swap(pb.u[neq - 2], pb.u[9]);
129+
130+
options.gFactorization(jrl::qp::GFactorization::NONE);
131+
options.equalityFirst(false);
132+
solver0.options(options);
133+
Eigen::MatrixXd G = pb.G;
134+
solver0.solve(G, pb.a, pb.C, pb.l, pb.u, pb.xl, pb.xu);
135+
Eigen::VectorXd x0 = solver0.solution();
136+
137+
options.equalityFirst(true);
138+
solver1.options(options);
139+
solver1.solve(pb.G, pb.a, pb.C, pb.l, pb.u, pb.xl, pb.xu);
140+
Eigen::VectorXd x1 = solver1.solution();
141+
142+
FAST_CHECK_UNARY(x1.isApprox(x0));
143+
}
144+
}
145+
107146
TEST_CASE("Precomputed R")
108147
{
109148
const int nbVar = 7;

0 commit comments

Comments
 (0)