Skip to content
Skills Library
Data & analytics · Analysis

linear-programming

/linear-programming

Linear Programming solver for MCM/ICM competitions. Use when optimizing linear objective functions subject to linear constraints (resource allocation, production planning, transportation problems). Supports simplex method, interior-point, and graphical solutions.

Licence
MIT
Last repository change
27.06.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
6
Scripts
0
HTML comments
0
URLs in SKILL.md
2
Deprecation

No signals detected. Repository changed on 27.06.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Linear Programming solver for MCM/ICM competitions. Use when optimizing linear objective functions subject to linear constraints (resource allocation, production planning, transportation problems). Supports simplex method, interior-point, and graphical solutions.

Original author description

Linear Programming solver for MCM/ICM competitions. Use when optimizing linear objective functions subject to linear constraints (resource allocation, production planning, transportation problems). Supports simplex method, interior-point, and graphical solutions.

How it works

  1. When to Use
  2. Quick Start
  3. Standard Form
  4. Examples in Skill
  5. Competition Tips
  6. Advanced: Integer Programming
  7. References
  8. Time Budget
  9. Related Skills
Original SKILL.md headings · 154 lines, 579 words
SKILL.md preview
---
name: linear-programming
description: Linear Programming solver for MCM/ICM competitions. Use when optimizing linear objective functions subject to linear constraints (resource allocation, production planning, transportation problems). Supports simplex method, interior-point, and graphical solutions.
---

# Linear Programming

Solve linear optimization problems: maximize/minimize a linear objective function subject to linear constraints.

## When to Use

- **Resource allocation**: Maximize profit with limited resources
- **Production planning**: Minimize cost while meeting demand
- **Transportation**: Optimize shipping routes
- **Diet problem**: Minimize cost while meeting nutritional requirements
- **Portfolio optimization**: Maximize return with risk constraints

## Quick Start

### Python (scipy.optimize.linprog)

```python
from scipy.optimize import linprog

# Minimize: c^T * x
# Subject to: A_ub @ x <= b_ub
#            A_eq @ x == b_eq
#            bounds for x

c = [-1, -2]  # Coefficients (negate for maximization)
A_ub = [[1, 1], [2, 1]]  # Inequality constraints
b_ub = [4, 5]

result = linprog(c, A_ub=A_ub, b_ub=b_ub, method='highs')
print(f"Optimal value: {-result.fun}")  # Negate back
print(f"Optimal solution: {result.x}")
```

### MATLAB (linprog)

```matlab
% Minimize: f' * x
% Subject to: A * x <= b
%            Aeq * x == beq
%            lb <= x <= ub

f = [-1; -2];  % Coefficients (negate for maximization)
A = [1, 1; 2, 1];  % Inequality constraints
b = [4; 5];

[x, fval] = linprog(f, A, b);
fprintf('Optimal value: %.4f\n', -fval);
fprintf('Optimal solution: [%.4f, %.4f]\n', x);
```

## Standard Form

**Maximize**: $z = c_1x_1 + c_2x_2 + ... + c_nx_n$

**Subject to**:
- $a_{11}x_1 + a_{12}x_2 + ... + a_{1n}x_n \leq b_1$
- $a_{21}x_1 + a_{22}x_2 + ... + a_{2n}x_n \leq b_2$
- ...
- $x_1, x_2, ..., x_n \geq 0$ (non-negativity)

## Examples in Skill

See `examples/` folder:
- `touzi.ipynb` / `Touzi.mlx`: Investment allocation problem
- `youxi.ipynb` / `youxi.mlx`: Game strategy optimization

## Competition Tips

### Model Formulation (Day 1)

1. **Define decision variables**: What are you optimizing?
2. **Write objective function**: Linear combination of variables
3. **List all constraints**: 
   - Resource limits (≤)
   - Demand requirements (≥)
   - Equality constraints (=)
4. **Check linearity**: All terms are $ax$ (not $x^2$, $xy$, $\sin(x)$, etc.)

### Implementation (Day 2)

