generic-max-supply

작성자: nvidia

Multi-period supply chain planning model: data files, BOM structure, variable/constraint reference for the max-supply base model.

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
Use when something is wrong: Search() hangs, all evaluations return INVALID_SCORE, scores aren't improving, every config returns the same number, ptxas errors…
official
create-github-pr
nvidia
gh CLI를 사용하여 GitHub 풀 리퀘스트를 생성합니다. 사용자가 새 PR을 만들거나, 코드 리뷰를 제출하거나, 풀 리퀘스트를 열고자 할 때 사용합니다. 트리거 키워드 -…
official
diagnose-perf
nvidia
First-responder performance triage for Isaac Sim and Isaac Lab. Identifies bottleneck category (GPU-bound, CPU-bound, VRAM, loading) using nvidia-smi and…
official
eagle3-review-logs
nvidia
Review EAGLE3 pipeline experiment logs from the launcher's experiments/ directory. Summarizes pass/fail status for all 4 tasks, diagnoses failures with root…
official
nemoclaw-maintainer-cross-issue-sweep
nvidia
다른 열린 이슈들을 스캔하여 주어진 PR이 함께 수정하거나 실수로 망가뜨릴 수 있는 이슈를 찾습니다. 인접 수정 기회와 모순 위험을 file:line…과 함께 출력합니다.
official
karpathy-guidelines
nvidia
일반적인 LLM 코딩 실수를 줄이기 위한 행동 지침입니다. 코드 작성, 검토 또는 리팩토링 시 과도한 복잡성을 피하고 정밀한 변경을 위해 사용하세요.
official
fhir-basics
nvidia
에이전트에게 FHIR R4 API의 작동 방식, 사용 가능한 리소스, 검색 매개변수를 사용한 쿼리 방법, 모든 응답 형식을 올바르게 파싱하는 방법을 가르칩니다…
official
underdeclared-agent
nvidia
A helpful assistant agent
official