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

Revive max constraint #519

Merged
merged 72 commits into from
Feb 16, 2022
Merged

Conversation

wu-haoze
Copy link
Collaborator

My attempt to clean up the MaxConstraint class.
Unit tests pretty much remains unchanged except that

  1. we are testing MaxConstraints' behaviors after "transformToUseAuxVariablesIfNeeded()".
  2. there are a few assertions in the original unit test which I think are not correct.

I think in the next few PRs about context dependent object, we should probably just change addAuxilliraryEquations() to transformToUseAuxVariablesIfNeeded() in every constraint class. Because not using aux variables is no longer an option with the context dependent object.

Invariants to maintain in this class (also written in the header file):

  1. All methods called after transformToUseAuxVariablesIfNeeded are operating under the assumption that f >= element for each element in _element, and f >= _maxValueofEliminatedVariables
  2. _maxLowerBound keeps track of the maximal lower bound of the output of the MaxConstraint, it is updated-on-the-fly by notifyLowerBound(), notifyUpperBound(), eliminateVariable()
  3. _phaseStatus is updated on-the-fly by notifyLowerBound(), notifyUpperBound(), eliminateVariable().
  4. elements in _elements are feasible (wrt. current variable bounds) Both _elements and _haveFeasibleEliminatedVariables are updated on-the-fly in notifyLowerBound(), notifyUpperBound(), eliminateVariable().
  5. The constraint is _obsolete only when 1) all elements are eliminated (handled by eliminateVariable()); 2) _f is eliminated.

Please also note that the case where the output variable is part of the input f = max (f, x1, x2...) is handled by transformtoUseAuxVariablesIfNeeded(). The method will add the constraint f >= x1, f>=x2 and make the constraint obsolete.

Copy link
Collaborator

@guykatzz guykatzz left a comment

Choose a reason for hiding this comment

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

I left a bunch of comments - most are cosmetic, but some are real.
One question that I had that didn't make it into the comments:

in MaxConstraint::getPhaseStatusInAssignment, if f currently has an assignment greater than all the elements, we return phase = ELIMINATED, even if there are no eliminated variables. Is this intended? If it is, maybe add a comment.

src/engine/Engine.cpp Outdated Show resolved Hide resolved
src/engine/Engine.cpp Show resolved Hide resolved
src/engine/MaxConstraint.cpp Outdated Show resolved Hide resolved
src/engine/MaxConstraint.cpp Outdated Show resolved Hide resolved
src/engine/MaxConstraint.cpp Outdated Show resolved Hide resolved
auto byAssignment = [&](const unsigned& a, const unsigned& b) {
return _assignment[a] < _assignment[b];
};
double maxValue = _assignment.get( *std::max_element( _elements.begin(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

if f has the maximal assignment, won't just grab f's value as "maxValue"? I think you want to exclude f's value from the computation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this line is getting the element with the maximal assignment?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still not convinced. std::max_element doesn't distinguish between max's f and its elements, no?
I think if you have f=max(x1,x2), and currently f=7, x1=x2=1, you would get maxValue = 7.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I still think the code is correct, since "_elements" contains only input variables to Max and does not include _f. But I do think the code is more confusing than it needs to be. I got rid of the std::max_element business.

src/engine/MaxConstraint.h Show resolved Hide resolved
src/engine/MaxConstraint.cpp Show resolved Hide resolved
src/engine/MaxConstraint.cpp Outdated Show resolved Hide resolved
src/engine/MaxConstraint.cpp Show resolved Hide resolved
wu-haoze and others added 25 commits February 15, 2022 16:32
…Verification#514)

* minor

* minor

* Update AbsoluteValueConstraint.cpp

* Update SignConstraint.cpp

* make all disjuncts bounds

* minor

* add transform constraint method to PLConstraint.h

* split equality into two inequality

* override

* Update DisjunctionConstraint.cpp

* progress

* soi for dijsunction

* change function name. Add clarification to unit tests

* expand on comment

* minor

* minor

* Update DisjunctionConstraint.cpp

* progress

* soi for dijsunction

* Update AbsoluteValueConstraint.cpp

* Update SignConstraint.cpp

* minor

* minor

* minor

* make all disjuncts bounds

* add transform constraint method to PLConstraint.h

* split equality into two inequality

* minor

* fix test

* support disjunction

* Update GlobalConfiguration.cpp

* serailize disjunction (NeuralNetworkVerification#517)

Co-authored-by: anwu <anwu@davidson.edu>

* Upgrade OpenBLAS version. (NeuralNetworkVerification#516)

* Update download_openBLAS.sh

* Update OptionParser.cpp

* Update Options.h

* Update Options.cpp

* Update main.cpp

* Update main.cpp

* Update main.cpp

* Update Marabou.py

* Update MarabouCore.cpp

* Update CMakeLists.txt

* Update MarabouCore.cpp

* serailize disjunction (NeuralNetworkVerification#517)

Co-authored-by: anwu <anwu@davidson.edu>

* Upgrade OpenBLAS version. (NeuralNetworkVerification#516)

* Update download_openBLAS.sh

* Update OptionParser.cpp

* Update Options.h

* Update Options.cpp

* Update main.cpp

* Update main.cpp

* Update main.cpp

* Update Marabou.py

* Update MarabouCore.cpp

* Update CMakeLists.txt

* Update MarabouCore.cpp

* make all disjuncts bounds

* add transform constraint method to PLConstraint.h

* change function name. Add clarification to unit tests

* expand on comment

* progress

* minor

* minor

* minor

* add support soi function, revert unintental changes, make isZero() in LinearExpression const

* mock constraint

* remove left over

* try to fix disjunction

* add additional logic to handle corner case

* make all disjuncts bounds

* add transform constraint method to PLConstraint.h

* change function name. Add clarification to unit tests

* minor

* minor

* Update DisjunctionConstraint.cpp

* progress

* soi for dijsunction

* Update AbsoluteValueConstraint.cpp

* Update SignConstraint.cpp

* minor

* minor

* progress

* soi for dijsunction

* minor

* make all disjuncts bounds

* add transform constraint method to PLConstraint.h

* split equality into two inequality

* minor

* fix test

* support disjunction

* Update GlobalConfiguration.cpp

* make all disjuncts bounds

* add transform constraint method to PLConstraint.h

* change function name. Add clarification to unit tests

* expand on comment

* progress

* minor

* minor

* add support soi function, revert unintental changes, make isZero() in LinearExpression const

* mock constraint

* remove left over

* try to fix disjunction

* add additional logic to handle corner case

* revert change

* revert

* handle corner case

* virtual override

* override issue

* Update Test_Disjunction.h

* Update Test_Disjunction.h

* minor

Co-authored-by: anwu <anwu@davidson.edu>
Copy link
Collaborator

@AleksandarZeljic AleksandarZeljic left a comment

Choose a reason for hiding this comment

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

LGTM.

@wu-haoze wu-haoze merged commit 8b1b29f into NeuralNetworkVerification:master Feb 16, 2022
@wu-haoze wu-haoze deleted the revive-max branch February 16, 2022 04:47
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.

Unit test failure for refactored MaxConstraint MaxConstraint's eliminate variable
3 participants