routing: Update CVRP sample
This commit is contained in:
@@ -41,58 +41,58 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333
|
||||
<line x1="798" y1="0" x2="798" y2="640" style="stroke-width:2;stroke:#969696;fill:none"/>
|
||||
<line x1="912" y1="0" x2="912" y2="640" style="stroke-width:2;stroke:#969696;fill:none"/>
|
||||
<!-- Print routes -->
|
||||
<!-- Print route 0 -->
|
||||
<polyline points="456,320 342.0,160.0 228,0" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<polyline points="228,0 171.0,40.0 114,80" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<!-- Print route 0: [0, 4, 3, 1, 7, 0] -->
|
||||
<polyline points="456,320 285.0,200.0 114,80" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<polyline points="114,80 57.0,80.0 0,80" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<polyline points="0,80 0.0,360.0 0,640" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<polyline points="0,640 228.0,480.0 456,320" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<circle cx="228" cy="0" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:white"/>
|
||||
<text x="228" y="0" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#4285F4">1</text>
|
||||
<polyline points="0,80 114.0,40.0 228,0" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<polyline points="228,0 285.0,120.0 342,240" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<polyline points="342,240 399.0,280.0 456,320" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:none;marker-mid:url(#arrow_blue)"/>
|
||||
<circle cx="114" cy="80" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:white"/>
|
||||
<text x="114" y="80" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#4285F4">4</text>
|
||||
<circle cx="0" cy="80" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:white"/>
|
||||
<text x="0" y="80" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#4285F4">3</text>
|
||||
<circle cx="0" cy="640" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:white"/>
|
||||
<text x="0" y="640" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#4285F4">15</text>
|
||||
<!-- Print route 1 -->
|
||||
<circle cx="228" cy="0" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:white"/>
|
||||
<text x="228" y="0" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#4285F4">1</text>
|
||||
<circle cx="342" cy="240" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#4285F4;fill:white"/>
|
||||
<text x="342" y="240" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#4285F4">7</text>
|
||||
<!-- Print route 1: [0, 14, 16, 10, 9, 0] -->
|
||||
<polyline points="456,320 570.0,440.0 684,560" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:none;marker-mid:url(#arrow_red)"/>
|
||||
<polyline points="684,560 741.0,600.0 798,640" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:none;marker-mid:url(#arrow_red)"/>
|
||||
<polyline points="798,640 855.0,520.0 912,400" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:none;marker-mid:url(#arrow_red)"/>
|
||||
<polyline points="912,400 912.0,200.0 912,0" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:none;marker-mid:url(#arrow_red)"/>
|
||||
<polyline points="912,0 684.0,160.0 456,320" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:none;marker-mid:url(#arrow_red)"/>
|
||||
<polyline points="912,400 741.0,400.0 570,400" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:none;marker-mid:url(#arrow_red)"/>
|
||||
<polyline points="570,400 513.0,360.0 456,320" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:none;marker-mid:url(#arrow_red)"/>
|
||||
<circle cx="684" cy="560" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:white"/>
|
||||
<text x="684" y="560" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#EA4335">14</text>
|
||||
<circle cx="798" cy="640" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:white"/>
|
||||
<text x="798" y="640" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#EA4335">16</text>
|
||||
<circle cx="912" cy="400" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:white"/>
|
||||
<text x="912" y="400" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#EA4335">10</text>
|
||||
<circle cx="912" cy="0" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:white"/>
|
||||
<text x="912" y="0" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#EA4335">2</text>
|
||||
<!-- Print route 2 -->
|
||||
<polyline points="456,320 399.0,280.0 342,240" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<polyline points="342,240 342.0,400.0 342,560" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<polyline points="342,560 285.0,520.0 228,480" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<circle cx="570" cy="400" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#EA4335;fill:white"/>
|
||||
<text x="570" y="400" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#EA4335">9</text>
|
||||
<!-- Print route 2: [0, 12, 11, 15, 13, 0] -->
|
||||
<polyline points="456,320 342.0,400.0 228,480" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<polyline points="228,480 171.0,480.0 114,480" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<polyline points="114,480 285.0,400.0 456,320" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<circle cx="342" cy="240" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:white"/>
|
||||
<text x="342" y="240" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#FBBC05">7</text>
|
||||
<circle cx="342" cy="560" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:white"/>
|
||||
<text x="342" y="560" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#FBBC05">13</text>
|
||||
<polyline points="114,480 57.0,560.0 0,640" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<polyline points="0,640 171.0,600.0 342,560" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<polyline points="342,560 399.0,440.0 456,320" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:none;marker-mid:url(#arrow_yellow)"/>
|
||||
<circle cx="228" cy="480" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:white"/>
|
||||
<text x="228" y="480" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#FBBC05">12</text>
|
||||
<circle cx="114" cy="480" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:white"/>
|
||||
<text x="114" y="480" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#FBBC05">11</text>
|
||||
<!-- Print route 3 -->
|
||||
<polyline points="456,320 513.0,360.0 570,400" style="stroke-width:6.666666666666667;stroke:#34A853;fill:none;marker-mid:url(#arrow_green)"/>
|
||||
<polyline points="570,400 627.0,320.0 684,240" style="stroke-width:6.666666666666667;stroke:#34A853;fill:none;marker-mid:url(#arrow_green)"/>
|
||||
<polyline points="684,240 741.0,200.0 798,160" style="stroke-width:6.666666666666667;stroke:#34A853;fill:none;marker-mid:url(#arrow_green)"/>
|
||||
<circle cx="0" cy="640" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:white"/>
|
||||
<text x="0" y="640" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#FBBC05">15</text>
|
||||
<circle cx="342" cy="560" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#FBBC05;fill:white"/>
|
||||
<text x="342" y="560" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#FBBC05">13</text>
|
||||
<!-- Print route 3: [0, 8, 2, 6, 5, 0] -->
|
||||
<polyline points="456,320 570.0,280.0 684,240" style="stroke-width:6.666666666666667;stroke:#34A853;fill:none;marker-mid:url(#arrow_green)"/>
|
||||
<polyline points="684,240 798.0,120.0 912,0" style="stroke-width:6.666666666666667;stroke:#34A853;fill:none;marker-mid:url(#arrow_green)"/>
|
||||
<polyline points="912,0 855.0,80.0 798,160" style="stroke-width:6.666666666666667;stroke:#34A853;fill:none;marker-mid:url(#arrow_green)"/>
|
||||
<polyline points="798,160 684.0,160.0 570,160" style="stroke-width:6.666666666666667;stroke:#34A853;fill:none;marker-mid:url(#arrow_green)"/>
|
||||
<polyline points="570,160 513.0,240.0 456,320" style="stroke-width:6.666666666666667;stroke:#34A853;fill:none;marker-mid:url(#arrow_green)"/>
|
||||
<circle cx="570" cy="400" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#34A853;fill:white"/>
|
||||
<text x="570" y="400" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#34A853">9</text>
|
||||
<circle cx="684" cy="240" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#34A853;fill:white"/>
|
||||
<text x="684" y="240" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#34A853">8</text>
|
||||
<circle cx="912" cy="0" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#34A853;fill:white"/>
|
||||
<text x="912" y="0" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#34A853">2</text>
|
||||
<circle cx="798" cy="160" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#34A853;fill:white"/>
|
||||
<text x="798" y="160" dy="8.88888888888889" style="text-anchor:middle;font-weight:bold;font-size:26.666666666666668;stroke:none;fill:#34A853">6</text>
|
||||
<circle cx="570" cy="160" r="26.666666666666668" style="stroke-width:6.666666666666667;stroke:#34A853;fill:white"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@@ -16,6 +16,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Google.OrTools.ConstraintSolver;
|
||||
using Google.Protobuf.WellKnownTypes; // Duration
|
||||
// [END import]
|
||||
|
||||
/// <summary>
|
||||
@@ -143,6 +144,8 @@ public class VrpCapacity {
|
||||
operations_research_constraint_solver.DefaultRoutingSearchParameters();
|
||||
searchParameters.FirstSolutionStrategy =
|
||||
FirstSolutionStrategy.Types.Value.PathCheapestArc;
|
||||
searchParameters.LocalSearchMetaheuristic = LocalSearchMetaheuristic.Types.Value.GuidedLocalSearch;
|
||||
searchParameters.TimeLimit = new Duration { Seconds = 1 };
|
||||
// [END parameters]
|
||||
|
||||
// Solve the problem.
|
||||
|
||||
@@ -16,10 +16,12 @@ package com.google.ortools.constraintsolver.samples;
|
||||
// [START import]
|
||||
import com.google.ortools.constraintsolver.Assignment;
|
||||
import com.google.ortools.constraintsolver.FirstSolutionStrategy;
|
||||
import com.google.ortools.constraintsolver.LocalSearchMetaheuristic;
|
||||
import com.google.ortools.constraintsolver.RoutingIndexManager;
|
||||
import com.google.ortools.constraintsolver.RoutingModel;
|
||||
import com.google.ortools.constraintsolver.RoutingSearchParameters;
|
||||
import com.google.ortools.constraintsolver.main;
|
||||
import com.google.protobuf.Duration;
|
||||
import java.util.logging.Logger;
|
||||
// [END import]
|
||||
|
||||
@@ -145,6 +147,8 @@ public class VrpCapacity {
|
||||
main.defaultRoutingSearchParameters()
|
||||
.toBuilder()
|
||||
.setFirstSolutionStrategy(FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC)
|
||||
.setLocalSearchMetaheuristic(LocalSearchMetaheuristic.Value.GUIDED_LOCAL_SEARCH)
|
||||
.setTimeLimit(Duration.newBuilder().setSeconds(1).build())
|
||||
.build();
|
||||
// [END parameters]
|
||||
|
||||
|
||||
@@ -186,6 +186,10 @@ def main():
|
||||
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
|
||||
search_parameters.first_solution_strategy = (
|
||||
routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC) # pylint: disable=no-member
|
||||
search_parameters.local_search_metaheuristic = (
|
||||
routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH)
|
||||
search_parameters.time_limit.FromSeconds(1)
|
||||
|
||||
# Solve the problem.
|
||||
assignment = routing.SolveWithParameters(search_parameters)
|
||||
print_solution(data, routing, manager, assignment)
|
||||
|
||||
@@ -161,14 +161,17 @@ void VrpCapacity() {
|
||||
|
||||
// Setting first solution heuristic.
|
||||
// [START parameters]
|
||||
RoutingSearchParameters searchParameters = DefaultRoutingSearchParameters();
|
||||
searchParameters.set_first_solution_strategy(
|
||||
RoutingSearchParameters search_parameters = DefaultRoutingSearchParameters();
|
||||
search_parameters.set_first_solution_strategy(
|
||||
FirstSolutionStrategy::PATH_CHEAPEST_ARC);
|
||||
search_parameters.set_local_search_metaheuristic(
|
||||
LocalSearchMetaheuristic::GUIDED_LOCAL_SEARCH);
|
||||
search_parameters.mutable_time_limit()->set_seconds(1);
|
||||
// [END parameters]
|
||||
|
||||
// Solve the problem.
|
||||
// [START solve]
|
||||
const Assignment* solution = routing.SolveWithParameters(searchParameters);
|
||||
const Assignment* solution = routing.SolveWithParameters(search_parameters);
|
||||
// [END solve]
|
||||
|
||||
// Print solution on console.
|
||||
|
||||
@@ -194,6 +194,9 @@ def main():
|
||||
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
|
||||
search_parameters.first_solution_strategy = (
|
||||
routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
|
||||
search_parameters.local_search_metaheuristic = (
|
||||
routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH)
|
||||
search_parameters.time_limit.FromSeconds(1)
|
||||
# [END parameters]
|
||||
|
||||
# Solve the problem.
|
||||
|
||||
Reference in New Issue
Block a user