Skip to content

Commit

Permalink
Add function to check whether a constraint has been added to a solver
Browse files Browse the repository at this point in the history
  • Loading branch information
arximboldi committed Jan 6, 2015
1 parent 1cb41a0 commit 0efd658
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rhea/simplex_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class simplex_solver : public solver, public tableau
return columns_has_key(v) || is_basic_var(v);
}

/** Check if the solver knows of a given constraint.
* \param c The constraint to check for
* \return True iff c has been added to the solver */
bool contains_constraint(const constraint& c)
{
return marker_vars_.find(c) != marker_vars_.end();
}

/** Check if this constraint was satisfied. */
bool is_constraint_satisfied(const constraint& c) const;

Expand Down
14 changes: 14 additions & 0 deletions unit_tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,3 +912,17 @@ BOOST_AUTO_TEST_CASE(add_constraints_after_marking_edit_variable)
BOOST_CHECK_EQUAL(v.value(), 3);
BOOST_CHECK(solver.is_valid());
}

BOOST_AUTO_TEST_CASE(contains_constraint)
{
auto c = constraint{ variable{} == 42 };
auto solver = simplex_solver{};

BOOST_CHECK(!solver.contains_constraint(c));

solver.add_constraint(c);
BOOST_CHECK(solver.contains_constraint(c));

solver.remove_constraint(c);
BOOST_CHECK(!solver.contains_constraint(c));
}

0 comments on commit 0efd658

Please sign in to comment.