Data Structure-topology sequencing

Source: Internet
Author: User

Application background

Student Elective Course Questions
Vertex--Represents a course
Arc-Indicates a prerequisite, if course I is a prerequisite for course J, the figure has an arc (I,J)
How the students should study these courses in order to complete their studies without contradiction and success--topological sequencing

     拓扑序列是有向无环图中各顶点构成的有序序列。该序列满足如下条件:如果图中一顶点vi到另一顶点vj存在一条路径,那么vj在此图的拓扑排序序列中位于vi之后。
Directed acyclic graph (DAG) and AoV Network

Directed acyclic graph "(Directed acyclic graph, abbreviated DAG
AOV Network (Activity on Vertex Network): A "viable" AOV must be a dag. Otherwise there is a loop in the diagram, so it is not possible to determine which of the activities in the loop is implemented first.
Vertex represents activity,
Arcs represent a priority relationship between activities,
Attention:
The arc in the AOV network indicates that there is some kind of restriction relationship between the activities:

voidToplogicalsort (Graph G,intTopnum[]) {intCounter;/ * Topological sequence number to identify the order of each vertex output * /    intV, W;int*indegree = (int*)malloc(G.N *sizeof(int) ); Getindegree (G, Indegree);/ * Calculate the degrees of each vertex in Figure G * /     for(Counter =0; Counter < G.N; counter++) {v = Findnewvertexofdegreezero ();/ * finds vertices with a degree of 0 and, if found, returns the subscript of the vertex in the vertex array. If no vertex of 0 is found, return-1 */        if(v = =-1) {printf("graph exists loop"); Break; } Topnum[v] = Counter; for(Each adjacency point W for V in G) indegree[w]--;/* The degrees of each vertex connected to vertex v minus 1 */}}
voidToplogicalsort (Graphadjlist GL,int* topnum) {QueueQueue; Edgenode *p;intCounter =0;intV, W;//int *indegree = (int *) malloc (G.N * sizeof (int));   //Getindegree (G, Indegree); /* Calculate the degrees of each vertex in Figure G * /     Queue= Initqueue (gl->numvertexes);/ * Create an empty queue * /      for(v =0; V <GL->numVertexes; v++)if(gl->adjlist[v].in==0) EnQueue (&Queue, v); while( ! Queueempty (Queue) {v = DeQueue (&Queue); TOPNUM[V] = ++counter;/ * Assign vertex topology sort ordinal * /            for(P=gl->adjlist[v].firstedge;p!=null;p=p->next)if(--gl->adjlist[p->adjvex].in = =0) EnQueue (&Queue, P->adjvex); }if(Counter! = gl->numvertexes)printf("diagram exists loop \ n"); Disposequeue (&Queue);/ * Free queue space * /      //free (indegree);}
Critical path
    On Edge) ,是边表示活动的有向无环图。    顶点表示事件(Event),每个事件表示在它之前的活动已完成,在它之后的活动可以开始;    弧表示活动,弧上的权值表示相应活动所需的时间或费用
AOV Network and AOE network

Topological sequencing is mainly to solve the problem of whether a project can be carried out smoothly.
The critical path is the shortest time to solve the project's completion needs.
The difference between AOV network and AOE network:
AoV Network, vertex represents activity, Edge describes the constraint relationship between activities
AoE NET, the weights on the edge indicate the duration of the activity,
Based on the lack of contradiction between activities and the restriction of relations,
Discuss how much time is required to complete the project, or what activities should be speeded up to shorten the time required to complete the project.

Path length-The sum of the duration of each activity on the path
Critical path-path with the maximum path length from the source point to the meeting point
Key activities-activities on critical paths. The key activity is the key that affects the whole project, and the delay affects the activity of the whole duration.
The earliest occurrence time-set V0 is the starting point, the longest path length from V0 to VI is called the earliest occurrence of event VI, that is, the earliest occurrence time of all activities with the tail of VI.

Find critical paths and key activities in AOE

⑴ algorithm Idea
① a topological sequence of AOE network is obtained by using topological sorting.
② begins with the first vertex (source point) of the sequence in which the topology is sorted, and calculates the earliest occurrence of each event in topological order. ve (i);
Starting at the last vertex (sink point) of the sequence in which the topology is sorted, the latest occurrence of each event is calculated in inverse topological order, vl (i);
Find out the earliest occurrence of each activity e (i) and the last occurrence of the time L (e), while the AI's time margin, time margin =0 those activities are key activities.

Shortest path

A transport network is represented by a weighted, forward graph:
Vertex: City
Edge: Inter-city transport links
The length of this line or the time or cost of transportation along this line, etc.
Problem:
Is there a pathway between the two places?
In the case of multiple access roads, which is the shortest one?
The starting vertex of a path is called the source point, and the last vertex is called the end point.

Single source Point Shortest path
对于给定的有向图G=(V,E)及单个源点V0,求V0到G的其余各顶点的最短路径。针对单源点的最短路径问题,Dijkstra提出了一种按路径长度递增次序产生最短路径的算法,即迪杰斯特拉(Dijkstra)算法。
Find the shortest path step

The distance value corresponding to the vertices in the remaining vertex},t at the beginning of the season s={v0},t={
If there is a v0,vi, the weight on the V0,vi arc
If there is no V0, Vi, for?
Select a vertex w with a minimum distance value from T to join S
The distance value of the vertex in T is modified: If a W is added as the middle vertex, the distance value from V0 to VI is shorter than the path without W, then the distance value is modified
Repeat the above steps until the s contains all vertices, i.e. s=v

Algorithm implementation
Graph with weighted adjacency matrix storage
The array dist[] stores the shortest path lengths that are currently found from the source point V0 to each end point, in the middle of which only the vertices in the set S are passed, with the initial state being the direct path weights in the graph
Array pre[] represents the ordinal of the previous vertex of this vertex on the shortest path from V0 to each end point, or 0 as the ordinal of its previous vertex if there is no path from V0 to an end point

Data Structure-topology sequencing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.