mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
mtw
This commit is contained in:
parent
1075e38504
commit
d28471fbda
50 changed files with 753 additions and 796 deletions
|
|
@ -58,28 +58,30 @@ public class MultipleTimeWindowExample {
|
|||
* build services at the required locations, each with a capacity-demand of 1.
|
||||
*/
|
||||
Service service1 = Service.Builder.newInstance("1")
|
||||
.addTimeWindow(5, 10)
|
||||
.addTimeWindow(50,100)
|
||||
.addTimeWindow(20,35)
|
||||
.addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(10, 0)).build();
|
||||
|
||||
Service service2 = Service.Builder.newInstance("2")
|
||||
.addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(20, 0)).build();
|
||||
.addSizeDimension(WEIGHT_INDEX, 1)
|
||||
// .setServiceTime(10)
|
||||
.setLocation(Location.newInstance(20, 0)).setServiceTime(10).build();
|
||||
|
||||
Service service3 = Service.Builder.newInstance("3")
|
||||
.addTimeWindow(5, 10)
|
||||
.addTimeWindow(35, 40)
|
||||
.addTimeWindow(35, 50)
|
||||
.addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(30, 0)).build();
|
||||
|
||||
Service service4 = Service.Builder.newInstance("4")
|
||||
// .addTimeWindow(5,10)
|
||||
.addTimeWindow(20, 40)
|
||||
.addTimeWindow(70, 80)
|
||||
.addTimeWindow(45, 80)
|
||||
.addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(40, 0)).build();
|
||||
|
||||
Service service5 = Service.Builder.newInstance("5")
|
||||
.addTimeWindow(5,10)
|
||||
// .addTimeWindow(20, 40)
|
||||
.addTimeWindow(35,100)
|
||||
.addTimeWindow(20, 40)
|
||||
.addTimeWindow(60,100)
|
||||
.addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(20, 0)).build();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,152 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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/>.
|
||||
******************************************************************************/
|
||||
package jsprit.examples;
|
||||
|
||||
import jsprit.analysis.toolbox.Plotter;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.box.Jsprit;
|
||||
import jsprit.core.analysis.SolutionAnalyser;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.cost.TransportDistance;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.Builder;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.reporting.SolutionPrinter;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class MultipleTimeWindowExample2 {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
/*
|
||||
* get a vehicle type-builder and build a type with the typeId "vehicleType" and one capacity dimension, i.e. weight, and capacity dimension value of 2
|
||||
*/
|
||||
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType")
|
||||
.addCapacityDimension(0, 60)
|
||||
.setCostPerWaitingTime(0.8)
|
||||
;
|
||||
VehicleType vehicleType = vehicleTypeBuilder.build();
|
||||
|
||||
/*
|
||||
* get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType"
|
||||
*/
|
||||
Builder vehicleBuilder = Builder.newInstance("vehicle");
|
||||
vehicleBuilder.setStartLocation(Location.newInstance(0, 0));
|
||||
vehicleBuilder.setType(vehicleType);
|
||||
vehicleBuilder.setLatestArrival(800);
|
||||
VehicleImpl vehicle = vehicleBuilder.build();
|
||||
|
||||
// Builder vehicleBuilder2 = Builder.newInstance("vehicle2");
|
||||
// vehicleBuilder2.setStartLocation(Location.newInstance(0, 0));
|
||||
// vehicleBuilder2.setType(vehicleType);
|
||||
// vehicleBuilder2.setEarliestStart(250).setLatestArrival(450);
|
||||
// VehicleImpl vehicle2 = vehicleBuilder2.build();
|
||||
//
|
||||
//
|
||||
// Builder vehicleBuilder3 = Builder.newInstance("vehicle3");
|
||||
// vehicleBuilder3.setStartLocation(Location.newInstance(0, 0));
|
||||
// vehicleBuilder3.setType(vehicleType);
|
||||
// vehicleBuilder3.setEarliestStart(380).setLatestArrival(600);
|
||||
// VehicleImpl vehicle3 = vehicleBuilder3.build();
|
||||
|
||||
/*
|
||||
* build services at the required locations, each with a capacity-demand of 1.
|
||||
*/
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
// .addVehicle(vehicle2).addVehicle(vehicle3);
|
||||
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
||||
|
||||
|
||||
Random random = RandomNumberGeneration.newInstance();
|
||||
for(int i=0;i<40;i++){
|
||||
Service service = Service.Builder.newInstance("" + (i + 1))
|
||||
.addTimeWindow(random.nextInt(50), 200)
|
||||
.addTimeWindow(220 + random.nextInt(50), 350)
|
||||
.addTimeWindow(400 + random.nextInt(50), 550)
|
||||
// .addSizeDimension(0, 1)
|
||||
.setServiceTime(1)
|
||||
.setLocation(Location.newInstance(random.nextInt(50), random.nextInt(50))).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
|
||||
for(int i=0;i<12;i++){
|
||||
Service service = Service.Builder.newInstance(""+(i+51))
|
||||
// .addTimeWindow(0, 80)
|
||||
//// .addTimeWindow(120, 200)
|
||||
// .addTimeWindow(250,500)
|
||||
// .addSizeDimension(0, 1)
|
||||
.setServiceTime(2)
|
||||
.setLocation(Location.newInstance(50 + random.nextInt(20), 20 + random.nextInt(25))).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
|
||||
Service service = Service.Builder.newInstance("100")
|
||||
.addTimeWindow(50, 80)
|
||||
.setServiceTime(10)
|
||||
.setLocation(Location.newInstance(40, 1)).build();
|
||||
vrpBuilder.addJob(service);
|
||||
|
||||
final VehicleRoutingProblem problem = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(problem).buildAlgorithm();
|
||||
|
||||
/*
|
||||
* and search a solution
|
||||
*/
|
||||
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
|
||||
|
||||
/*
|
||||
* get the best
|
||||
*/
|
||||
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
|
||||
|
||||
// new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml");
|
||||
|
||||
SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE);
|
||||
|
||||
/*
|
||||
* plot
|
||||
*/
|
||||
new Plotter(problem,bestSolution).setLabel(Plotter.Label.ID).plot("output/plot", "mtw");
|
||||
|
||||
SolutionAnalyser a = new SolutionAnalyser(problem, bestSolution, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to) {
|
||||
return problem.getTransportCosts().getTransportTime(from,to,0.,null,null);
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println("distance: " + a.getDistance());
|
||||
System.out.println("ttime: " + a.getTransportTime());
|
||||
System.out.println("completion: " + a.getOperationTime());
|
||||
System.out.println("waiting: " + a.getWaitingTime());
|
||||
|
||||
// new GraphStreamViewer(problem, bestSolution).labelWith(Label.ID).setRenderDelay(200).display();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue