From grimoire
Formulates and solves optimization problems — defining decision variables, objective functions, and constraints — and selects appropriate solvers for LP, QP, NLP, or MIP.
How this skill is triggered — by the user, by Claude, or both
Slash command
/grimoire:design-optimization-problemThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Formulate an optimization problem correctly — defining decision variables, objective function, and constraints — then select an appropriate solver based on problem class (LP, QP, NLP, MIP) to find solutions efficiently and reliably.
Formulate an optimization problem correctly — defining decision variables, objective function, and constraints — then select an appropriate solver based on problem class (LP, QP, NLP, MIP) to find solutions efficiently and reliably.
Adopted by: Optimization is the mathematical engine behind supply chain management (logistics companies: UPS, Amazon), financial portfolio optimization (Markowitz model, BlackRock), machine learning (gradient descent), engineering design (aerospace, automotive), and power grid dispatch (every electrical utility). Gurobi, CPLEX, and MOSEK are the gold-standard commercial solvers; GLPK, HiGHS, and SciPy are free alternatives. Impact: Boyd & Vandenberghe (2004) demonstrated that convex optimization problems can be solved globally and efficiently — the key insight is that convexity identification determines whether a globally optimal solution is achievable or only a local optimum. An incorrectly formulated problem (non-convex when convex reformulation exists) can increase solve time from seconds to hours or produce local optima mistaken for global solutions.
Before writing the objective or constraints:
Standard form: minimize f(x) [maximization: multiply by −1]
Write f(x) explicitly in terms of decision variables:
Check convexity of f(x): if Hessian ∇²f is positive semidefinite for all x → convex (global minimum guaranteed).
Three types:
Write constraints mathematically; verify units are consistent. Check feasibility: does a feasible point exist? (Empty feasible set = infeasible problem.)
| Problem class | Objective | Constraints | Solver |
|---|---|---|---|
| LP (Linear Programming) | Linear | Linear | HiGHS, Gurobi, GLPK |
| QP (Quadratic Programming) | Quadratic | Linear | Gurobi, OSQP, quadprog |
| SOCP (Second-Order Cone) | Convex | SOC constraints | MOSEK, SCS, ECOS |
| SDP (Semidefinite) | Linear | PSD constraint | MOSEK, SCS |
| NLP (Nonlinear, convex) | Convex nonlinear | Any | IPOPT, SNOPT |
| NLP (nonconvex) | Nonconvex | Any | IPOPT (local), Basin-Hopping, Differential Evolution |
| MIP (Mixed Integer) | Linear/quadratic | Linear + integer | Gurobi, CPLEX, HiGHS |
Rule: always try to reformulate as a convex problem before accepting a nonconvex formulation — convex problems have global optima and scale to thousands of variables.
# Example: LP with scipy
from scipy.optimize import linprog
result = linprog(c, A_ub=A, b_ub=b, bounds=bounds, method='highs')
print(result.status, result.fun, result.x)
# Example: convex QP with CVXPY
import cvxpy as cp
x = cp.Variable(n)
objective = cp.Minimize(0.5 * cp.quad_form(x, Q) + c.T @ x)
constraints = [A @ x <= b, x >= 0]
prob = cp.Problem(objective, constraints)
prob.solve()
Verification checklist:
For LP/QP, dual variables (shadow prices) quantify the value of relaxing each constraint by 1 unit:
This analysis guides which constraints are most valuable to relax in practice.
npx claudepluginhub jeffreytse/grimoire --plugin grimoireFormulates and solves optimization problems using LP (simplex, interior point), MIP (branch-and-bound), convex methods (Adam, L-BFGS), CSP (SAT/SMT), and combinatorial (VRP, scheduling) with solvers like PuLP, CVXPY, OR-Tools.
Optimizes multi-objective problems using pymoo (NSGA-II/III, MOEA/D) with Pareto-front computation, constraint handling, and standard benchmarks (ZDT, DTLZ).
Solves single and multi-objective optimization problems using evolutionary algorithms (NSGA-II/III, MOEA/D) and Pareto front analysis. Includes benchmarks and customizable operators.