OR Optimization Modeling Skill: Agent-Driven Closed-Loop Gurobi Modeling

Introduction

When working on linear programming, mixed-integer programming, or scheduling problems, the difficulty often lies not in “knowing how to write gurobipy,” but in ensuring consistency from business descriptions to variables, constraints, and the objective, as well as in verifying results after solving. Hand-written scripts easily require back-and-forth edits between data definitions and model structure; having a large model generate code in one pass can introduce unstated coefficients or skip feasibility checks.

Below is an introduction to the community Skill on SkillHub, the “Operations Research Optimization Modeling Skill” (coordinate @user_ff97f32a/gurobi-optimization-skill, version 1.0.0). It uses a generic SKILL.md to define the Agent’s execution order and comes with Python tools and example data, stringing together “problem understanding → modeling → code → solving and validation” into a repeatable workflow. The SkillHub page indicates requires_api_key=false; installing this Skill itself does not require an additional API Key. Actual solving still depends on your local Python environment and solver licenses such as Gurobi.

What Is This

Operations Research Optimization Modeling Skill is a developer-facing Agent Skill maintained by the community publisher user_ff97f32a, categorized under dev-programming, and sourced from community. Official entry points:

  • API / installation resolution: https://api.skillhub.cn/user_ff97f32a/gurobi-optimization-skill
  • SkillHub display page: https://www.skillhub.cn/skills/user_ff97f32a/gurobi-optimization-skill

The Skill’s self-description positions it as a full-process optimization modeling workflow based on Gurobi + Python, covering problem analysis, mathematical modeling, code generation, solving and validation, result analysis, and iterative optimization. Trigger phrases include “optimization model,” “linear programming,” “integer programming,” “Gurobi,” “solver,” “constraints,” “objective function,” etc. When a user clearly intends to modify constraints or objectives on an existing model, the documentation requires following an iterative path rather than starting over.

Core Features

The following content is derived from the installed package’s SKILL.md and directory structure (skillhub install pulls version 1.0.0).

Stepwise Prompts and Workflow

The Skill stipulates that the Agent reads the instruction files under prompts/ in order. The current package includes:

File Purpose
prompts/problem_intake.md Problem understanding: objectives, variables, constraints, data sources
prompts/model_formulation.md Mathematical modeling
prompts/code_generation.md Generate Gurobi Python code
prompts/iteration_context.md Context and intent in iteration scenarios

SKILL.md also describes a more complete seven-step workflow (including data analysis, solving and validation, result analysis, and filenames such as data_analysis.md). If the corresponding prompts files are not yet present in your local package, the actual directory prevails; the Agent should still comply with the mandatory rules in the documentation (see below).

Mandatory Modeling Rules

The Skill imposes hard constraints on data and code, suitable for scenarios requiring auditable models:

  1. Business numerical values must come from files provided by the user or data explicitly given in conversation; the Agent is forbidden from fabricating or filling defaults.
  2. Each parameter must be traceable to a file field or the user’s original statement; when missing, a to-be-collected data list must be provided.
  3. Model code must not hard-code business data such as costs, demands, or capacities; only mathematical constants such as big-M or step size are allowed.
  4. If the user requests running through with example data first, mark it as an example in comments and remind to replace.

Supporting Tools (tools/)

Tool Function
env_check.py Check Python (requires 3.9+), Gurobi license, and dependencies
refman_search.py Search the Gurobi Python API reference by keyword (classes, parameters, error codes, etc.)
data_loader.py Unified loading of .csv / .xlsx / .json / .dat
data_validator.py Validate required fields before modeling
model_validator.py Post-solve check of the reasonableness of the result JSON
solver_factory.py List or switch solvers (documentation supports gurobi, ortools, pulp_cbc, scip, etc.)
log_analyzer.py Parse Gurobi solver logs
result_visualizer.py Visualize results
update_references.py Maintain built-in API reference data

Dependencies are listed in the package’s requirements.txt: core includes gurobipy>=11.0, pandas>=1.5; optional dependencies include openpyxl, matplotlib, seaborn, numpy.

Problem Types and Solvers

The documentation lists LP, MILP, QP, MIQP, QCQP, SOCP, NLP (Gurobi 11+), multi-objective, and other types along with their modeling approaches. It also explains that when a Gurobi license is unavailable, open-source alternatives such as SCIP, OR-Tools, or PuLP/CBC can be attempted via solver_factory.py.

Examples and Templates

Under examples/, multiple modeling examples and datasets are provided (the README notes that some derive from Gurobi/modeling-examples), for example:

  • production_distribution (LP, minimum-cost production and distribution)
  • power_generation, portfolio_optimization, facility_location
  • railway_dispatching, supply_chain_food, technician_routing, traveling_salesman

