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
Changes from 2 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
11 changes: 11 additions & 0 deletions src/search/lp/lp_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@
#include <cassert>
#include <iostream>
#include <numeric>
#include <unordered_set>

using namespace std;
using utils::ExitCode;

namespace lp {
#ifndef NDEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you get an "unused function" error without this? If not, I'd reduce the number of preprocessor directives and just always define the function (it shouldn't have a performance impact if it is not used). I have no strong opinion, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I thought that's something we do if something's used only in debug mode. I'll remove it.

template<class T>
static bool all_values_are_unique(const vector<T> &v) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this function next to sorted_unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar enough with our conventions here. Moving it to collections.h would require an import in lp_solver.cc even though the function is only used in debug mode. I tried to avoid any changes in the release build by defining the function close to where it is used and building it only in debug mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You currently also have an additional import here (for unordered_set). I think treat both the algorithm and the utils namespace as something that may be included everywhere. But same as Jendrik, I'm also fine either way. It certainly has an advantage to make the module as independent from other modules as possible and we could always make the function more public later on if we need it somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I overlooked that because I first used set which didn't need the extra import. ;)

The disadvantage of defining it locally is that somebody else might define something similar locally unaware of this function here. So I'll just move it to utils until somebody has a stronger opinion in a different direction.

unordered_set<T> s(v.begin(), v.end());
return s.size() == v.size();
}
#endif

void add_lp_solver_option_to_feature(plugins::Feature &feature) {
feature.add_option<LPSolverType>(
"lpsolver",
Expand Down Expand Up @@ -185,6 +194,7 @@ void LPSolver::load_problem(const LinearProgram &lp) {

for (const LPConstraint &constraint : lp.get_constraints()) {
const vector<int> &vars = constraint.get_variables();
assert(all_values_are_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 +282,7 @@ void LPSolver::add_temporary_constraints(const vector<LPConstraint> &constraints
clear_temporary_data();
int num_rows = constraints.size();
for (const LPConstraint &constraint : constraints) {
assert(all_values_are_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