generic-max-supply

작성자: nvidia

다기간 공급망 계획 모델: 데이터 파일, BOM 구조, 최대 공급 기본 모델의 변수/제약 조건 참조.

npx skills add https://github.com/nvidia/cuopt-examples --skill generic-max-supply

Generic Max-Supply Planning

Core

  • Execution order (mandatory): read scripts/model.py first, then decide relevant CSV files from the prompt, then read only those CSVs, then run baseline model.py, then copy to model_whatif.py, apply a targeted edit, and run model_whatif.py.
  • Source data and reference model: scripts/ for Python (data.py, model.py); scripts/data/ for CSV inputs. load_data(data_dir, num_periods) reads from that data directory; optional cost/backlog files are read separately if needed.

Workspace layout

LocationContents
scripts/Python: data.py (load_data), model.py (build/solve). Run from repository root (or your run directory) with python scripts/model.py.
scripts/data/Required and optional CSV files (items, families, processes, supply, demand, etc.). All files from the data file map live here.

Using in the working directory

Do not modify the skill files. To run or change the model: (1) Copy skills/generic-max-supply/scripts/ into your run directory. (2) Edit only the copy. (3) Run from that run directory or repository root. Do not assume a fixed sandbox cwd.

cp -r skills/generic-max-supply/scripts . && python3 scripts/model.py

(From repository root, this copies skills/generic-max-supply/scripts/ to ./scripts/.)

What-If Variants

To run a what-if scenario (e.g. change opening inventory, tighten a supply cap, modify a cost):

  1. Read model.py first (required), identify which model block changes, and infer which CSV files are relevant to the requested change.

  2. Read only relevant CSV files for the prompt. Do not read all CSVs unless explicitly requested.

  3. Copy the scripts to the working directory and fix the data path:

    cp skills/generic-max-supply/scripts/data.py data.py
    cp skills/generic-max-supply/scripts/model.py model.py
    

    Then update DATA_DIR in the copied model.py to match your CSV location.

  4. Run baseline first and capture base objective:

    python model.py
    
  5. Fork the working model:

    cp model.py model_whatif.py
    
  6. Use edit_file to make only the targeted change in model_whatif.py.

  7. Run the what-if model and compare against baseline:

    python model_whatif.py   # ← this is the what-if result
    

Do not rewrite the model from scratch. One targeted edit keeps the change isolated and the comparison meaningful.

Problem overview

Type: MILP (Mixed-Integer Linear Program) Sense: MAXIMIZE Horizon: configurable num_periods (default 10)

The planner decides how many units of each manufacturing process to run on each resource in each period. The goal is to maximise the weighted sum of finished-good inventory at the end of the last period. Constraints capture multi-level BOM structure, lead-time offsets, integer yield truncation, material supply caps, and machine-hour capacity.

Data file map

All files live in the same directory (scripts/data/). load_data(data_dir, num_periods) reads all required CSVs from that directory; the three optional cost/backlog files are read separately if needed.

FileKey columnsWhat it populates
items.csvitem_id, name, family_idall_items, item_family lookup
families.csvfamily_id, name, is_constrainedconstrained_families, unconstrained_families
processes.csvprocess_id, name, lead_time, hours_per_unitall_processes, process_lead_time, process_hours
process_inputs.csvprocess_id, item_id, quantityprocess_input_qty[(p,i)], item_consuming_processes
process_outputs.csvprocess_id, item_id, quantityprocess_output_qty[(p,i)], item_producing_processes, derives produced_items
process_resources.csvprocess_id, resource_idprocess_resource_pairs, process_to_resources, resource_to_processes
resources.csvresource_id, name, period, available_hoursall_resources, resource_capacity[(r,t)]
supply.csvitem_id, period, quantitysupply_qty[(i,t)] — upper bound on procurement per period
demand.csvitem_id, period, quantity, priority_weightfinal_items, demand_weight[i] (only priority_weight is used in the base model)

Optional files — NOT loaded by data.py; read separately if needed:

FileKey columnsPurpose
item_costs.csvitem_id, unit_cost, holding_costPer-unit purchase cot and per-period holding cost
resource_costs.csvresource_id, production_cost_per_hourCost per machine-hour by resource
backlog_params.csvparameter, valueSingle row: backlog_cost_rate

Key sets and derivation

produced_items      = set(process_outputs_df["item_id"])
procured_items      = all_items - produced_items
final_items         = set(demand_df["item_id"])

constrained_families   = {f where is_constrained == True}
unconstrained_families = {f where is_constrained == False}

# A process is constrained if ANY of its output items is in a constrained family.
process_is_constrained[p] = any(
    item_family[i] in constrained_families
    for i in outputs_of(p)
)

In the sample dataset: FAM_FG, FAM_SA, FAM_RM1 are constrained; FAM_RM2 is not. RM3 (family FAM_RM2) is procured but unconstrained — no supply cap applied. All four processes (PROC1PROC4) are constrained because they produce items in constrained families.

Variable reference

VariableRepresentsDomainInitialisation
x[p, r, t]Units of process p executed on resource r starting in period tContinuous ≥ 0addVariable(lb=0, vtype=CONTINUOUS)
produced[i, t]Continuous (possibly fractional) output of item i in period tContinuous ≥ 0addVariable(lb=0, vtype=CONTINUOUS)
used[i, t]Usable (floor-truncated) integer output of item i in period tInteger ≥ 0addVariable(lb=0, vtype=INTEGER)
buy[i, t]Units of procured item i purchased in period tContinuous ≥ 0addVariable(lb=0, vtype=CONTINUOUS)
inventory[i, t]On-hand inventory of item i at end of period tContinuous ≥ 0addVariable(lb=0, vtype=CONTINUOUS)
inventory[i, 0]Opening balance (fixed to zero)Continuous, lb=ub=0addVariable(lb=0, ub=0, vtype=CONTINUOUS)

