Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Var::isVoid #18

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading