mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add VRPHE and VFM example
This commit is contained in:
parent
4dbf2e9388
commit
c723415839
3 changed files with 195 additions and 0 deletions
73
jsprit-examples/input/algorithmConfigWithSchrimpfAcceptance.xml
Executable file
73
jsprit-examples/input/algorithmConfigWithSchrimpfAcceptance.xml
Executable file
|
|
@ -0,0 +1,73 @@
|
|||
<?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"/>
|
||||
</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>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package jsprit.examples;
|
||||
|
||||
public class VFMExample {
|
||||
|
||||
}
|
||||
117
jsprit-examples/src/main/java/jsprit/examples/VRPHEExample.java
Normal file
117
jsprit-examples/src/main/java/jsprit/examples/VRPHEExample.java
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
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 VRPHEExample {
|
||||
|
||||
|
||||
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
|
||||
//2xtype1
|
||||
VehicleType type1 = VehicleTypeImpl.Builder.newInstance("type_1", 120).setCostPerDistance(1.0).build();
|
||||
VehicleImpl vehicle1_1 = VehicleImpl.Builder.newInstance("1_1").setLocationCoord(Coordinate.newInstance(40, 40)).setType(type1).build();
|
||||
vrpBuilder.addVehicle(vehicle1_1);
|
||||
VehicleImpl vehicle1_2 = VehicleImpl.Builder.newInstance("1_2").setLocationCoord(Coordinate.newInstance(40, 40)).setType(type1).build();
|
||||
vrpBuilder.addVehicle(vehicle1_2);
|
||||
//1xtype2
|
||||
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type_2", 160).setCostPerDistance(1.1).build();
|
||||
VehicleImpl vehicle2_1 = VehicleImpl.Builder.newInstance("2_1").setLocationCoord(Coordinate.newInstance(40, 40)).setType(type2).build();
|
||||
vrpBuilder.addVehicle(vehicle2_1);
|
||||
//1xtype3
|
||||
VehicleType type3 = VehicleTypeImpl.Builder.newInstance("type_3", 300).setCostPerDistance(1.3).build();
|
||||
VehicleImpl vehicle3_1 = VehicleImpl.Builder.newInstance("3_1").setLocationCoord(Coordinate.newInstance(40, 40)).setType(type3).build();
|
||||
vrpBuilder.addVehicle(vehicle3_1);
|
||||
|
||||
//add penaltyVehicles to allow invalid solutions temporarily
|
||||
vrpBuilder.addPenaltyVehicles(5, 1000);
|
||||
|
||||
//set fleetsize finite
|
||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||
|
||||
//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