Skip to content

Commit

Permalink
Merge pull request #18 from scipopt/var-isvoid
Browse files Browse the repository at this point in the history
Add Var::isVoid
  • Loading branch information
hedtke authored Nov 8, 2023
2 parents e845dd8 + fe8053a commit 004fac8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/scippp/var.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

}
5 changes: 5 additions & 0 deletions source/var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ bool Var::isZero(const Solution& solution) const
return SCIPisZero(solution.scip, getSolVal(solution));
}

bool Var::isVoid() const
{
return var == nullptr;
}

}
12 changes: 12 additions & 0 deletions test/test_var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 004fac8

Please sign in to comment.