```python
# Template
from scipy.optimize import linprog

# Decision variables: x = [x1, x2, ..., xn]

# Objective: minimize c^T * x (negate c for maximization)
c = [...]

# Inequality: A_ub @ x <= b_ub
A_ub = [[...], [...]]
b_ub = [...]

# Equality: A_eq @ x == b_eq (if any)
A_eq = [[...]]
b_eq = [...]

# Bounds: lb <= x <= ub
bounds = [(0, None), (0, 10), ...]  # (min, max) for each variable

# Solve
result = linprog(c, A_ub=A_ub, b_ub=b_ub, 
                 A_eq=A_eq, b_eq=b_eq, 
                 bounds=bounds, method='highs')

if result.success:
    print(f"Optimal: {result.x}")
    print(f"Value: {result.fun}")
else:
    print("No solution found")
```

### Validation (Day 3)

- **Sensitivity analysis**: How does optimal solution change with constraint bounds?
- **Shadow prices**: `result.ineqlin.marginals` (dual values)
- **Graphical check**: For 2D problems, plot feasible region

### Common Pitfalls

1. **Maximization**: Must negate objective coefficients for `linprog` (it minimizes)
2. **Inequality direction**: `linprog` uses ≤, convert ≥ by multiplying by -1
3. **Unbounded**: Check if problem is properly constrained
4. **Infeasible**: Constraints may be contradictory

## Advanced: Integer Programming

If variables must be integers (0/1 decisions, discrete quantities), use:
- Python: `scipy.optimize.milp` or `pulp`
- MATLAB: `intlinprog`

See `integer-programming` skill for details.

## References

- `references/7-线性规划【微信公众号丨B站:数模加油站】.pdf`: Complete tutorial with theory and examples
- SciPy docs: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html
- MATLAB docs: https://www.mathworks.com/help/optim/ug/linprog.html

## Time Budget

- **Formulation**: 30-60 min (most critical step)
- **Implementation**: 15-30 min
- **Validation**: 30-60 min
- **Total**: 1.5-2.5 hours

## Related Skills

- `integer-programming`: For discrete decisions
- `nonlinear-programming`: For nonlinear objectives/constraints
- `multi-objective-optimization`: For conflicting objectives
- `sensitivity-master`: For parameter sensitivity analysis
Files in this package (6)
  • SKILL.md 4 KB
  • examples/Touzi.mlx 19 KB
  • examples/touzi.ipynb 29 KB
  • examples/youxi.ipynb 2 KB
  • examples/youxi.mlx 4 KB
  • references/7-线性规划【微信公众号丨B站:数模加油站】.pdf 1,513 KB

Versions

The database has no other skills named linear-programming.

Database snapshot: 13.11.2026 · package version 17149f475a58 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100integer-programming
    Integer Programming for MCM/ICM competitions. Use when decision variables must be integers (0/1 decisions, discrete quantities) - knapsack, assignment, scheduling, facility location. Extends linear programming with integrality constraints.
  • 100nonlinear-programming
    Nonlinear Programming for MCM/ICM competitions. Use when objective function or constraints contain nonlinear terms (x², xy, sin(x), sqrt(x)). Handles engineering design, optimal control, parameter fitting. Requires initial guess and may find local optima.
  • 100nvidia-cuopt-numerical-optimization-api-python
    Solve Linear Programming (LP), Mixed-Integer Linear Programming (MILP), and Quadratic Programming (QP, beta) with the Python API. Use when the user asks about optimization with linear or quadratic objectives, linear constraints, integer variables, scheduling, resource…
  • 91auto-mcm
    AutoMCM-Pro industrial-grade math modeling agent. Supports AP (AI-led) and Manual (human-spec-led) dual modes with mandatory GitOps checkpoints, forced self-verification of all solver code before LaTeX inclusion, and structured human cross-validation at each pipeline stage. Use…
  • 91optimization-modeling
    When the user wants to build optimization models, solve mathematical programming problems, or find optimal solutions. Also use when the user mentions "linear programming," "integer programming," "mixed-integer programming," "constraint optimization," "mathematical optimization,"…
  • 100mcm-o-guide
    MCM/ICM 优秀论文写作全流程指南——基于 502 篇历年获奖论文(2004–2024)语料库的结构化分析与评委点评提炼。覆盖:摘要逐句模板、6 类题型模型选择矩阵、25 页页预算分配、图表黄金法则、灵敏度/稳健性分析范式、全文一致性检查清单。当用户准备美赛、写论文、打磨论文、查结构、选模型、做摘要、看评委标准、读优秀论文时使用。也适用于任何需要高质量数学建模论文写作的场景。

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.