diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptance.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptance.java
index 3b55288c..ed76fee3 100644
--- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptance.java
+++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptance.java
@@ -17,21 +17,13 @@
package jsprit.core.algorithm.acceptor;
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
-import jsprit.core.algorithm.io.AlgorithmConfig;
-import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
-import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
-import jsprit.core.algorithm.listener.IterationEndsListener;
import jsprit.core.algorithm.listener.IterationStartsListener;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import jsprit.core.util.Resource;
-import jsprit.core.util.Solutions;
-import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import java.net.URL;
import java.util.Collection;
@@ -81,38 +73,21 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
private final double alpha;
- private int nOfTotalIterations = 1000;
+ private int maxIterations = 1000;
private int currentIteration = 0;
private double initialThreshold = 0.0;
-
- private int nOfRandomWalks;
private final int solutionMemory;
-
- private boolean determineInitialThreshold = true;
+
public SchrimpfAcceptance(int solutionMemory, double alpha){
this.alpha = alpha;
this.solutionMemory = solutionMemory;
- determineInitialThreshold = false;
logger.info("initialise " + this);
}
-
- /**
- * @deprecated use new SchrimpfAcceptance(solutionMemory,alpha) instead. if you want to determine ini-threshold with a
- * random walk and the algorithm 'randomWalk.xml' use SchrimpfInitialThresholdGenerator.class instead.
- */
- @Deprecated
- public SchrimpfAcceptance(int solutionMemory, double alpha, int nOfWarmupIterations) {
- super();
- this.alpha = alpha;
- this.nOfRandomWalks = nOfWarmupIterations;
- this.solutionMemory = solutionMemory;
- logger.info("initialise " + this);
- }
-
+
@Override
public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) {
boolean solutionAccepted = false;
@@ -141,11 +116,11 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
@Override
public String toString() {
- return "[name=SchrimpfAcceptance][alpha="+alpha+"][warmup=" + nOfRandomWalks + "]";
+ return "[name=SchrimpfAcceptance][alpha="+alpha+"]";
}
private double getThreshold(int iteration) {
- double scheduleVariable = (double) iteration / (double) nOfTotalIterations;
+ double scheduleVariable = (double) iteration / (double) maxIterations;
return initialThreshold * Math.exp(-1. * Math.log(2) * scheduleVariable / alpha);
}
@@ -163,53 +138,12 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
*/
public void setInitialThreshold(double initialThreshold) {
this.initialThreshold = initialThreshold;
- determineInitialThreshold=false;
}
@Override
public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) {
- if(!determineInitialThreshold){
- logger.info("skip threshold initialization from here");
- return;
- }
- reset();
- logger.info("---------------------------------------------------------------------");
- logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold");
- logger.info("start random-walk (see randomWalk.xml)");
- double now = System.currentTimeMillis();
- this.nOfTotalIterations = algorithm.getMaxIterations();
-
- /*
- * randomWalk to determine standardDev
- */
- final double[] results = new double[nOfRandomWalks];
-
- URL resource = Resource.getAsURL("randomWalk.xml");
- AlgorithmConfig algorithmConfig = new AlgorithmConfig();
- new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
- vra.setMaxIterations(nOfRandomWalks);
- vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
-
- @Override
- public void informIterationEnds(int iteration, VehicleRoutingProblem problem, Collection solutions) {
- double result = Solutions.bestOf(solutions).getCost();
-// logger.info("result="+result);
- results[iteration-1] = result;
- }
-
- });
- vra.searchSolutions();
-
- StandardDeviation dev = new StandardDeviation();
- double standardDeviation = dev.evaluate(results);
- initialThreshold = standardDeviation / 2;
-
- logger.info("warmup done");
- logger.info("total time: " + ((System.currentTimeMillis()-now)/1000.0) + "s");
- logger.info("initial threshold: " + initialThreshold);
- logger.info("---------------------------------------------------------------------");
-
+ reset();
+ this.maxIterations = algorithm.getMaxIterations();
}
private void reset() {
diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptanceTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptanceTest.java
index becb5cb5..9305d5e0 100644
--- a/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptanceTest.java
+++ b/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptanceTest.java
@@ -1,20 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2014 Stefan Schroeder.
- *
+ * Copyright (C) 2014 Stefan Schroeder
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
+ * License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
- *
- * Contributors:
- * Stefan Schroeder - initial API and implementation
******************************************************************************/
package jsprit.core.algorithm.acceptor;
@@ -44,7 +42,7 @@ public class SchrimpfAcceptanceTest {
@SuppressWarnings("deprecation")
@Before
public void setup() {
- schrimpfAcceptance = new SchrimpfAcceptance(1, 0.3, 100);
+ schrimpfAcceptance = new SchrimpfAcceptance(1, 0.3);
// we skip the warmup, but still want to test that the initialThreshold is set
schrimpfAcceptance.setInitialThreshold(0.0);
// create empty memory with an initial capacity of 1
diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java
index bebea55b..5cf7f7d1 100644
--- a/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java
+++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java
@@ -62,7 +62,8 @@ public class SolomonR101Example {
* The algorithm can be defined and configured in an xml-file.
*/
// VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml");
+ VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml");
+ vra.setMaxIterations(100);
// vra.setPrematureBreak(100);
// vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/*