10.- Graph Algorithms
description
Transcript of 10.- Graph Algorithms
10.- Graph Algorithms
Centro de Investigación y Estudios Avanzados del Instituto Politécnico Nacional
• Introduction• Routing Algorithms
• Computation of Shortest Path• Distance Vector Routing• Link-State Routing• Interval Routing
Sistemas Distribuidos
Jorge Antonio Perez Espinoza
Graph
Graph G:G = (V, E)V = Set of nodes 0….N-1.E = Set of edges representing links: (A,B),(A,C)
• Each edge w(i, j) has a weight.
A B
EC D
24
1
3
1
5
Graphs on Distributed System
• The topology of a distributed system is represented by a graph where the nodes represent processes, and the links represent communication channels.
• Static vs. Dynamic Topology.
A B
EC D
24
1
3
1
5
ROUTING ALGORITHMS • Routing is a fundamental problem in networks.
• Discover and maintain an acyclic path from the source of a message to its destination.
• The routing table is updated when the topology changes.
• A path can have many attributes: hops, delay.
COMPUTATION OF SHORTEST PATHGiven a graph G:G = (V, E)V = Set of nodes 0….N-1.E = Set of edges representing links.• Each edge w(i, j) has a weight.
The topology is static.A B
EC D
24
1
3
1
1
Chandy and Misra Algorithm• A refinement of the Bellman-Ford Algorithm.
• Designed to work with a single initiator node 0.
• D(i): Distance to node 0
• Each node knows the weights of all edges incident on it.
Initially :D(0) = 0∀i : i > 0 : D(i) = ∞.
N0
N1
N2
N4
N4
N54
6
51
2 3
3
For each node:• 1. D, the current shortest distance of node 0 to itself. Initially
D(0) = 0, D(i: i > 0) = ∞
• 2. A node called parent: Initially parent (j) = j
• 3. A variable deficit, representing the number of unacknowledged messages. Initially deficit=0.
N0
N1
N2
N4
N4
N54
6
51
2 3
3
program shortest path {for process i >0};
define D, S : distance;{S denotes the shortest distance received through a message}parent : processdeficit : integer;N: set of neighbors of process i;
initially D= ∞, parent = i, deficit = 0
{for process 0}send (w(0,i), 0) to each neighbor i;deficit := |N(0)|;do ack -> deficit := deficit – 1 od;{deficit = 0 signals termination}
{for process i > 0}do message = (S ,k) ^ S < D if parent ≠ k or i -> send ack to parent fi;
parent := k; D := S; send (D + w(i,j), i) to each neighbor j ≠ parent;
deficit := deficit + |N(i)| -1message (S,k) ^ S ≥ D -> send ack to senderack -> deficit := deficit – 1deficit = 0 ^ parent ≠ i -> send ack to the parentod
N0
N1
N2
N4
N4
N54
6
51
2 3
3
Example
Lemma :• When the algorithm terminates, let k = parent (i). If D(k) is the
distance of the shortest path from k to 0, then D(i) = D(k) + w(k, i) is the distance of the shortest path from i to 0 and the shortest path includes k.
• Proof: Suppose this is false :The shortest path from 0 to i is via j , where j ≠ k.
Message D(i)>D(j)+w(j,i).
Message D(i)>D(k)+w(k,i).
iK 0
j
11
22
DISTANCE VECTOR ROUTING
Shortest path routing, but handles topology changes.Routing Table
Destination NextHop DistanceD[i, j] = 0 when i = j,= 1 when j is a neighbor of i, and
= ∞ when i = j and j is not a neighbor of i
∀k ≠ i :D[i,k]=minj(w[i,j]+D[j,k])
Each node j periodically broadcasts its distance vector to its immediate neighbors
DISTANCE VECTOR ROUTING
RT- U
X X 1
Y X 2
V V ∞
Following this, the distance vectorsare corrected, and routing table is eventually recomputed.
Count to Infinity Problem
A B C D E1 1 1 1
1.- Node A. -> B(A,A,1)2.- Node B. -> C(A,B,2)3.- Node C. -> B(A,C,3)4.- Node B. -> C(A,B,4)5.- Node C. -> B(A,C,5)....
Split Horizont Method
A B C D E1 1 1 1
LINK-STATE ROUTING• This is an alternative method of shortest path routing.• Converges faster.• Each node i periodically broadcasts the weights of all edges (i,j)
incident on it (this is the link state) to all its neighbors
Link State Protocol
INTERVAL ROUTING• Consider a connected network of N nodes.• The conventional routing table used to route a message from
one node to another has N − 1 entries, one for each destination node.
EntryDestination # Port
13 Entries
Can we do something to reduce the growth ofthe routing tables?
EntryDestination # Port
??????
Interval routing• Santoro and Khatib first proposed interval routing for tree
topologies only.• Each node has two ports:• port 0 is connected to the node with a higher id.• port 1 is connected with the node of lower id
Interval Routing• For a set of N nodes 0 ….N − 1, define the interval [p, q) between
a pair of p and q as follows:• if p < q then [p,q) = p, p + 1, p + 2 , . . ., q − 2, q − 1• if p ≥ q then [p, q) = p, p + 1, p + 2, . . .,N − 1, 0, 1, . . ., q − 2, q − 1
As an example, if N = 8, then [5, 5) = 5, 6, 7, 0, 1, 2, 3, 4.
Routing for a tree Network
1. Label the root as node 0.2. Do a preorder traversal of the tree, and label the successive nodes in ascending order starting from 1.3. For each node, label the port towards a child by the node number of the child. Then labelthe port towards the parent by L(i) + T(i) + 1 mod N, where
• L(i) is the label of the node i• T(i) is the number of nodes in the subtree under node i (excluding i)
Subtree under i: L(i),L(i)+T(i) + 1 mod N)Comp: [L(i)+T(i)+1 mod N,L(i))
Adaptation to changes in the topology .• Every time a new node is added to a network, or an existing
node is removed from the network, in general all node labels and port labels have to be recomputed.
Prefix Routing
if X = Y → Deliver the message locally X = Y → Find the port with the longest prefix of X as its label; Forward the message towards that portfi