=>演算虛擬碼 for ( i = 0; i < n; I ++) { if every vertex has a predecessor { fprintf(stderr, “Network has a cycle, n”) ; exit (1) ; } else { pick a vertex v that has no predecessors; output v ; delete v and all edages leading out of v from the network ; } }
=>演算程式碼 void topological ( int count [ ], int vertex, int link [ ], int n) { int top = 0, i , j , k ; for ( i = 1 ; i <= n ; i ++ ) if ( count [i] = = 0 ) { count [i] = top ; top = i ; }
for ( i = 1 ; i <= n ; i ++) { if ( top = = 0 ) { printf ( “network has a cycle” ); break ; } j = top ; top = count [top] ; printf ( “%d” , j ) ; ptr = link [j] ;
while ( ptr != 0) { k = vertex [ptr] ; count [k] = count [k] – 1; if ( count [k] = = 0 ) { count [k] = top ; top = k ; } ptr = link [ptr] ; } } }
AOE網路 (Activity on Edge Networks)
Ø 由於 1沒有前行者,故輸出V 1計算V 1相鄰頂點 V 2, V 3, V 5的ES: l l l ES(2) = max { ES(2), ES(1) +( 1, 2 ) }=max( 0, 0+3 ) = 3 ES(3) = max { ES(3), ES(1) +( 1, 3 ) }=max( 0, 0+3 ) = 3 ES(5) = max { ES(5), ES(1) +( 1, 5 ) }=max( 0, 0+4 ) = 4 ES 1 0 2 3 3 3 4 0 5 4 6 0 7 0