The templates/ directory currently contains production_scheduling.py, a production scheduling template; by default, generated artifacts are recommended to be written to outputs/{problem_name}/model.py and then executed for solving.

Installation and Activation

See the official SkillHub installation instructions at https://skillhub.cn/install/skillhub.md. Key points:

1. Install SkillHub CLI (if not already installed)

command -v skillhub && skillhub --version

If not installed, you can run (full installation includes default Skills):

curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash

2. Install this Skill into the current Agent’s skills directory

You must use --dir to point to the skills path actually recognized by the Agent; otherwise the default ./skills/ may not be loaded.

skillhub install @user_ff97f32a/gurobi-optimization-skill --dir <your skills directory>

Common paths (from SkillHub installation docs):

  • Cursor: ~/.cursor/skills/
  • Claude Code: ~/.claude/skills/
  • Codex: ~/.codex/skills/ or .agents/skills/ within a project

Alternatively, send the prompt from the SkillHub page to an AI: “Please install @user_ff97f32a/gurobi-optimization-skill according to https://skillhub.cn/install/skillhub.md.”

3. Python dependencies and Gurobi

Install dependencies in the Skill directory or your project environment:

pip install -r requirements.txt

Gurobi requires separate installation of gurobipy and license configuration (academic free license, etc., following Gurobi’s official process). After installation, you can use the Skill’s built-in check:

python3 "${SKILL_DIR}/tools/env_check.py"

Replace ${SKILL_DIR} with the installed Skill root directory, e.g., ~/.cursor/skills/@user_ff97f32a/gurobi-optimization-skill.

Once activated, mentioning optimization modeling needs in conversations within clients such as Cursor will trigger it; whether the Skill auto-loads depends on the client’s Skills mechanism, with a correct installation path as a prerequisite.

Typical Usage

Below is a reproducible data-loading approach consistent with the official example, along with the tool invocation order recommended by the Skill documentation.

Example: Production and Distribution LP

examples/production_distribution describes minimum-cost transportation from plants to distribution centers (LP), with data file data/cost.csv. Per the README, load data first:

import pandas as pd
data = pd.read_csv("data/cost.csv")

In an Agent session, a common practice is: state the optimization objective and constraints, provide the path to cost.csv, let the Skill follow problem_intake.md → model_formulation.md → code_generation.md to generate outputs/{problem_name}/model.py, then execute:

python3 outputs/{problem_name}/model.py

Validate data fields before modeling (replace field names to match your file):

python3 "${SKILL_DIR}/tools/data_validator.py" --data data/cost.csv --required "Field1,Field2"

If the solve outputs results.json, run:

python3 "${SKILL_DIR}/tools/model_validator.py" --results results.json

When you need to look up API syntax:

python3 "${SKILL_DIR}/tools/refman_search.py" addVar

Without a Gurobi license, you can first list available local backends:

python3 "${SKILL_DIR}/tools/solver_factory.py" --list

Iterative Modifications

When the user changes constraints, objectives, or variables on an existing model or previous output, the Skill requires reading iteration_context.md, saving the new version as {problem_name}_{YYYYMMDDHHmmss}.py with a timestamp, not overwriting old files, and maintaining an optimization-iteration-log.md in the project directory. SKILL.md also references parameter_tuning.md and model_revision.md; if these files are not present in your installed package, use iteration_context.md and the current model code as the basis for iterations.

Applicable Scenarios and Notes

Who it’s for

  • Teams needing to build LP/MILP/QP and other models with Gurobi (or open-source MIP solvers) and wanting the Agent to adhere to “data traceability, no fabricated coefficients” norms.
  • Users who want to encapsulate environment checks, data validation, solver switching, and result validation into fixed commands, reducing repeated script writing from scratch.
  • Users wanting to quickly align with example data structures based on Gurobi’s official modeling-examples problems.

Limitations and Caveats

  • Solve quality and speed depend on local licenses and problem scale; commercial Gurobi licenses must be obtained independently; the Skill does not manage licensing.
  • The complete seven-step prompt mapping and some template filenames in SKILL.md may not fully match the files in the current zip package; refer to the directory after skillhub install.
  • SkillHub crawled statistics (at time of writing): rating 100000, downloads 1282, install count 0; page data will change, subject to SkillHub.
  • The log analysis tool documentation notes a dependency on gurobi-logtools; related features may be unavailable if not installed.

Conclusion

The Operations Research Optimization Modeling Skill packages Gurobi modeling procedures, data discipline, and validation scripts into an Agent Skill, suitable for repeatable optimization delivery in environments that support Skills, such as Cursor and Claude Code. Installation and details are on SkillHub: https://www.skillhub.cn/skills/user_ff97f32a/gurobi-optimization-skill, coordinate @user_ff97f32a/gurobi-optimization-skill, version 1.0.0.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye