From 55ffe3970f39ab66fc4b653398c7397f16f84e4f Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Thu, 28 Aug 2014 05:55:54 +0200
Subject: [PATCH] add javadoc to acceptors
---
.../acceptor/AcceptNewRemoveFirst.java | 18 +++----
.../algorithm/acceptor/GreedyAcceptance.java | 19 +++++---
.../GreedyAcceptance_minVehFirst.java | 14 +++---
.../acceptor/SchrimpfAcceptance.java | 48 +++++++++----------
.../SchrimpfInitialThresholdGenerator.java | 20 ++++----
5 files changed, 62 insertions(+), 57 deletions(-)
diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveFirst.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveFirst.java
index 8da92a94..c14762e3 100644
--- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveFirst.java
+++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveFirst.java
@@ -1,27 +1,29 @@
/*******************************************************************************
- * Copyright (C) 2013 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
* License along with this library. If not, see
If there is enough memory, every solution will be accepted. If there is no memory anymore and the solution + * to be evaluated is better than the worst, the worst will be replaced by the new solution.
+ */ public class GreedyAcceptance implements SolutionAcceptor{ private final int solutionMemory; @@ -59,7 +64,7 @@ public class GreedyAcceptance implements SolutionAcceptor{ @Override public String toString() { - return "[name=acceptNewRemoveWorst]"; + return "[name=GreedyAcceptance]"; } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance_minVehFirst.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance_minVehFirst.java index ae5b0976..0fda452b 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance_minVehFirst.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance_minVehFirst.java @@ -1,27 +1,27 @@ /******************************************************************************* - * Copyright (C) 2013 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 * License along with this library. If not, seenew SchrimpfAcceptance(solutionMemory,alpha) instead. if you want to determine ini-threshold with a
+ * @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
@@ -130,7 +126,11 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
if(worst == null) worst = solutionInMemory;
else if(solutionInMemory.getCost() > worst.getCost()) worst = solutionInMemory;
}
- if(newSolution.getCost() < worst.getCost() + threshold){
+ if(worst == null){
+ solutions.add(newSolution);
+ solutionAccepted = true;
+ }
+ else if(newSolution.getCost() < worst.getCost() + threshold){
solutions.remove(worst);
solutions.add(newSolution);
solutionAccepted = true;
@@ -141,17 +141,17 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
@Override
public String toString() {
- return "[name=schrimpfAcceptanceFunction][alpha="+alpha+"][warmup=" + nOfRandomWalks + "]";
+ return "[name=SchrimpfAcceptance][alpha="+alpha+"][warmup=" + nOfRandomWalks + "]";
}
private double getThreshold(int iteration) {
double scheduleVariable = (double) iteration / (double) nOfTotalIterations;
- double currentThreshold = initialThreshold * Math.exp(-1. * Math.log(2) * scheduleVariable / alpha);
- return currentThreshold;
+ return initialThreshold * Math.exp(-1. * Math.log(2) * scheduleVariable / alpha);
}
- public double getInitialThreshold(){
+ @SuppressWarnings("UnusedDeclaration")
+ public double getInitialThreshold(){
return initialThreshold;
}
@@ -177,39 +177,39 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold");
logger.info("start random-walk (see randomWalk.xml)");
double now = System.currentTimeMillis();
- this.nOfTotalIterations = algorithm.getNuOfIterations();
-
+ 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.setNuOfIterations(nOfRandomWalks);
+ vra.setMaxIterations(nOfRandomWalks);
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
-
+
@Override
public void informIterationEnds(int iteration, VehicleRoutingProblem problem, Collection