mcpField
C
cuopt-routing-api-python

cuopt-routing-api-python

github.com/promptingcompanyデータ・データベース039 回インストール17 週間前に更新
リポジトリ

cuopt-routing-api-python について

TSP、VRP、PDP などの cuOpt ルーティング問題を構築・求解する Python 専用スキルです。モデルデータ、制約、ソルバー設定、解の確認、一般的な問題の調査を扱います。

主な機能

  1. 01TSP、VRP、PDP のモデリング
  2. 02時間枠と容量の制約
  3. 03ルートと目的値の取得
  4. 04求解状態と実行不可能な注文の確認
  5. 05明示的なデータ型指定

活用シーン

  1. 01時間枠付きの車両経路モデルを作る
  2. 02車両容量を考慮して配送注文をモデル化する
  3. 03求解失敗後に実行不可能な注文を調べる
  4. 04ルートコストと求解状態を確認する

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/promptingcompany/nv-skills --skill cuopt-routing-api-python

インストール後、Claude Code で/cuopt-routing-api-pythonを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

BENCHMARK.md
skill-card.md
skill.oms.sig
assets/
README.md
assets/pdp_basic/
model.py
README.md
assets/vrp_basic/
model.py
README.md
evals/
evals.json
references/
examples.md
server_examples.md

詳細

cuOpt ルーティング — Python API

コーディングを始める前に、問題の種類(TSP、VRP、PDP)とデータ(場所、注文、車両、制約)を確認してください。

このスキルはPython 専用です。cuOpt のルーティングには C API がありません。

最小限の VRP の例

import cudf
from cuopt import routing

cost_matrix = cudf.DataFrame([...], dtype="float32")
dm = routing.DataModel(n_locations=4, n_fleet=2, n_orders=3)
dm.add_cost_matrix(cost_matrix)
dm.set_order_locations(cudf.Series([1, 2, 3], dtype="int32"))
solution = routing.Solve(dm, routing.SolverSettings())

if solution.get_status() == 0:
    solution.display_routes()

制約の追加

# Time windows
dm.add_transit_time_matrix(transit_time_matrix)
dm.set_order_time_windows(earliest_series, latest_series)

# Capacities
dm.add_capacity_dimension("weight", demand_series, capacity_series)
dm.set_order_service_times(service_times)
dm.set_vehicle_locations(start_locations, end_locations)
dm.set_vehicle_time_windows(earliest_start, latest_return)

# Pickup-delivery pairs
dm.set_pickup_delivery_pairs(pickup_indices, delivery_indices)

# Precedence
dm.add_order_precedence(node_id=2, preceding_nodes=np.array([0, 1]))

解の確認

status = solution.get_status()  # 0=SUCCESS, 1=FAIL, 2=TIMEOUT, 3=EMPTY
if status == 0:
    route_df = solution.get_route()
    total_cost = solution.get_total_objective()
else:
    print(solution.get_error_message())
    print(solution.get_infeasible_orders().to_list())

データ型(明示的な dtype を使用)

cost_matrix = cost_matrix.astype("float32")
order_locations = cudf.Series([...], dtype="int32")
demand = cudf.Series([...], dtype="int32")

ソルバーの設定

ss = routing.SolverSettings()
ss.set_time_limit(30)
ss.set_verbose_mode(True)
ss.set_error_logging_mode(True)

よくある問題

問題解決方法
解が空時間枠を広げるか、移動時間を確認してください
注文を実行できない車両台数または積載量を増やしてください
時間枠がある場合にステータスが 0 以外add_transit_time_matrix() を追加してください
コストが誤っているcost_matrix が対称か確認してください
compute_waypoint_sequence が route_df を変更するlocation 列が waypoint ID にその場で置き換えられます。コスト行列のインデックスが引き続き必要な場合(例:トラックごとに反復処理する場合)は、route_df.copy() を渡してください

デバッグ

ステータスが 0 以外の場合: print(solution.get_error_message()) と print(solution.get_infeasible_orders().to_list()) を実行して、実行できない注文を確認してください。

データ型: サイレントエラーを避けるため、行列とシリーズには明示的な dtype(float32、int32)を使用してください。

例

エスカレーション

コントリビューションまたはソースからのビルドについては、開発者向けスキルを参照してください。

コメント