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

2 minute read

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


<DAG; Directed Acyclic Graph>๋Š” cycle์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” directed graph๋ฅผ ๋งํ•œ๋‹ค.

์ด๋•Œ, ๋ชจ๋“  DAG์˜ ๋…ธ๋“œ๋Š” <topological ordering>๋ฅผ ๊ฐ€์ง€๊ธฐ ๋•Œ๋ฌธ์—, ์šฐ๋ฆฌ๋Š” DAG๋ฅผ <topological sort>๋กœ linearization ํ•  ์ˆ˜ ์žˆ๋‹ค!!

์ด๊ฒƒ์€ DAG๊ฐ€ ๊ฐ–๋Š” ์„ฑ์งˆ ๋•Œ๋ฌธ์ธ๋ฐ, โ€œEvery DAG has at least one vertex with no incoming edge.โ€์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค! ์ด ์„ฑ์งˆ์— ๋”ฐ๋ผ, <topological sort>๋Š” DAG์— ์กด์žฌํ•˜๋Š” vertex with no incoming edge๋ฅผ ํ•˜๋‚˜์”ฉ ์ œ๊ฑฐํ•ด๊ฐ€๋ฉด์„œ, DAG๋ฅผ linearization ํ•œ๋‹ค ๐Ÿคฉ

์œ„์—์„œ ์ œ์‹œํ•œ DAG์— ๋Œ€ํ•ด vertex with no incoming edges๋ฅผ ๋ฐ˜๋ณต์ ์œผ๋กœ ์ œ๊ฑฐํ•˜์—ฌ topological sort๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉด, ๊ทธ ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

DAG๊ณผ topological ordering ์‚ฌ์ด์˜ ๊ด€๊ณ„๋ฅผ ๊ธฐ์ˆ ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

A directed graph is a DAG iff it has a topological ordering.


์ด๋ ‡๊ฒŒ DAG๋ฅผ topological order๋กœ linearization ํ–ˆ๋‹ค๋ฉด, ์šฐ๋ฆฌ๋Š” DAG ์œ„์—์„œ์˜ shortest path๋ฅผ ์‰ฝ๊ฒŒ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

Linearize $G$

for each $u \in V$ in linearized order
โ€ƒโ€ƒfor all edges $(u, v) \in E$
โ€ƒโ€ƒโ€ƒโ€ƒ$\texttt{update}(u, v)$
โ€ƒโ€ƒend for
end for

์ฐธ๊ณ ๋กœ ์ฃผ์–ด์ง„ ๊ทธ๋ž˜ํ”„๊ฐ€ DAG๋ผ๋ฉด, negative edge๊ฐ€ ์žˆ์–ด๋„ ์œ„์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ถฉ๋ถ„ํžˆ shortest path๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค!! (DAG๋Š” cycle์ด ์—†๊ธฐ ๋•Œ๋ฌธ์—, negative cycle์— ๋Œ€ํ•œ ๊ฑฑ์ •์ด ์—†๋‹ค! ๐Ÿ˜†)


์—ฌ๊ธฐ๊นŒ์ง€๊ฐ€ ์ •๊ทœ ์ˆ˜์—…์—์„œ ๋‹ค๋ฃฌ <Graph Algorithm>์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด๋‹ค. ๊ทธ๋ž˜ํ”„ ์ด๋ก ์€ PS์˜ ๊ธฐ๋ณธ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ณณ์—์„œ ๋‹ค๋ฃฌ ๋ชจ๋“  ๋‚ด์šฉ์„ ์™„์ „ํžˆ ์ดํ•ดํ•˜๊ณ  ์–ธ์ œ๋“ ์ง€ ์“ธ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š”๊ฒŒ ์ค‘์š”ํ•œ ๊ฒƒ ๊ฐ™๋‹ค. โ€˜์•Œ๊ณ ๋ฆฌ์ฆ˜โ€™ ๊ณผ๋ชฉ์˜ ์ •๊ทœ ์ˆ˜์—…์—์„œ ๋‹ค๋ฃจ์ง€๋Š” ์•Š์•˜์ง€๋งŒ, โ€˜์ธ๊ณ ์ง€๋Šฅโ€™ ๊ณผ๋ชฉ์—์„œ๋Š” ๋‹ค๋ค˜๋˜ heuristic path finding ๊ธฐ๋ฒ•์ธ <A* Algorithm>๋„ ์ถ”ํ›„์— ๋‹ค๋ค„๋ณด๋„๋ก ํ•˜๊ฒ ๋‹ค.

๊ทธ๋ž˜ํ”„์— ๋Œ€ํ•œ ๋‚ด์šฉ์€ ๋‚˜์ค‘์— <Network Flow> ๋ถ€๋ถ„์—์„œ ๋‹ค์‹œ ๋“ฑ์žฅํ•œ๋‹ค! ๐Ÿ˜‰

Categories:

Updated: