From bf8acf685341bd46e7bd87df87be4bc4044c05a6 Mon Sep 17 00:00:00 2001 From: Dee Yeum <36423861+ChefYeum@users.noreply.github.com> Date: Sun, 6 Dec 2020 19:00:26 +0000 Subject: [PATCH] Use markdown code block --- docs/Simple-Example.md | 53 +++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/docs/Simple-Example.md b/docs/Simple-Example.md index d61aa27e5..1f27be0b6 100644 --- a/docs/Simple-Example.md +++ b/docs/Simple-Example.md @@ -14,7 +14,8 @@ Assume the following problem. We can employ one vehicle(-type) located at (10,10 First, build a vehicle with its vehicle-type: -
/*
+```java
+/*
* get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2
* you are free to add an arbitrary number of capacity dimensions with .addCapacityDimension(dimensionIndex,dimensionValue)
*/
@@ -29,10 +30,11 @@ VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
vehicleBuilder.setStartLocation(Location.newInstance(10, 10));
vehicleBuilder.setType(vehicleType);
VehicleImpl vehicle = vehicleBuilder.build();
-
+```
Second, define the deliveries as services. Make sure their size dimensions are in line with your vehicle capacity dimensions (thus here the weight-index is made final and also used to define services).
-/*
+```java
+/*
* build services with id 1...4 at the required locations, each with a capacity-demand of 1.
* Note, that the builder allows chaining which makes building quite handy
*/
@@ -40,10 +42,11 @@ Service service1 = Service.Builder.newInstance("1").addSizeDimension(WEIGHT_INDE
Service service2 = Service.Builder.newInstance("2").addSizeDimension(WEIGHT_INDEX,1).setLocation(Location.newInstance(5, 13)).build();
Service service3 = Service.Builder.newInstance("3").addSizeDimension(WEIGHT_INDEX,1).setLocation(Location.newInstance(15, 7)).build();
Service service4 = Service.Builder.newInstance("4").addSizeDimension(WEIGHT_INDEX,1).setLocation(Location.newInstance(15, 13)).build();
-
+```
and put vehicles and services together to setup the problem.
-/*
+```java
+/*
* again define a builder to build the VehicleRoutingProblem
*/
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
@@ -56,11 +59,11 @@ vrpBuilder.addJob(service1).addJob(service2).addJob(service3).addJob(service4);
* by default, transport costs are computed as Euclidean distances
*/
VehicleRoutingProblem problem = vrpBuilder.build();
-
-
+```
Third, solve the problem by defining and running an algorithm. Here it comes out-of-the-box.
-/*
+```java
+/*
* get the algorithm out-of-the-box.
*/
VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(problem);
@@ -74,14 +77,17 @@ Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolu
* use the static helper-method in the utility class Solutions to get the best solution (in terms of least costs)
*/
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
-
+```
If you want to print a concise summary of the results to the console, do this:
-SolutionPrinter.print(problem, bestSolution, Print.CONCISE);
+```java
+SolutionPrinter.print(problem, bestSolution, Print.CONCISE);
+```
which results in
-+--------------------------+ +``` ++--------------------------+ | problem | +---------------+----------+ | indicator | value | @@ -99,14 +105,17 @@ which results in | costs | 35.3238075793812 | | nVehicles | 2 | +----------------------------------------------------------+ -+``` If you want to have more information about individual routes, use the verbose level such as -
SolutionPrinter.print(problem, bestSolution, Print.VERBOSE);
+```
+SolutionPrinter.print(problem, bestSolution, Print.VERBOSE);
+```
and you get this addtionally:
-+--------------------------------------------------------------------------------------------------------------------------------+ +``` ++--------------------------------------------------------------------------------------------------------------------------------+ | detailed solution | +---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+ | route | vehicle | activity | job | arrTime | endTime | costs | @@ -121,23 +130,29 @@ and you get this addtionally: | 2 | vehicle | service | 4 | 12 | 12 | 12 | | 2 | vehicle | end | - | 18 | undef | 18 | +--------------------------------------------------------------------------------------------------------------------------------+ -+``` If you want to write out problem and solution, you require the writer that is located in jsprit-io. Thus, you need to add the corresponding module to your pom.xml much like you added jsprit-core. Just use jsprit-io. You can then use this: -
new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml");
-
+```
+new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml");
+```
+
which looks like this: [problem-with-solution.xml](https://github.com/jsprit/misc-rep/raw/master/wiki-images/problem-with-solution.xml).
If you want to further analyse your solution, add the module jsprit-analysis to your pom. Then you can plot the routes like this
-new Plotter(problem,bestSolution).plot("output/solution.png", "solution");
+```
+new Plotter(problem,bestSolution).plot("output/solution.png", "solution");
+```
and you get [solution.png](https://github.com/jsprit/misc-rep/blob/master/wiki-images/solution.png)
or use the GraphStreamViewer which dynamically renders the problem and its according solution by coding
-new GraphStreamViewer(problem, bestSolution).setRenderDelay(100).display();
+```
+new GraphStreamViewer(problem, bestSolution).setRenderDelay(100).display();
+```
You can find the entire code [here](https://github.com/graphhopper/jsprit/blob/master/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleExample.java).