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

issue1088 #156

Merged
merged 7 commits into from
Jul 6, 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
3 changes: 3 additions & 0 deletions src/search/lp/lp_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "lp_internals.h"

#include "../plugins/plugin.h"
#include "../utils/collections.h"
#include "../utils/logging.h"
#include "../utils/system.h"

Expand Down Expand Up @@ -185,6 +186,7 @@ void LPSolver::load_problem(const LinearProgram &lp) {

for (const LPConstraint &constraint : lp.get_constraints()) {
const vector<int> &vars = constraint.get_variables();
assert(utils::all_values_unique(vars));
const vector<double> &coeffs = constraint.get_coefficients();
assert(vars.size() == coeffs.size());
starts.push_back(elements.size());
Expand Down Expand Up @@ -272,6 +274,7 @@ void LPSolver::add_temporary_constraints(const vector<LPConstraint> &constraints
clear_temporary_data();
int num_rows = constraints.size();
for (const LPConstraint &constraint : constraints) {
assert(utils::all_values_unique(constraint.get_variables()));
row_lb.push_back(constraint.get_lower_bound());
row_ub.push_back(constraint.get_upper_bound());
rows.push_back(new CoinShallowPackedVector(
Expand Down
6 changes: 6 additions & 0 deletions src/search/utils/collections.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ extern bool is_sorted_unique(const std::vector<T> &values) {
return true;
}

template<class T>
extern bool all_values_unique(const std::vector<T> &v) {
std::unordered_set<T> s(v.begin(), v.end());
return s.size() == v.size();
}

template<class T>
bool in_bounds(int index, const T &container) {
return index >= 0 && static_cast<size_t>(index) < container.size();
Expand Down