Quickstart Guide#
NVIDIA cuOpt provides a Python API for routing optimization and LP/QP/MILP that enables users to solve complex optimization problems efficiently.
Installation#
Choose your install method below; the selector is pre-set for the Python API. Copy the command and run it in your environment. See Installation for all interfaces and options.
NVIDIA Launchable#
NVIDIA cuOpt can be tested with NVIDIA Launchable with example notebooks. For more details, please refer to the NVIDIA Launchable documentation.
Smoke Test#
After installation, you can verify that NVIDIA cuOpt is working correctly by running a simple test.
Copy and paste this script directly into your terminal (smoke_test_example.sh):
1python -c '
2import cudf
3from cuopt import routing
4
5# Create cost matrix (symmetric distance matrix for 4 locations)
6cost_matrix = cudf.DataFrame(
7 [[0, 2, 2, 2],
8 [2, 0, 2, 2],
9 [2, 2, 0, 2],
10 [2, 2, 2, 0]],
11 dtype="float32"
12)
13
14# Task locations (indices into the cost matrix)
15# Tasks at locations 1, 2, and 3
16task_locations = cudf.Series([1, 2, 3])
17
18# Number of vehicles
19n_vehicles = 2
20
21# Create data model
22dm = routing.DataModel(
23 cost_matrix.shape[0], n_vehicles, len(task_locations)
24)
25dm.add_cost_matrix(cost_matrix)
26dm.add_transit_time_matrix(cost_matrix.copy(deep=True))
27
28# Configure solver settings
29ss = routing.SolverSettings()
30
31# Solve the routing problem
32sol = routing.Solve(dm, ss)
33
34# Display results
35print(sol.get_route())
36print("\n\n****************** Display Routes *************************")
37sol.display_routes()
38'
Example Response:
route arrival_stamp truck_id location type
0 0.0 0 0 Depot
2 2.0 0 2 Delivery
1 4.0 0 1 Delivery
0 6.0 0 0 Depot
****************** Display Routes *************************
Vehicle-0 starts at: 0.0, completes at: 6.0, travel time: 6.0, Route :
0(Dpt)->2(D)->1(D)->0(Dpt)
This results in a travel time of 6.0 to deliver all routes