๐ฉ๐ป๐พ
Chap 6. Branch and Bound ๋ณธ๋ฌธ
Branch and Bound
- Backtraking๊ณผ ๊ฐ์ด state-space tree๋ฅผ ์ฌ์ฉํ๋ค.
- ํธ๋ฆฌ๋ฅผ ํ์ํ๋ ๋ฐฉ์์ ์ ํ์ ๋์ง ์๋๋ค.
- ์ค์ง ์ต์ ํ ๋ฌธ์ ์๋ง ์ฌ์ฉ๋๋ค.
BFS์ Best-First Search๋ฅผ ์ฌ์ฉํด์ ํ์์ ์งํํ๋๋ฐ ์ด๋ฒ ํฌ์คํ ์์๋ Best-First Search๋ก 0-1 Knapsack Problem์ ํด๊ฒฐํ๋ ๋ฐฉ์์ ๋ํด ์์ฑํ๋๋ก ํ๊ฒ ์ต๋๋ค.
0-1 Knapsack Problem using Best-First Search
Basic Idea
- ๋ ธ๋๊ฐ promisingํ์ง๋ก ๊ฒฐ์ ํ๊ธฐ๋ณด๋ค๋ bound๋ฅผ ์ฌ์ฉํด์ ๋ค์์ผ๋ก ํ์ฅํ ๋ ธ๋๋ฅผ ์ ํ
- ๋ ธ๋์ bound๋ก ์ฐ์ ์์๊ฐ ์ ํด์ง๋ priority queue๋ฅผ ์ฌ์ฉ
1. item์ ๋ชจ๋ ๋ฃ์ง ์์์ ๋, bound ๊ฐ์ $115์ด๋ค.
์ด๋, node0๋ง ์กด์ฌํ๋ฏ๋ก current best solution์ ์๋์ผ๋ก 0์ด ๋๋ค.
2. item1์ ๋ด์์ ๋์ ๋ด์ง ์์์ ๋๋ก ๋ ธ๋๋ฅผ ํ์ฅํ ์ํ์ด๋ค.
node1๊ณผ node2 ๊ฐ๊ฐ์ bound๋ฅผ ๊ณ์ฐํด์ค๋ค.(bound๋ฅผ ๊ณ์ฐํ๋ ๋ฐฉ์์ ์ด์ Chap 5. Backtracking์์ ์ค๋ช ํ๋ค.)
์ด๋, current best solution์ node1๊ฐ์ผ๋ก ์ค์ ๋๋๋ฐ node2์ bound๊ฐ current best solution๋ณด๋ค ํฌ๋ฏ๋ก queue ๋ ๋ ธ๋ ๋ชจ๋ ๋ฃ์ด์ค๋ค.
3. node1์์ item2๋ฅผ ๋ด์์ ๋์ ๋ด์ง ์์์ ๋๋ก ๋ ธ๋๋ฅผ ํ์ฅํ ์ํ์ด๋ค.
์ถ๊ฐ๋ node3๊ณผ node4์ bound๋ฅผ ๊ณ์ฐํด์ค๋ค.
node2, node3, node4์ current profit์ ๋น๊ตํ์ ๋, node3์ ๊ฐ์ด ๊ฐ์ฅ ํฌ๋ฏ๋ก current best solution์ $70์ด ๋๋ค.
node2์ node4์ bound๊ฐ current best solution๋ณด๋ค ํฌ๋ฏ๋ก ๋ ๋ ธ๋ ๋ชจ๋ ํ์ ๋์์ผ๋ก queue์ ๋ฃ์ด์ค๋ค.
4. ์ฐ์ ์์๊ฐ ๊ฐ์ฅ ๋์ node3์ ๋ค์ ํ์ ๋์์ผ๋ก ์ก์์ item3์ ๋ด์์ ๋์ ๋ด์ง ์์์ ๋๋ก ๋ ธ๋๋ฅผ ํ์ฅํ๋ค.
๋ง์ฐฌ๊ฐ์ง๋ก, ์ถ๊ฐ๋ node5์ node6์ bound๋ฅผ ๊ณ์ฐํด์ค์ผ ํ๋๋ฐ node5์ current weight๊ฐ ์ต๋ ๋ฌด๊ฒ์ธ 16๋ณด๋ค ๋ฌด๊ฑฐ์์ ธ์ ํ์ ๋์์ด ์๋๋ฏ๋ก node6์ bound๋ง ๊ตฌํด์ค๋ค.
node2, node4, node6์ current profit์ ๋น๊ตํ์ ๋, node6์ ๊ฐ์ด ๊ฐ์ฅ ํฌ๋ฏ๋ก current best solution์ $70์ด ๋๋ค.
node2์ node4์ bound๊ฐ current best solution๋ณด๋ค ํฌ๋ฏ๋ก node6๋ง ์๋ก์ด ํ์ ๋์์ผ๋ก queue์ ๋ฃ์ด์ค๋ค.
5. ์ฐ์ ์์๊ฐ ๊ฐ์ฅ ๋์ node4๋ฅผ ๋ค์ ํ์ ๋์์ผ๋ก ์ก์์ item3์ ๋ด์์ ๋์ ๋ด์ง ์์์ ๋๋ก ๋ ธ๋๋ฅผ ํ์ฅํ๋ค.
์ถ๊ฐ๋ node7๊ณผ node8์ bound๋ฅผ ๊ณ์ฐํด์ค๋ค. ์ด๋, current best solution์ node7์ current profit์ธ $90์ด ๋๋๋ฐ node8์ bound๊ฐ $90๋ณด๋ค ์์ $50์ด๋ผ ํ์ ๋์์ด ์๋๋ค.(์ดํ ํ์ฅ๋์ด๋ $90๋ณด๋ค ์ปค์ง์ง ์๊ธฐ ๋๋ฌธ์)
node2์ node6์ bound๊ฐ current best solution๋ณด๋ค ํฌ๋ฏ๋ก node7๋ง ์๋ก์ด ํ์ ๋์์ผ๋ก queue์ ๋ฃ์ด์ค๋ค.
6. ์ฐ์ ์์๊ฐ ๊ฐ์ฅ ๋์ node4๋ฅผ ๋ค์ ํ์ ๋์์ผ๋ก ์ก์์ item4๋ฅผ ๋ด์์ ๋์ ๋ด์ง ์์์ ๋๋ก ๋ ธ๋๋ฅผ ํ์ฅํ๋ค.
node9์ node10์ bound๋ฅผ ๊ตฌํด์ผํ๋๋ฐ node9์ current weight๊ฐ ์ต๋ ๋ฌด๊ฒ์ธ 16๋ณด๋ค ๋ฌด๊ฑฐ์์ ธ์ ํ์ ๋์์ด ์๋๋ฏ๋ก node10์ bound๋ง ๊ตฌํด์ค๋ค.
์ด๋, current best solution์ $90์ด ๋๋ค. queue์ ๋จ์์๋ node2์ node6์ bound๊ฐ์ด ๊ฐ๊ฐ $80, $82๋ก current best solution๋ณด๋ค ์์ผ๋ฏ๋ก ํด๋น ๋ ธ๋๋ค๋ก๋ถํฐ ๋์ด์ ํ์ฅํ์ง ์๋๋ค.
7. ์ต์ข state-space tree๋ ์์ ์ฌ์ง๊ณผ ๊ฐ๋ค.
'Study > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Chap 9. Introduction to the Theory of NP (0) | 2023.06.11 |
---|---|
Chap 7. Introduction to Computational Complexity: The Sorting Problem (0) | 2023.06.08 |
Chap 5. Backtracking (0) | 2023.06.04 |
Chap 4. The Greedy Approach (0) | 2023.06.01 |
Chap 3. Dynamic Programming (0) | 2023.04.20 |