소스 정보
- 저장소
- KYRIE66nb/codex-omx-public-config
- 최근 소스 활동
- 2026년 5월 28일 04:35
- 감지된 SKILL.md 언어
- 영어
- 스타
- 0
- 포크
- 0
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/KYRIE66nb/codex-omx-public-config --skill pyomo명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SKILL.md 표시 중
SOC 직업 분류 기준
| name | pyomo |
| description | Pyomo optimization modeling: LP, MILP, NLP, stochastic programs, solvers, planning. |
| version | 6.7 |
| license | BSD-3-Clause |
Pyomo allows you to define optimization problems using a natural mathematical syntax (Sets, Parameters, Variables, Constraints). It decouples the model from the solver, allowing the same model to be solved by different engines without code changes.
pip install pyomo
# Also install a solver (e.g., GLPK for linear/integer problems)
# Conda: conda install -c conda-forge glpk ipopt
Official docs: http://www.pyomo.org/
GitHub: https://github.com/Pyomo/pyomo
Search patterns: pyo.ConcreteModel, pyo.Constraint, pyo.Objective, pyo.SolverFactory
Pyomo does not have its own solver. It requires external solvers (like glpk for LP/MIP or ipopt for NLP) installed on the system.
pip install pyomo
# Also install a solver (e.g., GLPK for linear/integer problems)
# Conda: conda install -c conda-forge glpk ipopt
import pyomo.environ as pyo
from pyomo.opt import SolverFactory
import pyomo.environ as pyo
# 1. Create Model
model = pyo.ConcreteModel()
# 2. Define Variables
model.x = pyo.Var(within=pyo.NonNegativeReals)
model.y = pyo.Var(within=pyo.NonNegativeReals)
# 3. Define Objective (Minimize x + 2*y)
model.obj = pyo.Objective(expr=model.x + 2*model.y, sense=pyo.minimize)
# 4. Define Constraints
model.con1 = pyo.Constraint(expr=3*model.x + 4*model.y >= 12)
model.con2 = pyo.Constraint(expr=2*model.x + 5*model.y >= 10)
# 5. Solve
solver = pyo.SolverFactory('glpk')
results = solver.solve(model)
# 6. Access Results
print(f"x = {pyo.value(model.x)}, y = {pyo.value(model.y)}")
pyo.value(model.x) to get their numerical result after solving.results.solver.termination_condition.solver.options['tm_limit'] = 60 (or similar depending on the solver) to manage execution time.pyo.log(), pyo.exp(), pyo.sqrt() instead of math.log() or np.log() inside expressions.abs(x) or max(x, y) are non-smooth and can break many solvers. Use reformulations.x + y = 10 are fine, but ensure your units are consistent.import pyomo.environ as pyo
import numpy as np
# ❌ BAD: Using NumPy/Math functions in constraints
# model.con = pyo.Constraint(expr=np.sin(model.x) <= 0.5)
# ✅ GOOD: Use Pyomo-compatible functions
model.con = pyo.Constraint(expr=pyo.sin(model.x) <= 0.5)
# ❌ BAD: Using Python IF for conditional constraints
# if model.x > 10:
# model.con = pyo.Constraint(expr=model.y <= 5)
# ✅ GOOD: Using Big-M notation (for binary variable z)
# y <= 5 + M * (1 - z)
# x >= 10 - M * (1 - z)
# ❌ BAD: Printing a variable directly
# print(model.x) # Returns a reference object, not a number!
# ✅ GOOD: Use value()
print(pyo.value(model.x))
model = pyo.ConcreteModel()
# Data
products = ['A', 'B', 'C']
profit = {'A': 10, 'B': 20, 'C': 15}
limit = 100
# Components
model.P = pyo.Set(initialize=products)
model.x = pyo.Var(model.P, within=pyo.NonNegativeReals)
# Indexed Objective
def obj_rule(model):
return sum(profit[p] * model.x[p] for p in model.P)
model.obj = pyo.Objective(rule=obj_rule, sense=pyo.maximize)
# Indexed Constraint
def limit_rule(model):
return sum(model.x[p] for p in model.P) <= limit
model.con = pyo.Constraint(rule=limit_rule)
# Solving: Minimize (x-2)^2 + (y-2)^2
model = pyo.ConcreteModel()
model.x = pyo.Var(initialize=0) # Initialization is CRUCIAL for NLP
model.y = pyo.Var(initialize=0)
model.obj = pyo.Objective(expr=(model.x - 2)**2 + (model.y - 2)**2)
# Constraint: x^2 + y <= 1
model.con = pyo.Constraint(expr=model.x**2 + model.y <= 1)
# Solve with IPOPT
solver = pyo.SolverFactory('ipopt')
solver.solve(model)
# Binary variable: 1 if we open a warehouse, 0 otherwise
model.use_warehouse = pyo.Var(within=pyo.Binary)
# Integer variable: Number of trucks to buy
model.num_trucks = pyo.Var(within=pyo.NonNegativeIntegers)
# Conditional logic: If warehouse is not used, trucks must be 0
# trucks <= Capacity * use_warehouse
model.cap_con = pyo.Constraint(expr=model.num_trucks <= 100 * model.use_warehouse)
def solve_diet(foods, nutrients, costs, requirements):
model = pyo.ConcreteModel()
model.F = pyo.Set(initialize=foods)
model.N = pyo.Set(initialize=nutrients)
model.x = pyo.Var(model.F, within=pyo.NonNegativeReals)
# Minimize cost
model.obj = pyo.Objective(expr=sum(costs[f] * model.x[f] for f in model.F))
# Meet nutrient requirements
def nutrient_rule(model, n):
return sum(nutrients[f][n] * model.x[f] for f in model.F) >= requirements[n]
model.con = pyo.Constraint(model.N, rule=nutrient_rule)
pyo.SolverFactory('glpk').solve(model)
return {f: pyo.value(model.x[f]) for f in model.F}
# Balancing component fractions in a mixture
# Note: Often becomes non-linear (NLP) if both flow and fraction are variables
def blend_optimization(inputs, target_purity):
model = pyo.ConcreteModel()
# ... model setup ...
# con: sum(flow[i] * purity[i]) / sum(flow[i]) == target_purity
# becomes: sum(flow[i] * purity[i]) == target_purity * sum(flow[i]) (Linearized)
For iterative optimizations, use the previous solution as a starting point.
# For NLP solvers like IPOPT
model.x.set_value(prev_x_value)
solver.solve(model)
Always check why the solver stopped.
from pyomo.opt import TerminationCondition
results = solver.solve(model)
if results.solver.termination_condition == TerminationCondition.optimal:
print("Success")
elif results.solver.termination_condition == TerminationCondition.infeasible:
print("Check your constraints!")
If your NLP model has multiple local minima, IPOPT might get stuck.
# ✅ Solution:
# 1. Provide multiple different initial guesses (multistart).
# 2. Use a global solver like BARON or SCIP.
model.x[model.y] where y is a Var is illegal.
# ✅ Solution: Use model.AddElement or binary variable reformulations.
pyo.value() to extract numerical results from variables after solvingpyo.Set and pyo.Param for organizing data in complex modelspyo.log(), pyo.exp(), etc.) instead of NumPy/math functions in expressionsabs() or max() - use reformulationsPyomo is the ultimate tool for turning high-level mathematical abstractions into solved business and scientific problems. Its ability to bridge the gap between algebraic modeling and high-performance solvers makes it the foundation of modern prescriptive analytics.