diff --git a/include/scippp/var.hpp b/include/scippp/var.hpp index 0d054e73..7a5675a5 100644 --- a/include/scippp/var.hpp +++ b/include/scippp/var.hpp @@ -48,6 +48,13 @@ struct Var { * @return \c true iff the value of this variable in the primal solution is in range epsilon of 0.0. */ [[nodiscard]] bool isZero(const Solution& solution) const; + + /** + * Checks whether an existing %SCIP variable is wrapped or the wrapper is empty. + * @since 1.2.0 + * @return \c true iff the wrapper is empty + */ + [[nodiscard]] bool isVoid() const; }; } diff --git a/source/var.cpp b/source/var.cpp index 64d3c2b8..21298846 100644 --- a/source/var.cpp +++ b/source/var.cpp @@ -26,4 +26,9 @@ bool Var::isZero(const Solution& solution) const return SCIPisZero(solution.scip, getSolVal(solution)); } +bool Var::isVoid() const +{ + return var == nullptr; +} + } diff --git a/test/test_var.cpp b/test/test_var.cpp index 062756ea..fb516f30 100644 --- a/test/test_var.cpp +++ b/test/test_var.cpp @@ -62,4 +62,16 @@ BOOST_AUTO_TEST_CASE(IsZero) BOOST_TEST(model.isZero(x1.getSolVal(sol))); } +BOOST_AUTO_TEST_CASE(IsVoid) +{ + scippp::Var x; + BOOST_TEST(x.var == nullptr); + BOOST_TEST(x.isVoid()); + + Model model("Simple"); + auto x1 = model.addVar("x_1", 1); + BOOST_TEST(x1.var != nullptr); + BOOST_TEST(!x1.isVoid()); +} + BOOST_AUTO_TEST_SUITE_END()