Skip to content

Commit 004fac8

Browse files
authored
Merge pull request #18 from scipopt/var-isvoid
Add Var::isVoid
2 parents e845dd8 + fe8053a commit 004fac8

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

include/scippp/var.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ struct Var {
4848
* @return \c true iff the value of this variable in the primal solution is in range epsilon of 0.0.
4949
*/
5050
[[nodiscard]] bool isZero(const Solution& solution) const;
51+
52+
/**
53+
* Checks whether an existing %SCIP variable is wrapped or the wrapper is empty.
54+
* @since 1.2.0
55+
* @return \c true iff the wrapper is empty
56+
*/
57+
[[nodiscard]] bool isVoid() const;
5158
};
5259

5360
}

source/var.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ bool Var::isZero(const Solution& solution) const
2626
return SCIPisZero(solution.scip, getSolVal(solution));
2727
}
2828

29+
bool Var::isVoid() const
30+
{
31+
return var == nullptr;
32+
}
33+
2934
}

test/test_var.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,16 @@ BOOST_AUTO_TEST_CASE(IsZero)
6262
BOOST_TEST(model.isZero(x1.getSolVal(sol)));
6363
}
6464

65+
BOOST_AUTO_TEST_CASE(IsVoid)
66+
{
67+
scippp::Var x;
68+
BOOST_TEST(x.var == nullptr);
69+
BOOST_TEST(x.isVoid());
70+
71+
Model model("Simple");
72+
auto x1 = model.addVar("x_1", 1);
73+
BOOST_TEST(x1.var != nullptr);
74+
BOOST_TEST(!x1.isVoid());
75+
}
76+
6577
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)