From cb3ea25766d1c2335b27fbfa640f0255b36eeb28 Mon Sep 17 00:00:00 2001 From: Mizux Seiha Date: Tue, 18 Aug 2020 17:16:05 +0200 Subject: [PATCH] doc: fix routing_svg.py --- ortools/constraint_solver/doc/routing_svg.py | 21 ++++++---- .../doc/tsp_distance_matrix_solution.svg | 2 +- .../constraint_solver/doc/tsp_solution.svg | 2 +- .../doc/vrp_global_span_solution.svg | 8 ++-- .../doc/vrp_pickup_delivery_fifo_solution.svg | 8 ++-- .../doc/vrp_pickup_delivery_lifo_solution.svg | 40 +++++++++---------- .../doc/vrp_pickup_delivery_solution.svg | 40 +++++++++---------- .../doc/vrp_resources_solution.svg | 8 ++-- .../constraint_solver/doc/vrp_solution.svg | 8 ++-- .../doc/vrp_starts_ends_solution.svg | 8 ++-- .../doc/vrp_time_windows_solution.svg | 8 ++-- 11 files changed, 80 insertions(+), 73 deletions(-) diff --git a/ortools/constraint_solver/doc/routing_svg.py b/ortools/constraint_solver/doc/routing_svg.py index 7e0654f7ab..bb25494f9a 100755 --- a/ortools/constraint_solver/doc/routing_svg.py +++ b/ortools/constraint_solver/doc/routing_svg.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # Copyright 2010-2018 Google LLC # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,10 +18,8 @@ from __future__ import print_function import argparse from ortools.constraint_solver import pywrapcp from ortools.constraint_solver import routing_enums_pb2 - # [END import] - # [START data_model] class DataModel(object): # pylint: disable=too-many-instance-attributes """Stores the data for the problem.""" @@ -540,6 +539,7 @@ class SVGPrinter(object): # pylint: disable=too-many-instance-attributes for node in range(self._routing.Size()): if self._routing.IsStart(node) or self._routing.IsEnd(node): continue + # A node is dropped if its next is itself if self._assignment.Value(self._routing.NextVar(node)) == node: dropped_nodes.append(self._manager.IndexToNode(node)) color = self._color_palette.value_from_name('black') @@ -572,7 +572,7 @@ class SVGPrinter(object): # pylint: disable=too-many-instance-attributes # First print route previous_loc_idx = None for loc_idx in route: - if previous_loc_idx and previous_loc_idx != loc_idx: + if previous_loc_idx != None and previous_loc_idx != loc_idx: self._svg.draw_polyline(self._data.locations[previous_loc_idx], self._data.locations[loc_idx], self._stroke_width, color, colorname) @@ -589,7 +589,7 @@ class SVGPrinter(object): # pylint: disable=too-many-instance-attributes """Draws the routes.""" print(r'') for route_idx, route in enumerate(self.routes()): - print(r''.format(idx=route_idx)) + print(f'') color = self._color_palette.value(route_idx) colorname = self._color_palette.name(route_idx) self.draw_route(route, color, colorname) @@ -835,10 +835,13 @@ def main(): # pylint: disable=too-many-locals,too-many-branches distance_dimension.CumulVar(delivery_index)) if args['fifo']: routing.SetPickupAndDeliveryPolicyOfAllVehicles( - pywrapcp.RoutingModel.FIFO) - if args['lifo']: + pywrapcp.RoutingModel.PICKUP_AND_DELIVERY_FIFO) + elif args['lifo']: routing.SetPickupAndDeliveryPolicyOfAllVehicles( - pywrapcp.RoutingModel.LIFO) + pywrapcp.RoutingModel.PICKUP_AND_DELIVERY_LIFO) + else: + routing.SetPickupAndDeliveryPolicyOfAllVehicles( + pywrapcp.RoutingModel.PICKUP_AND_DELIVERY_NO_ORDER) if args['starts_ends']: dimension_name = 'Distance' @@ -908,6 +911,10 @@ def main(): # pylint: disable=too-many-locals,too-many-branches search_parameters.first_solution_strategy = ( routing_enums_pb2.FirstSolutionStrategy.PARALLEL_CHEAPEST_INSERTION) + search_parameters.local_search_metaheuristic = ( + routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH) + search_parameters.time_limit.FromSeconds(10) + # Solve the problem. assignment = routing.SolveWithParameters(search_parameters) # Print the solution. diff --git a/ortools/constraint_solver/doc/tsp_distance_matrix_solution.svg b/ortools/constraint_solver/doc/tsp_distance_matrix_solution.svg index f68bf820c0..b91a3132d8 100644 --- a/ortools/constraint_solver/doc/tsp_distance_matrix_solution.svg +++ b/ortools/constraint_solver/doc/tsp_distance_matrix_solution.svg @@ -41,7 +41,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - + diff --git a/ortools/constraint_solver/doc/tsp_solution.svg b/ortools/constraint_solver/doc/tsp_solution.svg index f68bf820c0..b91a3132d8 100644 --- a/ortools/constraint_solver/doc/tsp_solution.svg +++ b/ortools/constraint_solver/doc/tsp_solution.svg @@ -41,7 +41,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - + diff --git a/ortools/constraint_solver/doc/vrp_global_span_solution.svg b/ortools/constraint_solver/doc/vrp_global_span_solution.svg index 8fa10ff130..48d29561af 100644 --- a/ortools/constraint_solver/doc/vrp_global_span_solution.svg +++ b/ortools/constraint_solver/doc/vrp_global_span_solution.svg @@ -41,7 +41,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - + @@ -55,7 +55,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 2 5 - + @@ -69,7 +69,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 4 3 - + @@ -83,7 +83,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 16 14 - + diff --git a/ortools/constraint_solver/doc/vrp_pickup_delivery_fifo_solution.svg b/ortools/constraint_solver/doc/vrp_pickup_delivery_fifo_solution.svg index 7e67e6f437..49cc99d79b 100644 --- a/ortools/constraint_solver/doc/vrp_pickup_delivery_fifo_solution.svg +++ b/ortools/constraint_solver/doc/vrp_pickup_delivery_fifo_solution.svg @@ -41,7 +41,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - + @@ -55,7 +55,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 6 9 - + @@ -69,7 +69,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 2 10 - + @@ -83,7 +83,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 13 12 - + diff --git a/ortools/constraint_solver/doc/vrp_pickup_delivery_lifo_solution.svg b/ortools/constraint_solver/doc/vrp_pickup_delivery_lifo_solution.svg index 7ce2c677a9..4a2d2ec6e4 100644 --- a/ortools/constraint_solver/doc/vrp_pickup_delivery_lifo_solution.svg +++ b/ortools/constraint_solver/doc/vrp_pickup_delivery_lifo_solution.svg @@ -41,27 +41,25 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - - - - - + + + + + + +16 + +14 13 - -15 - -11 12 - + - - - + 5 @@ -69,21 +67,23 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 2 10 - -16 - -14 9 - + - + + + 4 3 - + +15 + +11 + diff --git a/ortools/constraint_solver/doc/vrp_pickup_delivery_solution.svg b/ortools/constraint_solver/doc/vrp_pickup_delivery_solution.svg index 7ce2c677a9..4a2d2ec6e4 100644 --- a/ortools/constraint_solver/doc/vrp_pickup_delivery_solution.svg +++ b/ortools/constraint_solver/doc/vrp_pickup_delivery_solution.svg @@ -41,27 +41,25 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - - - - - + + + + + + +16 + +14 13 - -15 - -11 12 - + - - - + 5 @@ -69,21 +67,23 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 2 10 - -16 - -14 9 - + - + + + 4 3 - + +15 + +11 + diff --git a/ortools/constraint_solver/doc/vrp_resources_solution.svg b/ortools/constraint_solver/doc/vrp_resources_solution.svg index 31eb60eb05..9b4cf596a7 100644 --- a/ortools/constraint_solver/doc/vrp_resources_solution.svg +++ b/ortools/constraint_solver/doc/vrp_resources_solution.svg @@ -41,7 +41,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - + @@ -52,7 +52,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 14 16 - + @@ -66,7 +66,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 15 11 - + @@ -80,7 +80,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 4 3 - + diff --git a/ortools/constraint_solver/doc/vrp_solution.svg b/ortools/constraint_solver/doc/vrp_solution.svg index c02a81fb9e..0450e2477b 100644 --- a/ortools/constraint_solver/doc/vrp_solution.svg +++ b/ortools/constraint_solver/doc/vrp_solution.svg @@ -41,10 +41,10 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - - - - + + + + diff --git a/ortools/constraint_solver/doc/vrp_starts_ends_solution.svg b/ortools/constraint_solver/doc/vrp_starts_ends_solution.svg index 31223c03ce..4806136ca4 100644 --- a/ortools/constraint_solver/doc/vrp_starts_ends_solution.svg +++ b/ortools/constraint_solver/doc/vrp_starts_ends_solution.svg @@ -41,7 +41,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - + @@ -54,7 +54,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 3 7 - + @@ -67,7 +67,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 8 5 - + @@ -80,7 +80,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 12 13 - + diff --git a/ortools/constraint_solver/doc/vrp_time_windows_solution.svg b/ortools/constraint_solver/doc/vrp_time_windows_solution.svg index c211dd8542..362fbb1056 100644 --- a/ortools/constraint_solver/doc/vrp_time_windows_solution.svg +++ b/ortools/constraint_solver/doc/vrp_time_windows_solution.svg @@ -41,7 +41,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 - + @@ -52,7 +52,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 14 16 - + @@ -66,7 +66,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 3 1 - + @@ -80,7 +80,7 @@ width="1022.6666666666666" height="750.6666666666666" viewBox="-55.3333333333333 15 11 - +