[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
+107 -69
View File
@@ -2,91 +2,129 @@
id: wiki-2026-0508-linear-programming
title: Linear Programming
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [P-Reinforce-AUTO-LIPR-001]
aliases: [LP, Linear Optimization, Simplex]
duplicate_of: none
source_trust_level: A
confidence_score: 0.95
tags: [auto-reinforced, linear-programming, Optimization, algorithms, Operations-Research, constraints]
confidence_score: 0.9
verification_status: applied
tags: [optimization, lp, simplex, scipy, pulp, or-tools]
raw_sources: []
last_reinforced: 2026-04-20
last_reinforced: 2026-05-10
github_commit: pending
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
tech_stack:
language: unspecified
framework: unspecified
tech_stack: { language: Python, framework: scipy/PuLP/OR-Tools }
---
# [[Linear-Programming|Linear-Programming]]
# Linear Programming
## 📌 한 줄 통찰 (The Karpathy Summary)
> "현실적인 최선의 타협: '예산'은 얼마고 '시간'은 부족하다는 수많은 제약 조건 속에서, 이익을 최대화하거나 비용을 최소화하는 황금 해답을 선형 방정식이라는 수식을 통해 찾아내는 최적화의 정석."
## 한 줄
> **"매 LP는 선형 목적함수 + 선형 제약 → 최적해는 vertex에 있다"**. Simplex가 vertex 사이를 움직이고, interior point는 내부를 가로지른다.
## 📖 구조화된 지식 (Synthesized Content)
선형 계획법(Linear-Programming, LP)은 제약 조건이 있는 상황에서 선형 함수의 최댓값이나 최솟값을 구하는 수학적 방법입니다.
## 매 핵심
### 매 표준형
- minimize cᵀx s.t. Ax ≤ b, x ≥ 0
- Feasible region = polytope (convex). 최적해는 항상 corner(꼭짓점) 또는 edge.
- LP relaxation → IP/MIP의 lower bound.
1. **3대 요소**:
* **Objective Function**: 우리가 극대화하려는 것 (예: 수익).
* **Decision Variables**: 우리가 조정할 수 있는 값 (예: 생산량).
* **Constraints**: 우리가 넘어서는 안 될 벽 (예: 예산, 자원 부족).
2. **활용 분야**:
* 비행기 좌석 노선 배치, 공장 생산 스케줄링, 영양 균형 식단 짜기 등. ([[Combinatorial-Optimization|Combinatorial-Optimization]]와 연결)
### 매 알고리즘 비교
- **Simplex**: vertex hopping. exponential worst case지만 실제는 빠름.
- **Interior point (Karmarkar)**: polynomial time. 큰 LP에 유리.
- **Dual simplex**: 제약 추가 후 warm start에 강함 (branch-and-bound 내부).
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌**: 과거에는 변수가 몇 개 없는 단순 계산 정책이었으나, 현대 정책은 캄마르카르 알고리즘 정책 등을 활용해 수백만 개의 변수를 가진 전 지구적 물류망 정책 등을 최적화하는 단계로 진입함(RL Update).
- **정책 변화(RL Update)**: 단순 LP 정책을 넘어, 변수가 정수여야 하거나(Integer Programming) 관계가 비선형인 경우까지 아우르는 '현대적 운영 과학(OR) 정책'으로 진화하며 AI의 결정 보조 도구 정책으로 강력하게 작동함.
### 매 응용
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
## 🔗 지식 연결 (Graph)
- [[Optimization|Optimization]], [[Combinatorial-Optimization|Combinatorial-Optimization]], [[Search-Optimization|Search-Optimization]], [[Decision Theory|Decision Theory]], [[Efficiency|Efficiency]]
- **Modern Tech/Tools**: Simplex algorithm, Gurobi, IBM CPLEX, Microsoft Excel Solver.
---
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
**언제 이 지식을 쓰는가:**
- *(TODO)*
**언제 쓰면 안 되는가:**
- *(TODO)*
## 🧪 검증 상태 (Validation)
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
## 🧬 중복 검사 (Duplicate Check)
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
## 🕓 변경 이력 (Changelog)
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
## 💻 코드 패턴 (Code Patterns)
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
```text
# TODO
## 💻 패턴
### scipy.optimize.linprog
```python
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
```
## 🤔 의사결정 기준 (Decision Criteria)
### PuLP (선언적)
```python
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()
```
**선택 A를 써야 할 때:**
- *(TODO)*
### OR-Tools (production)
```python
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()
```
**선택 B를 써야 할 때:**
- *(TODO)*
### Integer/Mixed-Integer LP
```python
# 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
```
**기본값:**
> *(TODO)*
### Transportation problem
```python
# 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
```
## ❌ 안티패턴 (Anti-Patterns)
### Sensitivity / dual
```python
# scipy returns marginals via res.ineqlin.marginals (HiGHS)
# Dual variable = shadow price of constraint
```
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
## 매 결정 기준
| 상황 | 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
- 부모: [[Optimization]], [[Convex-Optimization]]
- 변형: [[Integer-Programming]], [[Mixed-Integer-Programming]], [[Quadratic-Programming]]
- 응용: [[Transportation-Problem]], [[Assignment-Problem]], [[Network-Flow]]
- Adjacent: [[Simplex-Method]], [[Duality]], [[SVM]]
## 🤖 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 패턴 |