-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hedtke/make-upper-and-lower-bounds-optional
Make upper and lower bounds in addVar(s) optional
- Loading branch information
Showing
4 changed files
with
97 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "scippp/model.hpp" | ||
|
||
using namespace scippp; | ||
using namespace std; | ||
|
||
BOOST_AUTO_TEST_SUITE(AddVar) | ||
|
||
// lb nullopt ub value lNuD | ||
// lb nullopt ub nullopt lNuN | ||
// lb value ub value GetSolVal | ||
// lb value ub nullopt lDuN | ||
|
||
const SCIP_Real LB_DEFAULT { 0.0 }; | ||
const SCIP_Real UB_DEFAULT { 1.0 }; | ||
|
||
BOOST_AUTO_TEST_CASE(lDuN, *boost::unit_test::tolerance(1e-3)) | ||
{ | ||
Model m1("Simple"); | ||
auto x1 = m1.addVar("x_1", 1, VarType::CONTINUOUS, LB_DEFAULT, nullopt); | ||
auto x2 = m1.addVar("x_2", 1); | ||
m1.addConstr(x1 + x2 <= 1, "line"); | ||
m1.setObjsense(Sense::MINIMIZE); | ||
m1.solve(); | ||
BOOST_REQUIRE(m1.getNSols() > 0); | ||
BOOST_TEST(m1.getPrimalbound() == 0); | ||
|
||
Model m2("Simple"); | ||
x1 = m2.addVar("x_1", 1, VarType::CONTINUOUS, LB_DEFAULT, nullopt); | ||
x2 = m2.addVar("x_2", 1); | ||
m2.addConstr(x1 + x2 >= 1, "line"); | ||
m2.setObjsense(Sense::MAXIMIZE); | ||
m2.solve(); | ||
BOOST_TEST(m2.getStatus() == SCIP_STATUS_UNBOUNDED); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(lNuD, *boost::unit_test::tolerance(1e-3)) | ||
{ | ||
Model m1("Simple"); | ||
auto x1 = m1.addVar("x_1", 1, VarType::CONTINUOUS, nullopt, UB_DEFAULT); | ||
auto x2 = m1.addVar("x_2", 1); | ||
m1.addConstr(x1 + x2 <= 1, "line"); | ||
m1.setObjsense(Sense::MINIMIZE); | ||
m1.solve(); | ||
BOOST_TEST(m1.getStatus() == SCIP_STATUS_UNBOUNDED); | ||
|
||
Model m2("Simple"); | ||
x1 = m2.addVar("x_1", 1, VarType::CONTINUOUS, nullopt, UB_DEFAULT); | ||
x2 = m2.addVar("x_2", 1); | ||
m2.addConstr(x1 + x2 <= 1, "line"); | ||
m2.setObjsense(Sense::MAXIMIZE); | ||
m2.solve(); | ||
BOOST_REQUIRE(m2.getNSols() > 0); | ||
BOOST_TEST(m2.getPrimalbound() == 1); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(lNuN, *boost::unit_test::tolerance(1e-3)) | ||
{ | ||
Model m1("Simple"); | ||
auto x1 = m1.addVar("x_1", 1, VarType::CONTINUOUS, nullopt, nullopt); | ||
auto x2 = m1.addVar("x_2", 1); | ||
m1.addConstr(x1 + x2 <= 1, "line"); | ||
m1.setObjsense(Sense::MINIMIZE); | ||
m1.solve(); | ||
BOOST_TEST(m1.getStatus() == SCIP_STATUS_UNBOUNDED); | ||
|
||
Model m2("Simple"); | ||
x1 = m2.addVar("x_1", 1, VarType::CONTINUOUS, nullopt, nullopt); | ||
x2 = m2.addVar("x_2", 1); | ||
m2.addConstr(x1 + x2 <= 1, "line"); | ||
m2.setObjsense(Sense::MAXIMIZE); | ||
m2.solve(); | ||
BOOST_REQUIRE(m2.getNSols() > 0); | ||
BOOST_TEST(m2.getPrimalbound() == 1); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters