Skip to content

Commit 964f6e5

Browse files
Implement match function to compare linear expressions for equality based on current constraints.
1 parent 1c3160d commit 964f6e5

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

include/linspire.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ namespace linspire
188188
*/
189189
[[nodiscard]] const std::vector<std::shared_ptr<const constraint>> &get_conflict() const noexcept { return cnfl; }
190190

191+
/**
192+
* @brief Checks if two linear expressions can be made equal.
193+
*
194+
* This function determines whether two linear expressions `l0` and `l1` can take on equal values
195+
* based on the current constraints in the solver.
196+
*
197+
* @param l0 The first linear expression to compare.
198+
* @param l1 The second linear expression to compare.
199+
* @return true if the linear expressions can be equal; false otherwise.
200+
*/
201+
[[nodiscard]] bool match(const utils::lin &l0, const utils::lin &l1) const noexcept;
202+
191203
#ifdef LINSPIRE_ENABLE_LISTENERS
192204
/**
193205
* @brief Adds a listener to the solver.

src/linspire.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ namespace linspire
185185
}
186186
}
187187

188+
bool solver::match(const utils::lin &l0, const utils::lin &l1) const noexcept { return lb(l0) <= ub(l1) && ub(l0) >= lb(l1); }
189+
188190
bool solver::set_lb(const utils::var x, const utils::inf_rational &v, std::shared_ptr<constraint> reason) noexcept
189191
{
190192
assert(x < vars.size());

0 commit comments

Comments
 (0)