mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add javadoc to acceptors
This commit is contained in:
parent
d551be0ca5
commit
55ffe3970f
5 changed files with 62 additions and 57 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
|
@ -16,12 +16,14 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.acceptor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use GreedyAcceptance instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class AcceptNewRemoveFirst implements SolutionAcceptor{
|
||||
|
||||
private final int solutionMemory;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
|
@ -21,7 +21,12 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
|||
import java.util.Collection;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Acceptor that accepts solutions to be memorized only better solutions.
|
||||
*
|
||||
* <p>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.</p>
|
||||
*/
|
||||
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]";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
|
@ -16,12 +16,12 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.acceptor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
@Deprecated
|
||||
public class GreedyAcceptance_minVehFirst implements SolutionAcceptor{
|
||||
|
||||
private final int solutionMemory;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
|
@ -101,11 +101,7 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param solutionMemory
|
||||
* @param alpha
|
||||
* @param nOfWarmupIterations
|
||||
* @Deprecated use <code>new SchrimpfAcceptance(solutionMemory,alpha)</code> instead. if you want to determine ini-threshold with a
|
||||
* @deprecated use <code>new SchrimpfAcceptance(solutionMemory,alpha)</code> 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,7 +177,7 @@ 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
|
||||
|
|
@ -188,7 +188,7 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
|
|||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
|
@ -8,13 +8,11 @@
|
|||
*
|
||||
* 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.
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.acceptor;
|
||||
|
||||
|
|
@ -65,7 +63,7 @@ public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListene
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue