python: fixup examples

This commit is contained in:
Corentin Le Molgat
2024-06-24 15:42:49 +02:00
parent 06aea80bf6
commit 7e8fef2003
4 changed files with 15 additions and 15 deletions

View File

@@ -14,7 +14,7 @@
"""Simple prize collecting TSP problem with a max distance."""
from ortools.routing import enums_pb2
from ortools.constraint_solver import pywrapcp
from ortools.routing import pywraprouting
DISTANCE_MATRIX = [
[0, 10938, 4542, 2835, 29441, 2171, 1611, 9208, 9528, 11111, 16120, 22606, 22127, 20627, 21246, 23387, 16697, 33609, 26184, 24772, 22644, 20655, 30492, 23296, 32979, 18141, 19248, 17129, 17192, 15645, 12658, 11210, 12094, 13175, 18162, 4968, 12308, 10084, 13026, 15056],
@@ -106,13 +106,13 @@ def main():
all_nodes = range(num_nodes)
# Create the routing index manager.
manager = pywrapcp.RoutingIndexManager(
manager = pywraprouting.RoutingIndexManager(
num_nodes,
num_vehicles,
depot)
# Create routing model.
routing = pywrapcp.RoutingModel(manager)
routing = pywraprouting.RoutingModel(manager)
# Create and register a transit callback.
def distance_callback(from_index, to_index):
@@ -145,7 +145,7 @@ def main():
VISIT_VALUES[node])
# Setting first solution heuristic.
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
search_parameters = pywraprouting.DefaultRoutingSearchParameters()
search_parameters.first_solution_strategy = (
enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
search_parameters.local_search_metaheuristic = (

View File

@@ -14,7 +14,7 @@
"""Simple prize collecting VRP problem with a max distance."""
from ortools.routing import enums_pb2
from ortools.constraint_solver import pywrapcp
from ortools.routing import pywraprouting
DISTANCE_MATRIX = [
[0, 10938, 4542, 2835, 29441, 2171, 1611, 9208, 9528, 11111, 16120, 22606, 22127, 20627, 21246, 23387, 16697, 33609, 26184, 24772, 22644, 20655, 30492, 23296, 32979, 18141, 19248, 17129, 17192, 15645, 12658, 11210, 12094, 13175, 18162, 4968, 12308, 10084, 13026, 15056],
@@ -112,13 +112,13 @@ def main():
all_nodes = range(num_nodes)
# Create the routing index manager.
manager = pywrapcp.RoutingIndexManager(
manager = pywraprouting.RoutingIndexManager(
num_nodes,
num_vehicles,
depot)
# Create routing model.
routing = pywrapcp.RoutingModel(manager)
routing = pywraprouting.RoutingModel(manager)
# Create and register a transit callback.
def distance_callback(from_index, to_index):
@@ -151,7 +151,7 @@ def main():
VISIT_VALUES[node])
# Setting first solution heuristic.
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
search_parameters = pywraprouting.DefaultRoutingSearchParameters()
search_parameters.first_solution_strategy = (
enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
search_parameters.local_search_metaheuristic = (

View File

@@ -27,7 +27,7 @@ from functools import partial
import random
from ortools.routing import enums_pb2
from ortools.constraint_solver import pywrapcp
from ortools.routing import pywraprouting
parser = argparse.ArgumentParser()
@@ -91,9 +91,9 @@ def main(args):
# Second argument = 1 to build a single tour (it's a TSP).
# Nodes are indexed from 0 to args_tsp_size - 1, by default the start of
# the route is node 0.
manager = pywrapcp.RoutingIndexManager(args.tsp_size, 1, 0)
routing = pywrapcp.RoutingModel(manager)
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
manager = pywraprouting.RoutingIndexManager(args.tsp_size, 1, 0)
routing = pywraprouting.RoutingModel(manager)
search_parameters = pywraprouting.DefaultRoutingSearchParameters()
# Setting first solution heuristic (cheapest addition).
search_parameters.first_solution_strategy = (
enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
from collections import namedtuple
from ortools.constraint_solver import pywrapcp
from ortools.routing import pywraprouting
VEHICLE_COUNT = 30
VEHICLE_CAPACITY = 200
@@ -14,8 +14,8 @@ customers.append(Customer(1, 1, 1.0, 1.0))
customers.append(Customer(1, 1, 2.0, 2.0))
customer_count = len(customers)
manager = pywrapcp.RoutingIndexManager(3, VEHICLE_COUNT, 0)
routing = pywrapcp.RoutingModel(manager)
manager = pywraprouting.RoutingIndexManager(3, VEHICLE_COUNT, 0)
routing = pywraprouting.RoutingModel(manager)
print('Demand Constraint')
demands = []