Skip to content

Commit c49ea05

Browse files
committed
Several changes
1. Misc edit to ipopt_capi 2. Adding solver tests
1 parent 01d5c53 commit c49ea05

File tree

4 files changed

+88
-7
lines changed

4 files changed

+88
-7
lines changed

Diff for: lib/coek/coek/solvers/ipopt/ipopt_capi.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ namespace coek {
3030

3131
int load_ipopt_library(const char* libname, std::string& error_message)
3232
{
33-
char buf[256];
34-
ipopt_handle = loadlib(libname, buf, 256);
33+
char buf[1024];
34+
ipopt_handle = loadlib(libname, buf, 1024);
3535
if (ipopt_handle == NULL) {
3636
error_message = buf;
3737
return 1;

Diff for: lib/coek/test/test_examples.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ TEST_CASE("ipopt_examples", "[smoke]")
288288
}
289289
# endif
290290
}
291+
else {
292+
SECTION("rosenbr")
293+
{
294+
auto m = rosenbr();
295+
coek::NLPModel nlp(m, adname);
296+
auto res = solver.solve(nlp);
297+
REQUIRE(res->termination_condition == coek::TerminationCondition::solver_not_available);
298+
}
299+
}
291300
#endif
292301
}
293302

@@ -298,7 +307,6 @@ TEST_CASE("gurobi_examples", "[smoke]")
298307
SECTION("simplelp1")
299308
{
300309
auto m = simplelp1();
301-
302310
solver.set_option("OutputFlag", 0);
303311
auto res = solver.solve(m);
304312
REQUIRE(coek::check_optimal_termination(res));
@@ -307,6 +315,13 @@ TEST_CASE("gurobi_examples", "[smoke]")
307315
REQUIRE(res->objective_bound == Approx(28750.0));
308316
check(m.get_variables(), simplelp1_soln);
309317
}
310-
// SECTION("simplelp1_solve") { simplelp1_solve(); }
318+
}
319+
else {
320+
SECTION("simplelp1")
321+
{
322+
auto m = simplelp1();
323+
auto res = solver.solve(m);
324+
REQUIRE(res->termination_condition == coek::TerminationCondition::solver_not_available);
325+
}
311326
}
312327
}

Diff for: lib/poek/poek/tests/test_solver.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
from poek import *
44

55

6-
def test_available():
6+
def test_available1():
77
opt = solver("bad_coek_solvername")
88
assert not opt.available
99

10+
def test_available2():
11+
m = model()
12+
x0 = m.add_variable(lower=0)
13+
x1 = m.add_variable(lower=0)
14+
m.add_objective(x0+x1)
15+
16+
opt = solver("bad_coek_solvername")
17+
res = opt.solve(m)
18+
assert res.termination_condition == "solver_not_available"
19+
20+
def test_available3():
21+
m = model()
22+
x0 = m.add_variable(lower=0)
23+
x1 = m.add_variable(lower=0)
24+
m.add_objective(x0+x1)
25+
nlp = nlp_model(m, "cppad")
26+
27+
opt = nlp_solver("bad_coek_solvername")
28+
res = opt.solve(nlp)
29+
assert res.termination_condition == "solver_not_available"
30+
1031

1132
def test_nlpsolver():
1233
m = model()
@@ -37,9 +58,13 @@ def test_rosenbr():
3758

3859
nlp = nlp_model(m, "cppad")
3960
opt = nlp_solver("ipopt")
61+
res = opt.solve(nlp)
62+
assert res.solver_name == "ipopt"
4063
if opt.available:
41-
res = opt.solve(nlp)
4264
assert check_optimal_termination(res)
43-
assert res.solver_name == "ipopt"
4465
assert x0.value == pytest.approx(1.0)
4566
assert x1.value == pytest.approx(1.0)
67+
else:
68+
assert res.termination_condition == "solver_not_available"
69+
70+

Diff for: lib/pyomo_coek/pyomo_coek/test/level1/test_solver.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
# Test variable API
3+
#
4+
import pytest
5+
6+
def test_available1(pyomo_module):
7+
opt = pyomo_module.SolverFactory("bad_pyomo_solvername")
8+
assert not opt.available(False)
9+
10+
def test_available2(pyomo_module):
11+
m = pyomo_module.ConcreteModel()
12+
m.x0 = pyomo_module.Var(bounds=(0,None))
13+
m.x1 = pyomo_module.Var(bounds=(0,None))
14+
m.o = pyomo_module.Objective(expr=m.x0+m.x1)
15+
16+
opt = pyomo_module.SolverFactory("bad_pyomo_solvername")
17+
with pytest.raises(RuntimeError) as e_info:
18+
res = opt.solve(m)
19+
20+
def test_gurobi(pyomo_module):
21+
m = pyomo_module.ConcreteModel()
22+
m.x0 = pyomo_module.Var(bounds=(0,None))
23+
m.x1 = pyomo_module.Var(bounds=(0,None))
24+
m.o = pyomo_module.Objective(expr=m.x0+m.x1)
25+
26+
opt = pyomo_module.SolverFactory("coek_gurobi")
27+
if opt.available(False):
28+
res = opt.solve(m)
29+
pyo.check_optimal_termination(m)
30+
31+
def test_ipopt(pyomo_module):
32+
m = pyomo_module.ConcreteModel()
33+
m.x0 = pyomo_module.Var(bounds=(0,None))
34+
m.x1 = pyomo_module.Var(bounds=(0,None))
35+
m.o = pyomo_module.Objective(expr=m.x0+m.x1)
36+
37+
opt = pyomo_module.SolverFactory("coek_ipopt")
38+
if opt.available(False):
39+
res = opt.solve(m)
40+
pyo.check_optimal_termination(m)
41+

0 commit comments

Comments
 (0)