diff --git a/jsprit-examples/input/bicycle_messenger_demand.txt b/jsprit-examples/input/bicycle_messenger_demand.txt new file mode 100644 index 00000000..42890e1b --- /dev/null +++ b/jsprit-examples/input/bicycle_messenger_demand.txt @@ -0,0 +1,31 @@ +item id pickup_x pickup_y deliver_x deliver_y +envelope 1 13745 55419 13883 55756 +envelope 2 8406 53246 13937 55854 +envelope 3 15738 57396 35996 79499 +envelope 4 12045 60418 19349 57118 +envelope 5 13750 56416 35733 78403 +envelope 6 13190 57068 11860 59749 +envelope 7 15021 55768 14098 57379 +envelope 8 11513 58543 11501 59683 +envelope 9 12013 64155 14120 59301 +envelope 10 15006 57578 35511 78426 +envelope 11 11450 58819 11916 58338 +envelope 12 13728 56304 35524 79013 +envelope 13 15104 60923 17937 57066 +envelope 14 11373 58388 13983 53804 +envelope 15 18575 55186 18718 54381 +envelope 16 11639 50071 17363 58375 +envelope 17 11273 53410 10860 60441 +envelope 18 13766 59041 13963 57769 +envelope 19 16138 55801 16183 56024 +envelope 20 13728 56146 14301 61694 +envelope 21 12848 57059 13586 59734 +envelope 22 13645 56488 13955 55859 +envelope 23 12896 56838 13937 55908 +envelope 24 13341 58150 35709 78924 +envelope 25 13483 57303 13614 57820 +envelope 26 12741 63478 15230 59838 +envelope 27 14676 51691 16501 48361 +envelope 28 13748 54933 14120 56110 +envelope 29 17875 59565 20453 61903 +envelope 30 9772 56424 6404 55601 \ No newline at end of file diff --git a/jsprit-examples/input/bicycle_messenger_supply.txt b/jsprit-examples/input/bicycle_messenger_supply.txt new file mode 100644 index 00000000..f25f8b66 --- /dev/null +++ b/jsprit-examples/input/bicycle_messenger_supply.txt @@ -0,0 +1,6 @@ +type id x y +messenger A 13750 57578 +messenger B 15104 53410 +messenger C 13728 55801 +messenger D 12741 63478 +messenger E 14676 18575 \ No newline at end of file diff --git a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java new file mode 100644 index 00000000..123834d9 --- /dev/null +++ b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java @@ -0,0 +1,87 @@ +package jsprit.examples; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Collection; + +import jsprit.analysis.toolbox.Plotter; +import jsprit.analysis.toolbox.SolutionPrinter; +import jsprit.core.algorithm.VehicleRoutingAlgorithm; +import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; +import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.VehicleRoutingProblem.Builder; +import jsprit.core.problem.VehicleRoutingProblem.FleetSize; +import jsprit.core.problem.job.Shipment; +import jsprit.core.problem.solution.VehicleRoutingProblemSolution; +import jsprit.core.problem.vehicle.Vehicle; +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; + +public class BicycleMessenger { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + + VehicleRoutingProblem.Builder problemBuilder = VehicleRoutingProblem.Builder.newInstance(); + readEnvelopes(problemBuilder); + readMessengers(problemBuilder); + problemBuilder.setFleetSize(FleetSize.FINITE); + + VehicleRoutingProblem bicycleMessengerProblem = problemBuilder.build(); + + VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(bicycleMessengerProblem, 6, "input/algorithmConfig_open.xml"); + algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(50)); + Collection solutions = algorithm.searchSolutions(); + + SolutionPrinter.print(Solutions.bestOf(solutions)); + Plotter plotter = new Plotter(bicycleMessengerProblem); + plotter.plotShipments(true); + plotter.plot("output/bicycleMessengerProblem.png", "bicycleMenssenger"); + + + Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions)); + plotter1.plotShipments(false); + plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMenssenger"); + + + } + + private static void readEnvelopes(Builder problemBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("input/bicycle_messenger_demand.txt"))); + String line = null; + boolean firstLine = true; + while((line = reader.readLine()) != null){ + if(firstLine) { firstLine = false; continue; } + String[] tokens = line.split("\\s+"); + Shipment envelope = Shipment.Builder.newInstance(tokens[1], 1).setPickupCoord(Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[3]))) + .setDeliveryCoord(Coordinate.newInstance(Double.parseDouble(tokens[4]), Double.parseDouble(tokens[5]))).build(); + problemBuilder.addJob(envelope); + } + reader.close(); + } + + private static void readMessengers(Builder problemBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("input/bicycle_messenger_supply.txt"))); + String line = null; + boolean firstLine = true; + VehicleType messengerType = VehicleTypeImpl.Builder.newInstance("messengerType", 15).setCostPerDistance(1).build(); + while((line = reader.readLine()) != null){ + if(firstLine) { firstLine = false; continue; } + String[] tokens = line.split("\\s+"); + Vehicle vehicle = VehicleImpl.Builder.newInstance(tokens[1]).setLocationCoord(Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[3]))) + .setReturnToDepot(false).setType(messengerType).build(); + problemBuilder.addVehicle(vehicle); + } + reader.close(); + } + +}