2020-1ํ•™๊ธฐ, ๋Œ€ํ•™์—์„œ โ€˜์•Œ๊ณ ๋ฆฌ์ฆ˜โ€™ ์ˆ˜์—…์„ ๋“ฃ๊ณ  ๊ณต๋ถ€ํ•œ ๋ฐ”๋ฅผ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ง€์ ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜์ž…๋‹ˆ๋‹ค :)

3 minute read

2020-1ํ•™๊ธฐ, ๋Œ€ํ•™์—์„œ โ€˜์•Œ๊ณ ๋ฆฌ์ฆ˜โ€™ ์ˆ˜์—…์„ ๋“ฃ๊ณ  ๊ณต๋ถ€ํ•œ ๋ฐ”๋ฅผ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ง€์ ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜์ž…๋‹ˆ๋‹ค :)

Interval Scheduling

๊ฐ Job $j$๋Š” $[s_j, f_j]$์˜ start time, finish time์„ ๊ฐ€์ง„๋‹ค๊ณ  ๊ฐ€์ž. ์ด๋•Œ, ๋‘ Job์ด compatible ํ•˜๋‹ค๋Š” ๊ฒƒ์€ ๋‘ Job์ด ์„œ๋กœ ์ค‘์ฒฉ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋ง์ด๋‹ค. <Interval Scheduling>์€ ์ „์ฒด Job์˜ ์ง‘ํ•ฉ์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ ์ค‘ ํฌํ•จ๋œ ๋ชจ๋“  Job์ด ์„œ๋กœ compatibleํ•˜๋ฉด์„œ ๊ทธ ๋ถ€๋ถ„์ง‘ํ•ฉ์˜ ํฌ๊ธฐ๊ฐ€ ์ตœ๋Œ€๊ฐ€ ๋˜๋Š” ์ง‘ํ•ฉ์„ ์ฐพ๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ํ•œ๋‹ค.

๊ณผ์—ฐ ์œ„์™€ ๊ฐ™์€ Maximum compatible subset์„ ์ฐพ์œผ๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ?? Greedy Algorithm์€ ๋ชจ๋“  Job์„ finish time์œผ๋กœ ์ •๋ ฌํ•œ ํ›„์— ์ข…๋ฃŒ์‹œ๊ฐ„์ด ๋น ๋ฅด๋ฉด์„œ compatible ํ•œ ์ˆœ์„œ๋Œ€๋กœ ๊ณ ๋ฅด๋Š” ๋ฐฉ์‹์„ ์ œ์•ˆํ•œ๋‹ค.

Theorem.

<Interval Scheduling> ๋ฌธ์ œ์—์„œ ์œ„์™€ ๊ฐ™์€ Greedy Approach๋Š” optimal solution์„ ๋ณด์žฅํ•œ๋‹ค.

Proof.

(๊ท€๋ฅ˜๋ฒ•) Assume that the given greedy approach is not optimal.

Let $i_1, i_2, \dots, i_n$ denote the set of jobs selected by greedy.

Let $j_1, j_2, \dots, j_m$ denote the set of jobs in the optimal solution with $i_1 = j_1$, $i_2 = j_2$, โ€ฆ, $i_r = j_r$ for the largest possible value of $r$.

(ํ•ด์„ค) ์ฆ‰, greedy๊ฐ€ optimal์ด ์•„๋‹ˆ๊ณ , ๋‹ค๋ฅธ optimal sequence $\{ j_k \}$๊ฐ€ ์กด์žฌํ•˜๋Š”๋ฐ, ๊ทธ optimal seq.์™€ greedy seq.๊ฐ€ $r$๊นŒ์ง€๋Š” ๋™์ผํ•œ seq.๋ผ๊ณ  ๊ฐ€์ •ํ•œ๋‹ค๋Š” ๋ง์ด๋‹ค.

By the greedy choice, job $i_{r+1}$ finishes before $j_{r+1}$.
(์ฒ˜์Œ์— greedy approach๊ฐ€ optimal์ด ์•„๋‹ˆ๋ผ๊ณ  ํ–ˆ์œผ๋ฏ€๋กœ ์œ„์™€ ๊ฐ™์€ ์ƒํ™ฉ์ด ์„ฑ๋ฆฝํ•œ๋‹ค!)

So in the optimal solution, we can replace job $j_{r+1}$ with job $i_{r+1}$. The resulting solution is still feasible and optimal, but contradicts the maximality of $r$.
(์ฆ‰, ์šฐ๋ฆฌ๊ฐ€ greedy๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ optimal seq.๋ฅผ ๊ฐ€์ •ํ–ˆ์„ ๋•Œ, ์“ด maximality ๊ฐ€์ •์ด ํ”๋“ค๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— โ€œgreedy seq.๊ฐ€ optimal ์•„๋‹ˆ๋‹คโ€๋ผ๋Š” ๊ฐ€์ •์€ ๊ฑฐ์ง“์ด ๋œ๋‹ค๋Š” ๋ง์ด๋‹ค.)



Interval Partitioning

$n$๊ฐœ์˜ ์ˆ˜์—…์ด ์ฃผ์–ด์กŒ๊ณ , ๊ฐ ์ˆ˜์—… $j$๋Š” $[s_j, f_j]$์˜ start/finish time์„ ๊ฐ–๋Š”๋‹ค๊ณ  ํ•˜์ž. ์ด๋•Œ, ์–ด๋–ค ๋‘ ์ˆ˜์—…๋„ ๊ฒน์น˜์ง€ ์•Š๋„๋ก ์Šค์ผ€์ฅด๋ง ํ•˜๋ฉด์„œ, ๊ฐ•์˜์‹ค์˜ ๊ฐฏ์ˆ˜๋Š” ์ตœ์†Œ๊ฐ€ ๋˜๋Š” ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•ด๋ณด์ž!

์œ„์˜ ๋ฌธ์ œ ์—ญ์‹œ Greedy Algorithm์œผ๋กœ ๊ฐ„๋‹จํžˆ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค!!

Algorithm: Interval-Partition($S$)


// initialization
sort intervals by starting time.
$d=0$

// greedy process!
for $j=1$ to $n$
โ€ƒโ€ƒif lecture $j$ is compatible with classroom $k$
โ€ƒโ€ƒโ€ƒโ€ƒschedule lecture $j$ in classroom $k$
โ€ƒโ€ƒelse
โ€ƒโ€ƒโ€ƒโ€ƒallocate a new classroom $d+1$
โ€ƒโ€ƒโ€ƒโ€ƒschedule lecture $j$ in a new classroom
โ€ƒโ€ƒโ€ƒโ€ƒ$d = d+1$

์ด๋•Œ, ๊ฐ classroom $k$๋Š” ํ˜„์žฌ lecture์˜ finish time $f_j$๋ฅผ ๋‹ด๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค. ๊ทธ๋ž˜์„œ, ์ด๊ฒƒ์„ classroom์„ Priorirty Queue๋กœ ๊ด€๋ฆฌํ•˜์—ฌ, ๋งŒ์•ฝ ์ƒˆ๋กœ์šด lecture๊ฐ€ front node์˜ finish time๋ณด๋‹ค ๋น ๋ฅธ start time์„ ๊ฐ€์ง„๋‹ค๋ฉด, $d = d+1$ ํ•œ ํ›„์— Priority Queue์— ์ƒˆ๋กญ๊ฒŒ insertion ํ•˜๋ฉด ๋œ๋‹ค!


์ถ”์ฒœ ๋ฌธ์ œ

Categories:

Updated: