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

Add getBestMove and FirstBestAdmissibleTabuSearch #39

Merged
merged 9 commits into from
Jun 14, 2017

Conversation

huanfachen
Copy link
Contributor

Add a new getBestMove to NeighbourhoodSearch() with a parameter boolean acceptFirstImprovement.
Add FirstBestAdmissibleTabuSearch.java

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.08%) to 95.095% when pulling 1c9e3b8 on huanfachen:tabuSearch/add_variant into f6bfd50 on hdbeukel:master.

@hdbeukel hdbeukel changed the base branch from master to tabuvariant May 31, 2017 11:56
@coveralls
Copy link

Coverage Status

Coverage decreased (-2.1%) to 95.095% when pulling e06489b on huanfachen:tabuSearch/add_variant into f6bfd50 on hdbeukel:tabuvariant.

Copy link
Owner

@hdbeukel hdbeukel left a comment

Choose a reason for hiding this comment

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

I have added some comments. Can you have a look? Please also add tests to get the coverage back up.

// track first improvement move AND best valid move + corresponding evaluation, validation and delta
Move<? super SolutionType> bestMove = null, firstImprovementMove = null;
double bestMoveDelta = -Double.MAX_VALUE, curMoveDelta, firstImprovementMoveDelta = -Double.MAX_VALUE;
Evaluation curMoveEvaluation, bestMoveEvaluation = null, firstImprovementMoveEvaluation = null;
Copy link
Owner

Choose a reason for hiding this comment

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

You don't need separate variables for first and best improvement. One variable, say chosenMove, is sufficient to store the move you selected (either first improvement, or best). Then you also have chosenMoveDelta, chosenMoveEvaluation, and chosenMoveValidation.

