[jboss-svn-commits] JBL Code SVN: r36111 - labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 29 09:49:15 EST 2010


Author: ge0ffrey
Date: 2010-11-29 09:49:13 -0500 (Mon, 29 Nov 2010)
New Revision: 36111

Added:
   labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/EnvironmentMode.java
Modified:
   labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/LocalSearchSolverConfig.java
Log:
JBRULES-2809 environmentmode trace to detect the corruption early

Added: labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/EnvironmentMode.java
===================================================================
--- labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/EnvironmentMode.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/EnvironmentMode.java	2010-11-29 14:49:13 UTC (rev 36111)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.planner.config.localsearch;
+
+import org.drools.planner.core.localsearch.decider.DefaultDecider;
+import org.drools.planner.core.move.Move;
+
+/**
+ * A solver has a single Random instance. Some solver configurations use the Random instance a lot more than others.
+ * For example simulated annealing depends highly on random numbers,
+ * while tabu search only depends on it to deal with score ties.
+ * The environment mode influences the seed of that Random instance.
+ * <p/>
+ * The environment mode also allows you to detect common bugs in your implementation.
+ */
+public enum EnvironmentMode {
+    /**
+     * The trace mode does a few more assertions (such as {@link DefaultDecider#assertMoveScoreIsUncorrupted})
+     * than the {@link #DEBUG} mode at a horrible performance cost.
+     * <p>
+     * The trace mode is reproducible (see {@link #REPRODUCIBLE} mode).
+     * <p>
+     * The trace mode is horribly slow.
+     */
+    TRACE,
+    /**
+     * The debug mode turns on most assertions (such as {@link DefaultDecider#assertUndoMoveIsUncorrupted})
+     * to fail-fast on a bug in a {@link Move} implementation, in a score rule or something else.
+     * <p>
+     * The debug mode is reproducible (see {@link #REPRODUCIBLE} mode).
+     * <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.
+     * This allows you to benchmark new optimizations (such as a new Move implementation) fairly.
+     * <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 to be 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/config/localsearch/LocalSearchSolverConfig.java
===================================================================
--- labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/LocalSearchSolverConfig.java	2010-11-29 14:44:27 UTC (rev 36110)
+++ labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/config/localsearch/LocalSearchSolverConfig.java	2010-11-29 14:49:13 UTC (rev 36111)
@@ -40,7 +40,6 @@
 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;
 
@@ -192,7 +191,7 @@
         localSearchSolver.setBestSolutionRecaller(new BestSolutionRecaller());
         localSearchSolver.setTermination(terminationConfig.buildTermination(scoreDefinition));
         localSearchSolver.setDecider(buildDecider());
-        if (environmentMode == EnvironmentMode.DEBUG) {
+        if (environmentMode == EnvironmentMode.DEBUG || environmentMode == EnvironmentMode.TRACE) {
             localSearchSolver.setAssertStepScoreIsUncorrupted(true);
         }
         return localSearchSolver;
@@ -251,7 +250,10 @@
         decider.setSelector(selectorConfig.buildSelector());
         decider.setAcceptor(acceptorConfig.buildAcceptor());
         decider.setForager(foragerConfig.buildForager());
-        if (environmentMode == EnvironmentMode.DEBUG) {
+        if ( environmentMode == EnvironmentMode.TRACE) {
+            decider.setAssertMoveScoreIsUncorrupted(true);
+        }
+        if (environmentMode == EnvironmentMode.DEBUG || environmentMode == EnvironmentMode.TRACE) {
             decider.setAssertUndoMoveIsUncorrupted(true);
         }
         return decider;
@@ -312,47 +314,4 @@
         }
     }
 
-    /**
-     * A solver has a single Random instance. Some solver configurations use the Random instance a lot more than others.
-     * For example simulated annealing depends highly on random numbers,
-     * while tabu search only depends on it to deal with score ties.
-     * The environment mode influences the seed of that Random instance.
-     * <p/>
-     * The environment mode also allows you to detect common bugs in your implementation.
-     */
-    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.
-         * This allows you to benchmark new optimizations (such as a new move implementation) fairly.
-         * <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
-    }
-
 }



More information about the jboss-svn-commits mailing list