[jboss-svn-commits] JBL Code SVN: r30883 - in labs/jbossrules/trunk/drools-planner: drools-planner-core/src/main/java/org/drools/planner/core/localsearch/decider and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jan 3 08:09:25 EST 2010
Author: ge0ffrey
Date: 2010-01-03 08:09:25 -0500 (Sun, 03 Jan 2010)
New Revision: 30883
Modified:
labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/LocalSearchSolverConfig.java
labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/core/localsearch/decider/DefaultDecider.java
labs/jbossrules/trunk/drools-planner/src/main/assembly/docs/UpgradeFromPreviousVersionRecipe.txt
Log:
JBRULES-2391 debug mode
Modified: labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/LocalSearchSolverConfig.java
===================================================================
--- labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/LocalSearchSolverConfig.java 2010-01-03 11:06:49 UTC (rev 30882)
+++ labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/LocalSearchSolverConfig.java 2010-01-03 13:09:25 UTC (rev 30883)
@@ -24,6 +24,7 @@
import org.drools.planner.core.localsearch.bestsolution.BestSolutionRecaller;
import org.drools.planner.core.localsearch.decider.Decider;
import org.drools.planner.core.localsearch.decider.DefaultDecider;
+import org.drools.planner.core.move.Move;
import org.drools.planner.core.solution.initializer.StartingSolutionInitializer;
import org.drools.planner.core.score.definition.ScoreDefinition;
@@ -33,8 +34,12 @@
@XStreamAlias("localSearchSolver")
public class LocalSearchSolverConfig {
- private Long randomSeed = null;
+ // Warning: all fields are null (and not defaulted) because they can be inherited
+ // and also because the input config file should match the output config file
+ private Long randomSeed = null; // TODO remove me, use environmentMode instead
+ private EnvironmentMode environmentMode = null;
+
@XStreamImplicit(itemFieldName = "scoreDrl")
private List<String> scoreDrlList = null;
@XStreamAlias("scoreDefinition")
@@ -44,7 +49,9 @@
private Class<StartingSolutionInitializer> startingSolutionInitializerClass = null;
@XStreamAlias("termination")
- private TerminationConfig terminationConfig = new TerminationConfig(); // TODO this new is pointless due to xstream
+ // TODO this new TerminationConfig is pointless due to xstream
+ // TODO but maybe we should be able to use the config API directly too
+ private TerminationConfig terminationConfig = new TerminationConfig();
@XStreamAlias("deciderScoreComparatorFactory")
private DeciderScoreComparatorFactoryConfig deciderScoreComparatorFactoryConfig
@@ -68,6 +75,14 @@
return scoreDrlList;
}
+ public EnvironmentMode getEnvironmentMode() {
+ return environmentMode;
+ }
+
+ public void setEnvironmentMode(EnvironmentMode environmentMode) {
+ this.environmentMode = environmentMode;
+ }
+
public void setScoreDrlList(List<String> scoreDrlList) {
this.scoreDrlList = scoreDrlList;
}
@@ -209,6 +224,9 @@
private Decider buildDecider() {
DefaultDecider decider = new DefaultDecider();
+ if (environmentMode == EnvironmentMode.DEBUG) {
+ decider.setAssertUndoMoveIsUncorrupted(true);
+ }
decider.setDeciderScoreComparator(deciderScoreComparatorFactoryConfig.buildDeciderScoreComparatorFactory());
decider.setSelector(selectorConfig.buildSelector());
decider.setAcceptor(acceptorConfig.buildAcceptor());
@@ -220,6 +238,9 @@
if (randomSeed == null) {
randomSeed = inheritedConfig.getRandomSeed();
}
+ if (environmentMode == null) {
+ environmentMode = inheritedConfig.getEnvironmentMode();
+ }
if (scoreDrlList == null) {
scoreDrlList = inheritedConfig.getScoreDrlList();
} else {
@@ -268,4 +289,41 @@
}
}
+ /**
+ * The environment mode is Debug, reproducible (the default) or production.
+ */
+ public enum EnvironmentMode {
+ /**
+ * The debug mode is reproducible (see the reproducible mode)
+ * and also turns on assertions (such as {@link DefaultDecider#assertUndoMoveIsUncorrupted})
+ * to fail-fast on a bug in a {@link Move} implementation, a score rule, ...
+ * <p>
+ * The debug mode is slow.
+ */
+ DEBUG,
+ /**
+ * The reproducible mode is the default mode because it is recommended during development.
+ * In this mode, 2 runs on the same computer will execute the same code in the same order.
+ * They will also yield the same result, except if they use a time based termination
+ * and they have a sufficiently large difference in allocated CPU time.
+ * <p>
+ * The reproducible mode is not much slower than the production mode.
+ * </p>
+ * In practice, this mode uses the default random seed,
+ * and it also disables certain concurrency optimizations (such as work stealing).
+ * TODO: JBRULES-681 Multi-threaded support which implement those concurrency optimizations
+ */
+ REPRODUCIBLE,
+ /**
+ * The production mode is the fastest and the most robust, but not reproducible.
+ * It is recommended for a production environment.
+ * <p>
+ * The random seed is different on every run, which makes it more robust against an unlucky random seed.
+ * An unlucky random seed gives a bad result on a certain data set with a certain solver configuration.
+ * Note that in most use cases the impact of the random seed is relatively low on the result.
+ * An occasional bad result is far more likely caused by another issue (such as a score trap).
+ */
+ PRODUCTION
+ }
+
}
Modified: labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/core/localsearch/decider/DefaultDecider.java
===================================================================
--- labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/core/localsearch/decider/DefaultDecider.java 2010-01-03 11:06:49 UTC (rev 30882)
+++ labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/core/localsearch/decider/DefaultDecider.java 2010-01-03 13:09:25 UTC (rev 30883)
@@ -30,7 +30,7 @@
protected Acceptor acceptor;
protected Forager forager;
- protected boolean verifyUndoMoveIsUncorrupted = false;
+ protected boolean assertUndoMoveIsUncorrupted = false;
public void setLocalSearchSolver(LocalSearchSolver localSearchSolver) {
this.localSearchSolver = localSearchSolver;
@@ -61,8 +61,8 @@
this.forager = forager;
}
- public void setVerifyUndoMoveIsUncorrupted(boolean verifyUndoMoveIsUncorrupted) {
- this.verifyUndoMoveIsUncorrupted = verifyUndoMoveIsUncorrupted;
+ public void setAssertUndoMoveIsUncorrupted(boolean assertUndoMoveIsUncorrupted) {
+ this.assertUndoMoveIsUncorrupted = assertUndoMoveIsUncorrupted;
}
// ************************************************************************
@@ -117,7 +117,7 @@
move.doMove(workingMemory);
processMove(moveScope);
undoMove.doMove(workingMemory);
- if (verifyUndoMoveIsUncorrupted) {
+ if (assertUndoMoveIsUncorrupted) {
Score undoScore = moveScope.getStepScope().getLocalSearchSolverScope().calculateScoreFromWorkingMemory();
if (!undoScore.equals(moveScope.getStepScope().getLocalSearchSolverScope()
.getLastCompletedStepScope().getScore())) {
Modified: labs/jbossrules/trunk/drools-planner/src/main/assembly/docs/UpgradeFromPreviousVersionRecipe.txt
===================================================================
--- labs/jbossrules/trunk/drools-planner/src/main/assembly/docs/UpgradeFromPreviousVersionRecipe.txt 2010-01-03 11:06:49 UTC (rev 30882)
+++ labs/jbossrules/trunk/drools-planner/src/main/assembly/docs/UpgradeFromPreviousVersionRecipe.txt 2010-01-03 13:09:25 UTC (rev 30883)
@@ -13,7 +13,7 @@
-------------------
A score is no longer a double, now it's a Score instance,
-because a SimpleScore is now just an int and a HardAndSoftScore is now 2 seperated ints.
+because a SimpleScore is now just an int and a HardAndSoftScore is now 2 separated ints.
In the Solver interface, the return type of the getBestScore() method changed:
@@ -238,3 +238,18 @@
<acceptor>
...
</acceptor>
+
+
+The method DefaultDecider.setAssertUndoMoveIsUncorrupted() has been renamed.
+Use the EnvironmentMode debug instead.
+Before in *.java:
+ (DefaultDecider ((DefaultLocalSearchSolver) solver).getDecider()).setVerifyUndoMoveIsUncorrupted(true);
+Before in *.xml:
+ <localSearchSolver>
+ ...
+ </localSearchSolver>
+After in *.xml:
+ <localSearchSolver>
+ <environmentMode>DEBUG</environmentMode>
+ ...
+ </localSearchSolver>
More information about the jboss-svn-commits
mailing list