Files
2nd/10_Wiki/Topics/Domain_Programming/AI_and_ML/Linear-Programming.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

4.1 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-linear-programming Linear Programming 10_Wiki/Topics verified self
LP
Linear Optimization
Simplex
none A 0.9 applied
optimization
lp
simplex
scipy
pulp
or-tools
2026-05-10 pending
language framework
Python scipy/PuLP/OR-Tools

Linear Programming

매 한 줄

"매 LP는 선형 목적함수 + 선형 제약 → 최적해는 vertex에 있다". Simplex가 vertex 사이를 움직이고, interior point는 내부를 가로지른다.

매 핵심

매 표준형

  • minimize cᵀx s.t. Ax ≤ b, x ≥ 0
  • Feasible region = polytope (convex). 최적해는 항상 corner(꼭짓점) 또는 edge.
  • LP relaxation → IP/MIP의 lower bound.

매 알고리즘 비교

  • Simplex: vertex hopping. exponential worst case지만 실제는 빠름.
  • Interior point (Karmarkar): polynomial time. 큰 LP에 유리.
  • Dual simplex: 제약 추가 후 warm start에 강함 (branch-and-bound 내부).

매 응용

  1. Resource allocation, transportation, assignment
  2. Diet/blending, production scheduling
  3. Network flow (max-flow, min-cost-flow)
  4. ML: SVM (QP지만 LP-like), L1 regression, portfolio optimization

💻 패턴

scipy.optimize.linprog

from scipy.optimize import linprog
# minimize -x0 - 2x1 s.t. x0+x1<=4, x0+3x1<=6, x>=0
res = linprog(c=[-1, -2], A_ub=[[1,1],[1,3]], b_ub=[4,6],
              bounds=[(0, None), (0, None)], method="highs")
print(res.x, res.fun)  # [3, 1] -> -5

PuLP (선언적)

from pulp import LpProblem, LpVariable, LpMaximize, lpSum
prob = LpProblem("prod", LpMaximize)
x = LpVariable.dicts("x", ["A", "B"], lowBound=0)
prob += 40*x["A"] + 30*x["B"]               # objective
prob += 2*x["A"] + x["B"] <= 100             # labor
prob += x["A"] + x["B"] <= 80                # material
prob.solve()

OR-Tools (production)

from ortools.linear_solver import pywraplp
solver = pywraplp.Solver.CreateSolver("GLOP")  # LP. "CBC" for MIP
x = solver.NumVar(0, solver.infinity(), "x")
y = solver.NumVar(0, solver.infinity(), "y")
solver.Add(x + 2*y <= 14); solver.Add(3*x - y >= 0)
solver.Maximize(3*x + 4*y)
solver.Solve()

Integer/Mixed-Integer LP

# PuLP with integer variables
x = LpVariable("x", lowBound=0, cat="Integer")
y = LpVariable("y", lowBound=0, upBound=1, cat="Binary")
# branch-and-bound: LP relaxation → branch on fractional vars

Transportation problem

# min sum c_ij x_ij s.t. sum_j x_ij = supply_i, sum_i x_ij = demand_j
costs = [[8, 6, 10], [9, 12, 13], [14, 9, 16]]
supply = [20, 30, 25]; demand = [10, 35, 30]
# flatten to linprog

Sensitivity / dual

# scipy returns marginals via res.ineqlin.marginals (HiGHS)
# Dual variable = shadow price of constraint

매 결정 기준

상황 Tool
빠른 prototype scipy.linprog (HiGHS)
선언적/큰 모델 PuLP
Production / MIP OR-Tools, Gurobi, CPLEX
정수 변수 多 CBC, Gurobi (commercial)
Network flow NetworkX, OR-Tools min_cost_flow

기본값: scipy HiGHS → 부족하면 PuLP+CBC → 상용 Gurobi.

🔗 Graph

🤖 LLM 활용

언제: LP 모델링 (변수/제약 도출), code 생성, 결과 해석. 언제 X: 대규모 commercial solver tuning, numerical stability 진단은 전문가.

안티패턴

  • 비선형 제약을 LP로 모델링 (→ NLP/QP 필요)
  • 정수 변수에 LP 그대로 적용 (반올림 ≠ 최적)
  • 큰 dense A matrix를 sparse 변환 없이 사용
  • Unbounded/infeasible 모델 진단 없이 결과 신뢰

🧪 검증 / 중복

  • Verified (Bertsimas Tsitsiklis "Intro to LO", scipy/PuLP/OR-Tools docs). 신뢰도 A.
  • 중복: 없음 (LP는 독립 토픽).

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — 매 prefix, scipy/PuLP/OR-Tools 패턴