@SafeVarargs
protected final Move<? super SolutionType> getBestMove(List<? extends Move<? super SolutionType>> moves,
boolean requireImprovement,
boolean acceptFirstImprovement,
Copy link
Owner

Choose a reason for hiding this comment

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

Parameter acceptFirstImprovement is never used. You implementation returns the first improvement, even if acceptFirstImprovement is false. See comments below to fix.

Evaluation curMoveEvaluation, bestMoveEvaluation = null, firstImprovementMoveEvaluation = null;
Validation curMoveValidation, bestMoveValidation = null, firstImprovementMoveValidation = null;
// go through all moves
for (Move<? super SolutionType> move : moves) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please use an Iterator here in a while loop with multiple conditions to avoid the use of break. You should continue as long as there are more moves to try and !(acceptFirstImprovement && chosenMoveDelta > 0).

* @return first improving move or the best valid move, may be <code>null</code>
*/
@SafeVarargs
protected final Move<? super SolutionType> getBestMove(Collection<? extends Move<? super SolutionType>> moves,
Copy link
Owner

Choose a reason for hiding this comment

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

Once this method's implementation is finished, the other getBestMove method should relay to this one with acceptFirstImprovement set to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with the suggestion. Before adding tests, I found a problem in Line 445 of GenericProblem.java, which prevents the running of NeighbourhoodSearchTest. Could you have a look at it?

Copy link
Owner

Choose a reason for hiding this comment

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

It's not a problem with JAMES but with Eclipse. See #41 and #31.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Problem solved by switching to IntelliJ IDEA

@SafeVarargs
protected final Move<? super SolutionType> getBestMove(Collection<? extends Move<? super SolutionType>> moves,
boolean requireImprovement,
boolean acceptFirstImprovement,
Copy link
Owner

Choose a reason for hiding this comment

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

the parameter acceptFirstImprovement is never checked.

// track first improvement move AND best valid move + corresponding evaluation, validation and delta
Move<? super SolutionType> bestMove = null, firstImprovementMove = null;
double bestMoveDelta = -Double.MAX_VALUE, curMoveDelta, firstImprovementMoveDelta = -Double.MAX_VALUE;
Evaluation curMoveEvaluation, bestMoveEvaluation = null, firstImprovementMoveEvaluation = null;
Copy link
Owner

Choose a reason for hiding this comment

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

No need to store first and best move (and their metadata separately). You can have one series of variables for the chosen move, say chosenMove, chosenMoveDelta, etc. which will either be the first or best one depending on the parameter acceptFirstImprovement.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 96.555% when pulling a25b183 on huanfachen:tabuSearch/add_variant into f6bfd50 on hdbeukel:tabuvariant.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 96.555% when pulling df1fe55 on huanfachen:tabuSearch/add_variant into f6bfd50 on hdbeukel:tabuvariant.

Copy link
Owner

@hdbeukel hdbeukel left a comment

Choose a reason for hiding this comment

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

Nice work. I added some more suggestions.

@@ -7,6 +7,7 @@
<groupId>org.jamesframework</groupId>
<artifactId>james</artifactId>
<version>1.3-SNAPSHOT</version>
<relativePath>../james/james</relativePath>
Copy link
Owner

Choose a reason for hiding this comment

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

Why has this line been added? Should not be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is added to make the codes work on my computer, as I cloned James and James-core separately. I have added pom.xml to .gitignore. Please revise the pom.xml file accordingly.

Copy link
Owner

Choose a reason for hiding this comment

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

I see. I will remove this line when merging the pull request.

* @param <SolutionType> solution type of the problems that may be solved using this search, required to extend {@link Solution}
* @author <a href="mailto:chenhuanfa@gmail.com">Huanfa Chen</a>
*/
public class FirstBestAdmissibleTabuSearch<SolutionType extends Solution> extends TabuSearch<SolutionType>{
Copy link
Owner

Choose a reason for hiding this comment

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

Please also test this new Tabu search.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test added in the new pull request.

Copy link
Owner

Choose a reason for hiding this comment

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

Please don't create a new pull request for each commit. Just keep committing to the same branch, all changes will show up here. I closed the other pull request #43.

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 am not very familiar with Github. Say, I add and commit the changes, and push them to the remote repo. Will it be automatically committed to the same branch?

Copy link
Owner

@hdbeukel hdbeukel Jun 2, 2017

Choose a reason for hiding this comment

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

If you don't specify an explicit branch when pushing, git will push to the remote branch that has been associated with your local branch. So yes, these commits will end up in the same branch each time. In your case tabuSearch/add_variant.

Are you using git on command line or a desktop client?

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 am using git bash on Windows. Just add a new push.



@Test
public void testGetBestMoveAcceptFirstImprovement() throws Exception {
Copy link
Owner

Choose a reason for hiding this comment

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

Please move test method down (alongside other test methods instead of in between the setup code).

assertTrue(bestMove != null);
assertTrue(bestMoveFirstImprovement != null);
assertTrue(bestMove == bestMoveFirstImprovement);
assertTrue(neighSearch.evaluate(bestMove).getValue() == neighSearch.evaluate(bestMoveFirstImprovement).getValue());
Copy link
Owner

Choose a reason for hiding this comment

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

Please avoid comparing double values with ==. Either use assertEquals(double expected, double actual, double delta) or just remove this line because it can never fail if the previous line succeeds.

bestMoveFirstImprovement = neighSearch.getBestMove(moves, true,true);
}

// when curSolution is best, bestMove and bestMoveFirstImprovement should be the (nearly) the same
Copy link
Owner

@hdbeukel hdbeukel Jun 1, 2017

Choose a reason for hiding this comment

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

Nice test case! Why nearly the same? They should be exactly the same no? (which is what you test)

Could you perhaps think of a way to also explicitly test the other case, i.e. when the first and best improvement are not the same?

@hdbeukel
Copy link
Owner

hdbeukel commented Jun 1, 2017

Please remove the following files and folders (IntelliJ/Eclipse settings) and include them in .gitignore to avoid that they are added in the future:

  • .classpath
  • .project
  • .settings
  • james-core.iml (add *.iml to .gitignore)
  • .idea

Also see my other comments.

@hdbeukel
Copy link
Owner

hdbeukel commented Jun 2, 2017

You have several compiler warnings in your code. See https://travis-ci.org/hdbeukel/james-core/builds/238702467?utm_source=github_status&utm_medium=notification. Please fix.

@hdbeukel
Copy link
Owner

hdbeukel commented Jun 2, 2017

The undesired files listed above are also still present.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 97.146% when pulling 5d564cb on huanfachen:tabuSearch/add_variant into f6bfd50 on hdbeukel:tabuvariant.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 97.096% when pulling 9eaf5c4 on huanfachen:tabuSearch/add_variant into f6bfd50 on hdbeukel:tabuvariant.

@hdbeukel
Copy link
Owner

hdbeukel commented Jun 2, 2017

Tests fail now because you have deleted the file pom.xml (alongside the undesired files).

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 97.146% when pulling 37e899e on huanfachen:tabuSearch/add_variant into f6bfd50 on hdbeukel:tabuvariant.

@hdbeukel
Copy link
Owner

hdbeukel commented Jun 5, 2017

Thanks for the fix. I will get back to this next week and merge your pull request (no time this week).

@hdbeukel
Copy link
Owner

hdbeukel commented Jun 5, 2017

I will probably make some more changes (e.g. Javadocs). If you want you can then pull them back into your fork. I will send you a pull request.

@hdbeukel hdbeukel merged commit e4db65a into hdbeukel:tabuvariant Jun 14, 2017
hdbeukel added a commit that referenced this pull request Jun 14, 2017
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.

None yet

3 participants