cuOpt Self-Hosted Thin Client API Example

 1import os
 2from cuopt_sh_client import CuOptServiceSelfHostClient
 3
 4data = {"cost_matrix_data": {"data": {"0": [[0,1],[1,0]]}},
 5        "task_data": {"task_locations": [0,1]},
 6        "fleet_data": {"vehicle_locations": [[0,0],[0,0]]}}
 7
 8# If cuOpt is not running on localhost:5000, edit ip and port parameters
 9cuopt_service_client = CuOptServiceSelfHostClient(
10    ip="localhost",
11    port=5000
12)
13
14optimized_routes = cuopt_service_client.get_optimized_routes(data)
15print(optimized_routes)

The data argument to get_optimized_routes may be a dictionary of the format show in Get Routes Open-API spec. It may also be the path of a file containing such a dictionary as JSON or written using the Python pickle module. A JSON file may optionally be compressed with zlib.

cuOpt Self-Hosted Thin Client CLI Example

Create a data.json file containing this sample data:

{"cost_matrix_data": {"data": {"0": [[0, 1], [1, 0]]}},
 "task_data": {"task_locations": [0, 1]},
 "fleet_data": {"vehicle_locations": [[0, 0], [0, 0]]}}

Invoke the CLI

# client's default ip address for cuOpt is localhost:5000 if ip/port are not specified
cuopt_sh data.json -i ip -p port