inventory[i, 0] is a fixed variable (lb = ub = 0). For a non-zero opening balance, set ub = lb = opening_balance.

Constraint map

LabelName patternWhat it enforcesVariables linked
C1prod_def_{i}_{t}produced[i,t] equals the sum of BOM-output quantities from all processes that started at t − lead_timeproduced, x
C2atrunc_upper_{i}_{t}used[i,t] ≤ produced[i,t] (integer cannot exceed real output)used, produced
C2btrunc_lower_{i}_{t}used[i,t] ≥ produced[i,t] − (1 − ε) with ε = 1e-4 (forces integer to be the floor)used, produced
C3abal_proc_{i}_{t}Material balance for procured items: inv[i,t] = inv[i,t−1] + buy[i,t] − consumptioninventory, buy, x
C3bbal_prod_{i}_{t}Material balance for produced items: inv[i,t] = inv[i,t−1] + used[i,t] − consumptioninventory, used, x
C4supply_{i}_{t}buy[i,t] ≤ supply_qty[(i,t)] — only applied to procured items in constrained familiesbuy
C5cap_{r}_{t}Σ hours_per_unit[p] · x[p,r,t] ≤ capacity[(r,t)] — only processes where process_is_constrained[p] is Truex

Lead-time note: C1 uses start_t = t − lead_time[p]. If start_t < 1, the term is skipped (process cannot have started before period 1).

Objective

last_t = max(data.periods)
obj = Σ  demand_weight[i] * inventory[i, last_t]   for i in final_items

Maximise the priority-weighted inventory of finished goods at the end of the planning horizon. demand_weight comes from the priority_weight column in demand.csv (the quantity column in demand.csv is present but not used by the base model).

Solver settings (default)

settings = SolverSettings()
settings.set_parameter("mip_relative_gap", 0.01)
prob.solve(settings)

mip_relative_gap = 0.01 (1% gap). Do not change solver precision (e.g. do not tighten to 0.1% or 0.0); use this default only.

Sanity-checking results

After solving, verify the model is correct:

  1. Check model size changed when you add items/constraints. The solver log prints Solving a problem with N constraints, M variables. If you added a new item or constraint but N and M are unchanged, your data edits did not take effect — check that you edited the CSV files in the working directory.
  2. Check item count in the Loading data... output matches your expectation (e.g., adding RM4 should increase the item count by 1).
  3. Check objective value actually changed meaningfully. Differences smaller than the MIP gap (~1%) may just be solver noise, not real model changes.

Quick links by task

TaskUse
Implement or extend the base modelData file map, key sets, variable reference, constraint map, objective.
Load or modify input dataData file map; optional files read separately.
Tune or run the solverSolver settings (default); data in scripts/data/ by default.
Verify results after changesSanity-checking results.

nvidia의 다른 스킬

compileiq-debug
nvidia
무언가 잘못되었을 때 사용: Search()가 멈추거나, 모든 평가가 INVALID_SCORE를 반환하거나, 점수가 개선되지 않거나, 모든 설정이 동일한 숫자를 반환하거나, ptxas 오류 등이 발생할 때
create-github-pr
nvidia
gh CLI를 사용하여 GitHub 풀 리퀘스트를 생성합니다. 사용자가 새 PR을 만들거나, 코드 리뷰를 제출하거나, 풀 리퀘스트를 열고자 할 때 사용합니다. 트리거 키워드 -…
nemoclaw-maintainer-cross-issue-sweep
nvidia
다른 열린 이슈들을 스캔하여 주어진 PR이 함께 수정하거나 실수로 망가뜨릴 수 있는 이슈를 찾습니다. 인접 수정 기회와 모순 위험을 file:line…과 함께 출력합니다.
fhir-basics
nvidia
에이전트에게 FHIR R4 API의 작동 방식, 사용 가능한 리소스, 검색 매개변수를 사용한 쿼리 방법, 모든 응답 형식을 올바르게 파싱하는 방법을 가르칩니다…
compileiq-validate-result
nvidia
검색이 완료된 후, 속도 향상을 청구하거나 ACF를 발송하기 전에 사용합니다. dump_results CSV를 로드하고, 상위 K개 후보(단일 목표)를 추출합니다…
changelog-audit
nvidia
릴리스 전에 Warp CHANGELOG.md를 감사합니다: 누락된 항목 복구, 사용자 영향별 정렬, 항목 언어 다듬기, 줄 바꿈, (릴리스 브랜치 모드) 비교 업데이트…
maintain-dynamic-plugins
nvidia
NeMo Relay 동적 플러그인 로더, 매니페스트, Rust 네이티브 SDK, gRPC 워커 프로토콜, Python 워커 SDK, 문서, 테스트 및 릴리스 워크플로 커버리지를 유지 관리합니다.
dgx-diagnose
nvidia
일반적인 DGX Station GB300 문제 진단 — CUDA 충돌, 잘못된 GPU 타겟팅, vLLM/SGLang 컨테이너 버그, MIG 상태 문제, NVLink/Fabric Manager 오류,…