mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
fix algorithmSearchProgress...Listener - reset it when algorithm starts,
deprecate setters VehicleRoutingProblem to make it immutable in the next release, add Example
This commit is contained in:
parent
a113a6cf18
commit
bc6c1e23b5
5 changed files with 114 additions and 38 deletions
|
|
@ -0,0 +1,64 @@
|
|||
package examples;
|
||||
|
||||
import readers.SolomonReader;
|
||||
import algorithms.GreedySchrimpfFactory;
|
||||
import algorithms.SchrimpfFactory;
|
||||
import analysis.AlgorithmSearchProgressChartListener;
|
||||
import analysis.StopWatch;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
|
||||
|
||||
public class CompareAlgorithmExample {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
/*
|
||||
* Build the problem.
|
||||
*
|
||||
* But define a problem-builder first.
|
||||
*/
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
/*
|
||||
* A solomonReader reads solomon-instance files, and stores the required information in the builder.
|
||||
*/
|
||||
new SolomonReader(vrpBuilder).read("input/C101_solomon.txt");
|
||||
|
||||
/*
|
||||
* Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances).
|
||||
*/
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
/*
|
||||
* Get schrimpf with threshold accepting
|
||||
* Note that Priority.LOW is a way to priorize AlgorithmListeners
|
||||
*/
|
||||
VehicleRoutingAlgorithm vra_withThreshold = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
vra_withThreshold.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/schrimpfThreshold_progress.png"), Priority.LOW);
|
||||
vra_withThreshold.getAlgorithmListeners().addListener(new StopWatch(), Priority.HIGH);
|
||||
/*
|
||||
* Get greedy schrimpf
|
||||
*/
|
||||
VehicleRoutingAlgorithm vra_greedy = new GreedySchrimpfFactory().createAlgorithm(vrp);
|
||||
vra_greedy.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/schrimpfGreedy_progress.png"), Priority.LOW);
|
||||
vra_greedy.getAlgorithmListeners().addListener(new StopWatch(), Priority.HIGH);
|
||||
|
||||
/*
|
||||
* run both
|
||||
*/
|
||||
vra_withThreshold.searchSolutions();
|
||||
|
||||
vra_greedy.searchSolutions();
|
||||
|
||||
|
||||
vra_greedy.setPrematureBreak(40);
|
||||
vra_greedy.searchSolutions();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ public class SolomonExample {
|
|||
* The algorithm can be defined and configured in an xml-file.
|
||||
*/
|
||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
|
||||
// vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener(pngFileName));
|
||||
/*
|
||||
* Solve the problem.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue