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

issue1088 #156

merged 7 commits into from
Jul 6, 2023

Conversation

ClemensBuechner
Copy link
Contributor

Assert that LP constraints contain every variable at most once.

#ifndef NDEBUG
template<class T>
static bool all_values_are_unique(const vector<T> &v) {
set<T> s(v.begin(), v.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
set<T> s(v.begin(), v.end());
unordered_set<T> s(v.begin(), v.end());

since we don't require a sorted container.

@@ -37,6 +37,14 @@ using namespace std;
using utils::ExitCode;

namespace lp {
#ifndef NDEBUG
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.


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.

@ClemensBuechner ClemensBuechner merged commit 9831694 into aibasel:main Jul 6, 2023
12 checks passed
@ClemensBuechner ClemensBuechner deleted the issue1088 branch July 6, 2023 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants