๐Ÿ‘ฉ๐Ÿป‍๐ŸŒพ

Chap 6. Branch and Bound ๋ณธ๋ฌธ

Study/Algorithm

Chap 6. Branch and Bound

์ฅฌ์Šค์ด 2023. 6. 6. 02:06
728x90
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๋Š”  ์œ„์˜ ์‚ฌ์ง„๊ณผ ๊ฐ™๋‹ค. 

728x90

'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
Comments