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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -16,12 +16,14 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.algorithm.acceptor;
|
package jsprit.core.algorithm.acceptor;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use GreedyAcceptance instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public class AcceptNewRemoveFirst implements SolutionAcceptor{
|
public class AcceptNewRemoveFirst implements SolutionAcceptor{
|
||||||
|
|
||||||
private final int solutionMemory;
|
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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* 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;
|
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{
|
public class GreedyAcceptance implements SolutionAcceptor{
|
||||||
|
|
||||||
private final int solutionMemory;
|
private final int solutionMemory;
|
||||||
|
|
@ -59,7 +64,7 @@ public class GreedyAcceptance implements SolutionAcceptor{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -16,12 +16,12 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.algorithm.acceptor;
|
package jsprit.core.algorithm.acceptor;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class GreedyAcceptance_minVehFirst implements SolutionAcceptor{
|
public class GreedyAcceptance_minVehFirst implements SolutionAcceptor{
|
||||||
|
|
||||||
private final int solutionMemory;
|
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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -101,11 +101,7 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @deprecated use <code>new SchrimpfAcceptance(solutionMemory,alpha)</code> instead. if you want to determine ini-threshold with a
|
||||||
* @param solutionMemory
|
|
||||||
* @param alpha
|
|
||||||
* @param nOfWarmupIterations
|
|
||||||
* @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.
|
* random walk and the algorithm 'randomWalk.xml' use SchrimpfInitialThresholdGenerator.class instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|
@ -130,7 +126,11 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
|
||||||
if(worst == null) worst = solutionInMemory;
|
if(worst == null) worst = solutionInMemory;
|
||||||
else if(solutionInMemory.getCost() > worst.getCost()) 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.remove(worst);
|
||||||
solutions.add(newSolution);
|
solutions.add(newSolution);
|
||||||
solutionAccepted = true;
|
solutionAccepted = true;
|
||||||
|
|
@ -141,16 +141,16 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[name=schrimpfAcceptanceFunction][alpha="+alpha+"][warmup=" + nOfRandomWalks + "]";
|
return "[name=SchrimpfAcceptance][alpha="+alpha+"][warmup=" + nOfRandomWalks + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getThreshold(int iteration) {
|
private double getThreshold(int iteration) {
|
||||||
double scheduleVariable = (double) iteration / (double) nOfTotalIterations;
|
double scheduleVariable = (double) iteration / (double) nOfTotalIterations;
|
||||||
double currentThreshold = initialThreshold * Math.exp(-1. * Math.log(2) * scheduleVariable / alpha);
|
return initialThreshold * Math.exp(-1. * Math.log(2) * scheduleVariable / alpha);
|
||||||
return currentThreshold;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
public double getInitialThreshold(){
|
public double getInitialThreshold(){
|
||||||
return initialThreshold;
|
return initialThreshold;
|
||||||
}
|
}
|
||||||
|
|
@ -177,7 +177,7 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
|
||||||
logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold");
|
logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold");
|
||||||
logger.info("start random-walk (see randomWalk.xml)");
|
logger.info("start random-walk (see randomWalk.xml)");
|
||||||
double now = System.currentTimeMillis();
|
double now = System.currentTimeMillis();
|
||||||
this.nOfTotalIterations = algorithm.getNuOfIterations();
|
this.nOfTotalIterations = algorithm.getMaxIterations();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* randomWalk to determine standardDev
|
* randomWalk to determine standardDev
|
||||||
|
|
@ -188,7 +188,7 @@ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsList
|
||||||
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
||||||
new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
|
new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
|
||||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
|
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
|
||||||
vra.setNuOfIterations(nOfRandomWalks);
|
vra.setMaxIterations(nOfRandomWalks);
|
||||||
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
|
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
|
||||||
|
|
||||||
@Override
|
@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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* 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,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* 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
|
* 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/>.
|
* 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;
|
package jsprit.core.algorithm.acceptor;
|
||||||
|
|
||||||
|
|
@ -65,7 +63,7 @@ public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListene
|
||||||
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
||||||
new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
|
new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
|
||||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
|
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
|
||||||
vra.setNuOfIterations(nOfRandomWalks);
|
vra.setMaxIterations(nOfRandomWalks);
|
||||||
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
|
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue