-
Notifications
You must be signed in to change notification settings - Fork 146
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
Make propagation stops sooner if time limit is met (fix issue #1062) #1064
Open
ArthurGodet
wants to merge
2
commits into
master
Choose a base branch
from
improvedTimeLimit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,15 @@ | |
*/ | ||
package org.chocosolver.solver; | ||
|
||
import org.chocosolver.solver.exception.SolverException; | ||
import org.chocosolver.solver.variables.IntVar; | ||
import org.chocosolver.util.tools.TimeUtils; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.chocosolver.util.ProblemMaker.makeNQueenWithBinaryConstraints; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
/** | ||
|
@@ -35,6 +38,35 @@ public void testTime() { | |
assertTrue(tl - (tl * 5 / 100) <= tc && tc <= tl + (tl * 5 / 100), tl + " vs. " + tc); | ||
} | ||
|
||
@Test(groups="1s", timeOut=60000) | ||
public void testTime2() throws SolverException { | ||
Model model = new Model(); | ||
|
||
IntVar v7 = model.intVar("@v7", IntVar.MIN_INT_BOUND, IntVar.MAX_INT_BOUND, true); | ||
|
||
model.post( | ||
model.arithm(v7, ">", v7), | ||
model.arithm(v7, "<", v7) | ||
); | ||
// TODO : such a simple case should be detected within the constraint declaration | ||
// TODO : this test might need to be changed if better model analysis is done during model declaration | ||
|
||
Solver solver = model.getSolver(); | ||
solver.limitTime(250); | ||
|
||
long start = System.currentTimeMillis(); | ||
boolean solved = solver.solve(); | ||
long took = System.currentTimeMillis() - start; | ||
|
||
assertFalse(solved); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to check that solve() returns false; |
||
assertEquals(solver.getNodeCount(), 1); | ||
assertEquals(solver.getBackTrackCount(), 0); | ||
assertEquals(solver.getFailCount(), 0); | ||
assertEquals(solver.getSolutionCount(), 0); | ||
assertTrue(solver.isStopCriterionMet()); | ||
assertTrue(took <= 1000); // less than 1 second | ||
} | ||
|
||
@Test(groups="1s", timeOut=60000) | ||
public void testNode() { | ||
Model s = makeNQueenWithBinaryConstraints(12); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not calling model.getSolver().isStopCriterionMet() ?
This would avoid modifying the Solver class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to have a simple check on the time limit, and not check all the stopping criterion before the propagation of each propagator.
Indeed, all stopping criterion but the time limit do not depend on the problem's state outside of fixpoint. Unless you can think of one that would.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personnaly, I would have move the code to the end of the while-loop just to keep the main purpose (ie, propagating) clear