Summary of Topology sequencing

Source: Internet
Author: User

AOV Network and topology sequencing

㈠aov Network Concept

in a direction graph, if a vertex is used to represent an activity, there is a direction to indicate the activity order, which is called the graph as the vertex of the active network, referred to as AoV net. In the AOV network, if there is a forward path from vertex i to Vertex J, the vertex i is the precursor of the vertex J, or the vertex J is the successor of vertex I. If is the edge in the graph, then I is the direct precursor of J, and J is the direct successor of I.

the practical significance of ㈡aov net

in a large project, often divided into many smaller sub-projects, in the entire project implementation process, some activities start with all of its pre-order activities to end as a prerequisite, while others have no prerequisites, can be scheduled at any time to start. AoV Network is an image of the whole project to reflect the relationship between the front and back of the map.

㈢ Topology Ordering

In the graph g= (v,e), for a linear sequence of vertices in V, if there is a path from Vertex VI to VJ in G, then VI must precede VJ in the sequence, calling the sequence a topological sequence of G. The process of constructing a topological sequence of a forward graph is called topological ordering.

Description:

⑴ in the AOV network, if there is no loop, all activities can be lined up in a linear sequence so that all precursor activities of each activity are in front of the activity, then the sequence is called the topological sequence.

The ⑵ topology sequence is not unique.

The ⑶aov network does not necessarily have a topological sequence. AoV network can not appear in the direction of the loop (or have Shang), if there is a forward ring, it means that an activity to itself as a precondition, this is not right, the project will not be carried out. The program will show a dead loop. Therefore, for a given AOV network, it should be judged whether there is a forward ring. The judging method is to aov the network topology, if the sequence contains all the vertices of the AOV network, there is no ring, otherwise there is a forward ring, the network represents the project is not feasible.

The practical meaning of ⑷ topological ordering is that if each activity is carried out according to the vertex order of the topological sequence, all of its precursor activities are completed when each activity is carried out, so that the project can be executed smoothly.

㈣ topology sequencing algorithm steps

⑴ selects a vertex with a degree of 0 in the AOV Network (no precursor) and outputs it;

⑵ Delete this vertex and all the forward edges emitted by the vertex in the AOV net;

⑶ repeats the ⑴, ⑵ two steps until all vertices in the AOV network are output or do not have a point with an entry level of 0.

Reference code:

Code one, two-dimensional number formation diagram;

#include <stdio.h> #include <string.h>int map[1010][1010];int indegree[1010];int ans[1010];void toposort ( int n) {for (int i=1;i<=n;i++)//lookup for each point {int j=1;while (INDEGREE[J])//From small to large find to no precursor j++;ans[i]=j;//stored in the array, can also directly output the The indegree[j]=-1;//is recorded as-1, preventing the re-lookup to the for (int k=1;k<=n;k++)//update the point associated with the found point of the precursor if (map[j][k]) indegree[k]--;} int main () {int n,m;//has n points, M-Bars while (scanf ("%d%d", &n,&m)!=eof) {memset (map,0,sizeof (map));//Initialize memset ( Indegree,0,sizeof (Indegree)), for (int i=0;i<m;i++) {int p1,p2;scanf ("%d%d", &P1,&P2), if (!MAP[P1][P2])// The redo operation {indegree[p2]++;//stores P2 precursor value MAP[P1][P2]=1;//P2 is P1, Mark}}toposort (n); for (int i=1;i<n;i++)// The ANS array holds a topological sequence of printf ("%d", Ans[i]);p rintf ("%d\n", Ans[n]);} return 0;}


code two, chain-built diagram;

#include <stdio.h> #include <string.h>int head[5100];int indegree[5100];int ans[5100];struct node{int to; int next;} a[5100];void toposort (int n) {for (int i=1;i<=n;i++) {int j=1;while (indegree[j]) j++;ans[i]=j;indegree[j]=-1;for ( int k=head[j];k!=-1;k=a[k].next) {indegree[a[k].to]--;}}} int main () {int n,m;while (scanf ("%d%d", &n,&m)!=eof) {memset (head,-1,sizeof (head)); Memset (indegree,0,sizeof (Indegree)); for (int i=1;i<=m;i++) {int p1,p2;scanf ("%d%d", &p1,&p2); a[i].to=p2;a[i].next=head[p1];head[p1]=i; indegree[p2]++;} Toposort (n); for (int i=1;i<n;i++) printf ("%d", Ans[i]);p rintf ("%d\n", Ans[n]);} return 0;}


Code three, queue implementation;

#include <stdio.h> #include <string.h> #include <queue>using namespace Std;int degree[5100];int map[ 510][510];void toposort (int n) {priority_queue<int,vector<int>,greater<int> >q;for (int i=1;i<= n;i++) if (degree[i]==0) Q.push (i); int flag=1;while (!q.empty ()) {int top=q.top (); Q.pop ();d egree[top]=-1;if (flag) printf ("%d", top), elseprintf ("%d", top), flag=0;for (int j=1;j<=n;j++) if (Map[top][j]) {degree[j]--;if (degree[j]== 0) {Q.push (j);}}} printf ("\ n");} int main () {int n,m,p1,p2;while (scanf ("%d%d", &n,&m)!=eof) {memset (map,0,sizeof (map)); Memset (degree,0, sizeof (degree)), for (int i=0;i<m;i++) {scanf ("%d%d", &P1,&P2), if (map[p1][p2]==0) {map[p1][p2]=1;degree[ p2]++;}} Toposort (n);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Summary of 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.