Skip to content

Commit 390e848

Browse files
committed
TestLPSolver: avoid LPSolver copy (pb with statistics?)
1 parent c534af4 commit 390e848

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

tests/TestLPSolver.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,42 @@ void TestLinearSolver::test01() {
4040

4141
}
4242

43-
LPSolver TestLinearSolver::create_kleemin(int n) {
44-
LPSolver lp(n, LPSolver::Mode::Certified);
43+
LPSolver* TestLinearSolver::create_kleemin(int n) {
44+
LPSolver* lp = new LPSolver(n, LPSolver::Mode::Certified);
4545
Vector v(n);
4646

4747
for (int j=1;j<=n;j++) {
4848
v[j-1]= ::pow(10,n-j);
4949
}
50-
lp.set_cost(-v);
50+
lp->set_cost(-v);
5151

52-
IntervalVector bound (n, Interval(0, 1e200));
53-
lp.set_bounds(bound);
52+
IntervalVector bound (n, Interval(0,1e200));
53+
lp->set_bounds(bound);
5454

5555
for (int i=1;i<=n;i++) {
5656
v=Vector::zeros(n);
5757
for (int j=1;j<=i-1;j++) {
5858
v[j-1]= 2*(::pow(10,i-j));
5959
}
6060
v[i-1] =1;
61-
lp.add_constraint(v,LEQ, ::pow(10,i-1));
61+
lp->add_constraint(v,LEQ, ::pow(10,i-1));
6262
}
6363

6464
return lp;
6565
}
6666

6767
void TestLinearSolver::kleemin( int n) {
68-
LPSolver lp(create_kleemin(n));
68+
LPSolver* lp = create_kleemin(n);
6969

70-
LPSolver::Status res = lp.minimize();
70+
LPSolver::Status res = lp->minimize();
7171
CPPUNIT_ASSERT(res==LPSolver::Status::OptimalProved);
7272

73-
Vector dualsol = lp.not_proved_dual_sol();
74-
Vector primalsol = lp.not_proved_primal_sol();
73+
Vector dualsol = lp->not_proved_dual_sol();
74+
Vector primalsol = lp->not_proved_primal_sol();
7575
Vector vrai(n);
7676
vrai[n-1] = ::pow(10,n-1);
7777
check_relatif(vrai,primalsol,1.e-9);
78+
delete lp;
7879
}
7980

8081
void TestLinearSolver::kleemin30() {
@@ -140,38 +141,39 @@ void TestLinearSolver::kleemin30() {
140141
}
141142

142143
void TestLinearSolver::reset() {
143-
LPSolver lp(create_kleemin(8));
144+
LPSolver* lp = create_kleemin(8);
144145
int n = 3;
145-
lp.reset(n);
146+
lp->reset(n);
146147

147148
// copy-past kleemin to
148149
Vector v(n);
149150

150151
for (int j=1;j<=n;j++) {
151152
v[j-1]= ::pow(10,n-j);
152153
}
153-
lp.set_cost(-v);
154+
lp->set_cost(-v);
154155

155156
IntervalVector bound (n, Interval(0, 1e200));
156-
lp.set_bounds(bound);
157+
lp->set_bounds(bound);
157158

158159
for (int i=1;i<=n;i++) {
159160
v=Vector::zeros(n);
160161
for (int j=1;j<=i-1;j++) {
161162
v[j-1]= 2*(::pow(10,i-j));
162163
}
163164
v[i-1] =1;
164-
lp.add_constraint(v,LEQ, ::pow(10,i-1));
165+
lp->add_constraint(v,LEQ, ::pow(10,i-1));
165166
}
166167

167-
LPSolver::Status res = lp.minimize();
168+
LPSolver::Status res = lp->minimize();
168169
CPPUNIT_ASSERT(res==LPSolver::Status::OptimalProved);
169170

170-
Vector dualsol = lp.not_proved_dual_sol();
171-
Vector primalsol = lp.not_proved_primal_sol();
171+
Vector dualsol = lp->not_proved_dual_sol();
172+
Vector primalsol = lp->not_proved_primal_sol();
172173
Vector vrai(n);
173174
vrai[n-1] = ::pow(10,n-1);
174175
check_relatif(vrai,primalsol,1.e-9);
176+
delete lp;
175177
}
176178

177179
void TestLinearSolver::test_known_problem(std::string filename, double optimal) {

tests/TestLPSolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TestLinearSolver : public CppUnit::TestFixture {
4848
#endif
4949

5050
CPPUNIT_TEST_SUITE_END();
51-
LPSolver create_kleemin(int n);
51+
LPSolver* create_kleemin(int n);
5252
void kleemin(int n);
5353

5454
void test01();

0 commit comments

Comments
 (0)