mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add example for VRP with heterogeneous fleet as well as an example of
how to benchmark it
This commit is contained in:
parent
66df42ac2e
commit
9d1bbc2e84
5 changed files with 202 additions and 115 deletions
75
jsprit-examples/input/algorithmConfig_considerFixedCosts.xml
Executable file
75
jsprit-examples/input/algorithmConfig_considerFixedCosts.xml
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2013 Stefan Schroeder
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Contributors:
|
||||
Stefan Schroeder - initial API and implementation
|
||||
-->
|
||||
<algorithm xmlns="http://www.w3schools.com"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd">
|
||||
|
||||
<iterations>2000</iterations>
|
||||
|
||||
<construction>
|
||||
<insertion name="bestInsertion">
|
||||
<considerFixedCosts weight="1.0">true</considerFixedCosts>
|
||||
</insertion>
|
||||
</construction>
|
||||
|
||||
<strategy>
|
||||
<memory>1</memory>
|
||||
<searchStrategies>
|
||||
<searchStrategy name="radialRuinAndRecreate">
|
||||
<selector name="selectBest"/>
|
||||
<acceptor name="schrimpfAcceptance">
|
||||
<alpha>0.05</alpha>
|
||||
<warmup>20</warmup>
|
||||
</acceptor>
|
||||
|
||||
<modules>
|
||||
<module name="ruin_and_recreate">
|
||||
<ruin name="randomRuin">
|
||||
<share>0.5</share>
|
||||
</ruin>
|
||||
<insertion name="bestInsertion"/>
|
||||
</module>
|
||||
|
||||
</modules>
|
||||
<probability>0.5</probability>
|
||||
</searchStrategy>
|
||||
|
||||
<searchStrategy name="radialRuinAndRecreate">
|
||||
<selector name="selectBest"/>
|
||||
<acceptor name="schrimpfAcceptance"/>
|
||||
|
||||
<modules>
|
||||
<module name="ruin_and_recreate">
|
||||
<ruin id="1" name="radialRuin">
|
||||
<share>0.3</share>
|
||||
</ruin>
|
||||
<insertion name="bestInsertion"/>
|
||||
</module>
|
||||
|
||||
</modules>
|
||||
<probability>0.5</probability>
|
||||
</searchStrategy>
|
||||
|
||||
</searchStrategies>
|
||||
</strategy>
|
||||
|
||||
|
||||
</algorithm>
|
||||
67
jsprit-examples/input/cn_14mix.txt
Normal file
67
jsprit-examples/input/cn_14mix.txt
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
50
|
||||
0 40 40 0
|
||||
1 22 22 18
|
||||
2 36 26 26
|
||||
3 21 45 11
|
||||
4 45 35 30
|
||||
5 55 20 21
|
||||
6 33 34 19
|
||||
7 50 50 15
|
||||
8 55 45 16
|
||||
9 26 59 29
|
||||
10 40 66 26
|
||||
11 55 65 37
|
||||
12 35 51 16
|
||||
13 62 35 12
|
||||
14 62 57 31
|
||||
15 62 24 8
|
||||
16 21 36 19
|
||||
17 33 44 20
|
||||
18 9 56 13
|
||||
19 62 48 15
|
||||
20 66 14 22
|
||||
21 44 13 28
|
||||
22 26 13 12
|
||||
23 11 28 6
|
||||
24 7 43 27
|
||||
25 17 64 14
|
||||
26 41 46 18
|
||||
27 55 34 17
|
||||
28 35 16 29
|
||||
29 52 26 13
|
||||
30 43 26 22
|
||||
31 31 76 25
|
||||
32 22 53 28
|
||||
33 26 29 27
|
||||
34 50 40 19
|
||||
35 55 50 10
|
||||
36 54 10 12
|
||||
37 60 15 14
|
||||
38 47 66 24
|
||||
39 30 60 16
|
||||
40 30 50 33
|
||||
41 12 17 15
|
||||
42 15 14 11
|
||||
43 16 19 18
|
||||
44 21 48 17
|
||||
45 50 30 21
|
||||
46 51 42 27
|
||||
47 50 15 19
|
||||
48 48 21 20
|
||||
49 12 38 5
|
||||
50 15 56 22
|
||||
//Vehicles characteristics: volume, fixed cost, variable cost, number available
|
||||
v 1 120 1000 1.0 4
|
||||
v 2 160 1500 1.1 2
|
||||
v 3 300 3500 1.4 1
|
||||
|
||||
160
|
||||
8 300 0 10000 625.679906 + 7*1000 + 1500 =
|
||||
7 26 7 35 19 8 46 34 10530637
|
||||
4 10 38 11 14 10794953
|
||||
8 33 1 43 42 41 23 49 16 10916479
|
||||
6 48 47 36 21 28 22 10931709
|
||||
7 27 13 15 20 37 5 29 10832981
|
||||
6 44 32 50 18 24 3 10862722
|
||||
5 6 2 30 45 4 10469680
|
||||
7 12 39 31 25 9 40 17 15917639
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package jsprit.examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener;
|
||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||
import jsprit.analysis.toolbox.Plotter;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter.Print;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.util.Solutions;
|
||||
import jsprit.instance.reader.VrphGoldenReader;
|
||||
import jsprit.instance.reader.VrphGoldenReader.VrphType;
|
||||
|
||||
/**
|
||||
* Shows how to benchmark the algorithm on different classical HVRP and FSM instances.
|
||||
*
|
||||
* <p>These instances are from Golden and Taillard and copied from http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html.
|
||||
*
|
||||
* <p>You can find best results of different problems, instances and authors here:
|
||||
* <br><a href="http://www2.ic.uff.br/~satoru/conteudo/artigos/PAPER%20PUCA-JHeuristics-2011.pdf">http://www2.ic.uff.br/~satoru/conteudo/artigos/PAPER%20PUCA-JHeuristics-2011.pdf</a>
|
||||
* <br><a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.100.2331&rep=rep1&type=pdf">http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.100.2331&rep=rep1&type=pdf</a>
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class HVRPBenchmarkExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
//read modified Golden-instance, you can find all relevant instances in jsprit-instances/instances/vrph
|
||||
//you can build various problems, see VrphType doc for more details
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPFD).read("input/cn_14mix.txt");
|
||||
vrpBuilder.addPenaltyVehicles(10.0);
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_considerFixedCosts.xml");
|
||||
vra.setNuOfIterations(10000);
|
||||
// vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(500));
|
||||
vra.addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
VehicleRoutingProblemSolution best = Solutions.bestOf(solutions);
|
||||
|
||||
SolutionPrinter.print(vrp, best, Print.VERBOSE);
|
||||
|
||||
|
||||
Plotter plotter = new Plotter(vrp,best);
|
||||
plotter.plot("output/cn14.png", "cn14");
|
||||
|
||||
new GraphStreamViewer(vrp, best).setRenderDelay(100).display();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ import jsprit.core.util.Solutions;
|
|||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class VRPHEExample {
|
||||
public class HVRPExample {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
package jsprit.examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter.Print;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
||||
/**
|
||||
* customers (id,x,y,demand)
|
||||
* 1 22 22 18
|
||||
* 2 36 26 26
|
||||
* 3 21 45 11
|
||||
* 4 45 35 30
|
||||
* 5 55 20 21
|
||||
* 6 33 34 19
|
||||
* 7 50 50 15
|
||||
* 8 55 45 16
|
||||
* 9 26 59 29
|
||||
* 10 40 66 26
|
||||
* 11 55 65 37
|
||||
* 12 35 51 16
|
||||
* 13 62 35 12
|
||||
* 14 62 57 31
|
||||
* 15 62 24 8
|
||||
* 16 21 36 19
|
||||
* 17 33 44 20
|
||||
* 18 9 56 13
|
||||
* 19 62 48 15
|
||||
* 20 66 14 22
|
||||
*
|
||||
* vehicles (id,cap,fixed costs, perDistance, #vehicles) at location (40,40)
|
||||
* 1 120 1000 1.0 2
|
||||
* 2 160 1500 1.1 1
|
||||
* 3 300 3500 1.4 1
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class VFMExample {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
//add customers
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("1", 18).setCoord(Coordinate.newInstance(22, 22)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("2", 26).setCoord(Coordinate.newInstance(36, 26)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("3", 11).setCoord(Coordinate.newInstance(21, 45)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("4", 30).setCoord(Coordinate.newInstance(45, 35)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("5", 21).setCoord(Coordinate.newInstance(55, 20)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("6", 19).setCoord(Coordinate.newInstance(33, 34)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("7", 15).setCoord(Coordinate.newInstance(50, 50)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("8", 16).setCoord(Coordinate.newInstance(55, 45)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("9", 29).setCoord(Coordinate.newInstance(26, 59)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("10", 26).setCoord(Coordinate.newInstance(40, 66)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("11", 37).setCoord(Coordinate.newInstance(55, 56)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("12", 16).setCoord(Coordinate.newInstance(35, 51)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("13", 12).setCoord(Coordinate.newInstance(62, 35)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("14", 31).setCoord(Coordinate.newInstance(62, 57)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("15", 8).setCoord(Coordinate.newInstance(62, 24)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("16", 19).setCoord(Coordinate.newInstance(21, 36)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("17", 20).setCoord(Coordinate.newInstance(33, 44)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("18", 13).setCoord(Coordinate.newInstance(9, 56)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("19", 15).setCoord(Coordinate.newInstance(62, 48)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("20", 22).setCoord(Coordinate.newInstance(66, 14)).build());
|
||||
|
||||
|
||||
//add vehicle - finite fleet
|
||||
//fixed costs only (and equal variable costs)
|
||||
//vehicle type1
|
||||
VehicleType type1 = VehicleTypeImpl.Builder.newInstance("type_1", 120).setCostPerDistance(1.0).setFixedCost(1000).build();
|
||||
VehicleImpl vehicle1 = VehicleImpl.Builder.newInstance("1_1").setLocationCoord(Coordinate.newInstance(40, 40)).setType(type1).build();
|
||||
vrpBuilder.addVehicle(vehicle1);
|
||||
//vehicle type2
|
||||
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type_2", 160).setCostPerDistance(1.0).setFixedCost(1500).build();
|
||||
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("2_1").setLocationCoord(Coordinate.newInstance(40, 40)).setType(type2).build();
|
||||
vrpBuilder.addVehicle(vehicle2);
|
||||
//vehicle type3
|
||||
VehicleType type3 = VehicleTypeImpl.Builder.newInstance("type_3", 300).setCostPerDistance(1.0).setFixedCost(3500).build();
|
||||
VehicleImpl vehicle3 = VehicleImpl.Builder.newInstance("3_1").setLocationCoord(Coordinate.newInstance(40, 40)).setType(type3).build();
|
||||
vrpBuilder.addVehicle(vehicle3);
|
||||
|
||||
//set fleetsize finite - which actually the default value, thus it does not need to be set
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
|
||||
//build problem
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfigWithSchrimpfAcceptance.xml");
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
VehicleRoutingProblemSolution best = Solutions.bestOf(solutions);
|
||||
|
||||
SolutionPrinter.print(vrp, best, Print.VERBOSE);
|
||||
|
||||
new GraphStreamViewer(vrp, best).setRenderDelay(100).display();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue