copt-linear-program

A tool for turning linear programming problems into mathematical models and solving them with Cardinal Optimizer, a software package for optimization. It can start from a word problem or from supplied matrices and JSON data.

In plain words
What is it for?
Use it to model and solve problems that maximize or minimize a linear goal, such as allocating resources under limits. It reports the best goal value and the values of the variables.
Why use it?
It removes the need to manually translate a written problem into variables, goals, and constraints before solving it. It also helps check that matrix dimensions and constraint data match.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/verymath/ai4math-optimization/copt-linear-program
Any agent
npx skills add VeryMath/AI4Math-Optimization --skill copt-linear-program
Clone the repo
git clone --depth 1 https://github.com/VeryMath/AI4Math-Optimization

Made for: Claude Code, Codex.

Per session 90 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,869 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00090 $0.02869
Opus 5 $0.00045 $0.01435
Sonnet 5 $0.00018 $0.00574
Haiku 4.5 $0.00009 $0.00287

Measured yesterday against content hash 1337f4ee7ad4, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

copt-linear-program scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/solve_lp.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/copt-linear-program/SKILL.md · 209 lines

How it starts

The opening of the file, as written. The whole thing — 209 lines — stays where its author put it; the contents beside it link to each section on GitHub.

用 COPT 求解线性规划(Linear Program, LP)

适用场景

  • 线性目标:minmaxc^T x
  • 线性约束:A_ub x <= b_ubA_eq x == b_eq(可只用其中一类或组合)
  • 变量界:每个 x_j 可有下界、上界(或无界)

输入:可以是自然语言/应用题,也可以是已给定的系数矩阵或 JSON。不要默认要求用户先整理成矩阵;仅在用户已提供矩阵或完成符号化后,再用 JSON 字段复现或调用 solve_lp

Quick Start(先做这个)

按下面清单执行并在回答中保留结构:

  • 路径判断:用户给的是自然语言,还是已给矩阵/JSON
  • 输出重述(1-2 句)
  • 请用户确认重述是否正确(若有问题则澄清,无误则继续)
  • 列变量/目标/约束(符号化)
  • 需要时提关键澄清问题,或明确写出假设
  • 给出求解结果(目标值 + 变量值)
  • 用 1-2 句解释业务含义

执行流程(两条路径)

flowchart LR
  A[Matrix_or_JSON]
  B[Natural_language]
  A --> A1[Build_or_solve_lp]
  B --> B1[Restate]
  B1 --> B2[User_confirm]
  B2 --> B3[Clarify_or_assume]
  B3 --> B4[Symbolic_model]
  B4 --> B5[Numeric_or_addVar]
  B5 --> B6[Solve_and_report]
  A1 --> B6

路径 A:已有矩阵或 JSON

  1. 核对维度:c 长度、A 行列、b 长度与约束条数一致。
  2. scripts/solve_lp.py 中的 solve_lp,或按「手建模型」自行写 coptpy(适合需要命名变量、稀疏结构的题)。

路径 B:自然语言 / 应用题

用户未给数字矩阵时,Agent 不要先索要 JSON。按下面交付物顺序推进:

步骤 内容
1. 重述 用一两句话复述题意,便于用户确认理解是否正确。
2. 用户确认 请用户确认重述是否准确,如有偏差则澄清;无异议再继续。
3. 符号化 变量表:名称、含义、单位(若有)、是否非负。目标:min 还是 max,线性式。约束:逐条写出,并标明 <= / >= / =(注意「不超过」「不少于」与不等号方向)。
4. 数值化 把符号模型写成 cA_ub/b_ubA_eq/b_eqbounds;或跳过稠密矩阵,用 addVar + addConstr + 有意义约束名直接建模。
5. 求解与回答 给出最优值、各变量取值;必要时用一句话解释经济/物理含义(用户未问不必展开对偶或灵敏度)。

输出模板(推荐)

回答尽量按以下模板组织(可省略不适用小节):

### 问题重述
...

### 符号化模型
- 决策变量:...
- 目标函数:...
- 约束:...

### 数值化(可选)
- c: ...
- A_ub / b_ub: ...
- A_eq / b_eq: ...
- bounds: ...

### 求解结果
- status: ...
- objective: ...
- x: ...

### 结果解释
...

歧义与澄清

建模前若信息不足,优先提问;若是标准教材题型,可列出假设再求解,并在重述中写明假设:

  • 目标是最小化成本/资源还是最大化利润/效用(口语可能含糊)。
  • 「至多 / 不超过」→ 通常对应 <=;「至少 / 不少于」→ 通常对应 >=(按变量所在一侧核对)。
  • 是否允许分数解(连续 LP 默认可行);若题意明确要求整数台数、0-1 选址等,见下节,勿当连续变量悄悄求解。
  • 非负:产量、投入量等若题中未写,常默认 >=0,须在变量表里写明「假设非负」。
  • 多商品、多期、多维约束:检查下标与矩阵行、列是否一一对应,避免把行维与列维弄反。

范围与非 LP(本 skill 边界)

本文件针对连续变量的 LP。若叙述中出现下列情况,应向用户说明已超出纯 LP,需 MILP、非线性或其它建模,禁止不声明就把整数松弛成连续变量:

Read the full file on GitHub · 209 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 209 lines · 90 tokens per session scan A 1337f4ee7ad4

Subscribe to this mod's changes

copt-linear-program is a skill published in the GitHub repository VeryMath/AI4Math-Optimization (5 stars, last pushed 1mo ago), licensed MIT. It adds 90 tokens to every session and 2,869 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

math-beamer

Use when creating, revising, or auditing source-grounded mathematical Beamer slide decks from papers, notes, proofs, lectures, experiments, or existing LaTeX slides across pure mathematics, applied mathematics, computational mathematics, statistics, optimization, geometry, topology, algebra, number theory…

VeryMath/AI4Math-Writing · 100 tokens

paper-writing

Use when drafting, revising, or auditing source-grounded mathematical paper text, including abstracts, introductions, related work, theorem exposition, experiment narratives, revision plans, and response letters.

VeryMath/AI4Math-Writing · 40 tokens

latex-build-and-layout-audit

Use when checking LaTeX paper projects for compilation, latexmk logs, undefined references, citation issues, duplicate labels, macro/package hygiene, layout warnings, floats, arXiv, or venue compatibility.

VeryMath/AI4Math-Writing · 48 tokens

proof-obligation-and-assumption-audit

Use when checking mathematical paper results for assumptions, quantifiers, domains, dependency fit, edge cases, external theorem use, proof coverage, or theorem-to-claim consistency.

VeryMath/AI4Math-Writing · 43 tokens

claim-evidence-ledger

Use when auditing mathematical paper drafts for supported claims, missing citations, overclaims, proof status, experiment support, or source-to-text traceability.

VeryMath/AI4Math-Writing · 35 tokens

paper-skeleton-and-logical-architecture

Use when turning mathematical notes, theorem statements, proof sketches, experiments, or reading outputs into a paper skeleton, section plan, result dependency map, or contribution architecture before prose drafting.

VeryMath/AI4Math-Writing · 45 tokens