0% found this document useful (0 votes)
24 views

Paths: Friday, September 21, 2012

The document discusses various graph algorithms and problems including: 1. Algorithms to determine if a path exists between two nodes in a graph and to find shortest paths between nodes. 2. Problems involving finding shortest paths in directed acyclic graphs and determining the shortest path tree with the root node. 3. Other problems discussed include the knapsack problem, project planning as a precedence problem, and finding shortest paths in graphs that may contain cycles.

Uploaded by

foca monaca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Paths: Friday, September 21, 2012

The document discusses various graph algorithms and problems including: 1. Algorithms to determine if a path exists between two nodes in a graph and to find shortest paths between nodes. 2. Problems involving finding shortest paths in directed acyclic graphs and determining the shortest path tree with the root node. 3. Other problems discussed include the knapsack problem, project planning as a precedence problem, and finding shortest paths in graphs that may contain cycles.

Uploaded by

foca monaca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Paths

Friday, September 21, 2012


Traffic plan of the city
intersection
2
1
street
5
assign a direction
to the arcs: 3
4
one way or 9
t wo ways streets
6

10
7

Friday, September 21, 2012


Connection problems
Is there a path from 1 to 6?
How can you certify it concisely?

Is there a path from 1 to 10?


How can you certify it concisely?

Friday, September 21, 2012


Graph_search (G, s, P)
for i ∈ N do P[i]←0
P[s]←s; Q←{s};
repeat
select i from Q; Q←Q\{i};
foreach (i,j) ∈ FS(i) do
if P[j]=0 then P[j]← i
Q←Q∪{j}
until Q=∅

Friday, September 21, 2012


Very important property
Given a directed graph G = (N, A)
and t wo nodes s, t ∈ N

either there is a path pst

or there is a cut (Ns , Nt ), s ∈ Ns , t ∈ Nt


such that each arc of the cutset is (i, j) : i ∈ Nt , j ∈ Ns

[variant of the Minty coloring lemma]

Friday, September 21, 2012


Renewal plan problem
You are hired for a 5 years job, a car is required and you don’t have one
cost of the mainte selling
age
car nance price
now 12 1 cost
2 7
+1yr 13 2 4 6
+2yrs 14 3 5 3
+3yrs 15 4 9 2
+4yrs 16 5 11 1

When to buy and sell a car?

Friday, September 21, 2012


Shortest path problem
Given a directed graph G = (N, A)
with costs cij , ∀(i, j) ∈ A
and t wo nodes s, t ∈ N

find the (elementary) path


!
p from s to t
minimizing cij
(i,j)∈p

Friday, September 21, 2012


“Analogical” computer
A 5

B
5
3
10
7
C
15
4
D
6 3 F

Friday, September 21, 2012


Shortest Path Tree (SPT)
Given a directed graph G = (N, A)
with costs cij , ∀(i, j) ∈ A
and one node (root) r ∈ N

find the collection of all shortest paths paths from r

Why is it a tree?

Friday, September 21, 2012


When G is acyclic
C 2
4 A E

1 4
0
1 3

2 G
B
D
6

10 3 10

How can we check that there are no cycles?

Topological order
(i, j) ∈ A ⇒ i < j

Friday, September 21, 2012


When G is acyclic2
4
1 2
4 3 4
0
1 4
0
1 3

2 7 6
2
5
6
1 4

10 3 10

6
7

Length of the shortest path from 1 to 1: d[1] = 0


Inductive rule
d[i] = min{d[j] + cji : (j, i) ∈ BS(i)}

Note that j < i


Friday, September 21, 2012
SPT_Acyclic(G, P, d)
for i←2,…,n do P[i]←0; d[i]←+∞;

P[1]←1; d[1]←0;
for i←1,…,n-1 do
foreach (i,j) ∈ FS(i) do
if d[i]+cij < d[j] then P[j]← i
d[j] ← d[i]+cij

Friday, September 21, 2012


Project planning: home construction
activity description time Precedences
A foundations 7
E →D, G
doors and
B
windows frames
2 A, B →E
C floors 15 D, G →F
D tubes 8 G →H
E walls 10
C, F →I
F ceiling 2
I →J
G roof 5

H doors and 8
windows
I wiring 2
J paint 3

Plan (sequence) the activities so that the completion time is minimized

Friday, September 21, 2012


Solve the!knapsack problem
max ci xi
!
i=1,...,n
ai xi ≤ b
i=1,...,n
xi ∈ {0, 1} i = 1, . . . , n
Consider the objects in some order
Construct a state graph representing feasible decisions
last considered node i, k weight currently in the knapsack

0 discard object i
i − 1, k i, k

ci
i, k + ai select object i

The graph is acyclic: what is the size?


Friday, September 21, 2012
When G is not acyclic
Advantages of SPT_Acyclic algorithm:
nodes (and arcs) are examined only once according to the order
when a node i is considered d[i] has the final value

How can we maintain this behavior if G is no more acyclic?


Hypothesis:
cij ≥ 0, ∀(i, j) ∈ A

Friday, September 21, 2012


SPT_Dijkstra(G, r, P, d)
for i ∈ N do P[i]←0 d[i]←+∞;

P[r]←r; d[r]←0; Q←{r};


repeat
selectiifrom
select fromQ;Q Q←Q\{i};
with minimum d[i]; Q←Q\{i};
foreach (i,j) ∈ FS(i) do
if d[i]+cij < d[j] then P[j]← i
d[j] ← d[i]+cij
Q←Q∪{j}
until Q=∅

Friday, September 21, 2012


Dijkstra (1930-2002)
applet for generating and solving problems

http://www.dgp.toronto.edu/people/JamesStewart/
270/9798s/Laffra/DijkstraApplet.html

Dijstra home page with his original slides

http://www.cs.utexas.edu/users/EWD/

Friday, September 21, 2012


Graphs with cycles and negative costs
4
2 5
2 4

-10
-6
1 -2 4 6

3
-5
3 4
3

Warning
What happens to Dijkstra algorithm with negative cost cycles?
What happens if we apply it to a graph without negative cost
cycles but with some negative cost arcs?

Friday, September 21, 2012


SPT_Label_Correcting(G, r, P, d)
for i ∈ N do P[i]←0 d[i]←+∞;

P[r]←r; d[r]←0; Q←{r};


repeat
selectiifrom
select fromQQwith
withminimum
FIFO policy;
d[i]; Q←Q\{i};
foreach (i,j) ∈ FS(i) do
if d[i]+cij < d[j] then P[j]← i
d[j] ← d[i]+cij
Q←Q∪{j}
until Q=∅

Friday, September 21, 2012


How to detect negative cost cycles
From the complexity analysis we know that a node cannot be
inserted into Q more than n-1 times

If a node is inserted n times

negative cost cycle

How do we identify it?

Friday, September 21, 2012

You might also like