Home > Back-end >  . Critical path [problem description] an AOE - known network (edge said activities of the network, t
. Critical path [problem description] an AOE - known network (edge said activities of the network, t

Time:09-22

#include
#include
#include
#include
9////# define PROJECTNUMBER 10
////# define PLANNUMBER 11 of 13
Typedef struct node
{
Int adjvex;
Int the dut;
Struct node * next;
} edgenode;
Typedef struct
{
Int the projectname;
Int id;
Edgenode * link;
} vexnode;
//vexnode Graphicmap [PROJECTNUMBER];
Void CreateGraphic (vexnode * Graphicmap, int projectnumber, int activenumber)
{
Int the begin and end, duttem, k, I;
Edgenode * p;
for( i=0; i{
Graphicmap [I] projectname=I;
Graphicmap [I]. Id=0;
Graphicmap [I] the link=NULL;
}
Printf (" the beginning of a project to the end node in the graph input & lt; Vi, vj, dut> \n");
Printf (" such as: 3,4,9 carriage return between nodes said the third to the fourth activity with the nine per unit time \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
For (k=0; K{
The scanf (" % d, % d, % d ", & amp; The begin, & amp; End, & amp; Duttem);
P=(edgenode *) malloc (sizeof (edgenode));
P - & gt; Adjvex=end - 1;
P - & gt; Dut=duttem;
Graphicmap [end - 1]. Id + +;
P - & gt; Next=Graphicmap [the begin - 1]. The link;
Graphicmap [the begin - 1]. The link=p;
}
}
Int SearchMapPath (vexnode * Graphicmap, int projectnumber, int activenumber, int totaltime)
{
Int I, j, k, m=0;
Int front=1, rear=1;
Int * topologystack=(int *) malloc (projectnumber * sizeof (int));//is used to store the topological arrangement
Int * vl=(int *) malloc (projectnumber * sizeof (int));//used to indicate on the premise of not to delay the whole project, VJ allowed to happen at the latest time
Int * ve=(int *) malloc (projectnumber * sizeof (int));//used to represent Vj first time
Int * l=(int *) malloc (activenumber * sizeof (int));//used to represent activity Ai completed the latest start time
Int * e=(int *) malloc (activenumber * sizeof (int)); The earliest start time//said activity
Edgenode * p;
Totaltime=0;
for(i=0; ifor(i=0; i{
If (Graphicmap [I] id==0)
{
Topologystack [+ + rear]=I;
M++;
}
}
While (front!=rear)
{
Front++;
J=topologystack (front),
M++;
P=Graphicmap [j]. The link;
While (p)
{
K=p - & gt; Adjvex;
Graphicmap [k]. Id -;
If (ve [j] + p - & gt; Dut & gt; Ve [k])
Ve [k]=ve [j] + p - & gt; Dut.
If (Graphicmap [k]. Id==0)
Topologystack [+ + rear]=k;
P=p - & gt; Next;
}
}
If (m{
Printf (" \ n this procedure established figure circuit not to calculate the critical path \ n ");
Printf (" will exit the program \ n ");
return 0;
}
Totaltime=ve [projectnumber - 1);
for(i=0; iVl [I]=totaltime;
For (I=projectnumber - 2; I>=0; I -)
{
J=topologystack [I];
P=Graphicmap [j]. The link;
While (p)
{
K=p - & gt; Adjvex;
If ((vl [k] - p - & gt; Dut) & lt; Vl [j])
Vl [j]=vl [k] - p - & gt; Dut.
P=p - & gt; Next;
}
}
i=0;
Printf (" | | starting point at the end of the earliest start time | | | the latest finish time difference note | | \ n ");
for(j=0; j{
P=Graphicmap [j]. The link;
While (p)
{
K=p - & gt; Adjvex;
E [+ + I]=ve [j];
L=vl [I] [k] - p - & gt; Dut.
Printf (" 4 d | | | % 4 d % % 4 d to 4 d | | % % 4 d | ", Graphicmap [j]. J projectname + 1, Graphicmap [k]. Projectname + 1, [I], e l [I], [I] - [I] e l);
If (l==e [I] [I])
Printf (" | "key activities);
printf("\n");
P=p - & gt; Next;
}
}
return 1;
}
Void seekkeyroot ()
{
Int projectnumber, activenumber, totaltime=0;
System (" CLS ");
Printf (" please input the project into a number of nodes in the graph: ");
The scanf (" % d ", & amp; Projectnumber);
printf("\n");
Printf (" please enter the number of the project activity: ");
The scanf (" % d ", & amp; Activenumber);
printf("\n");
Vexnode * Graphicmap=(vexnode *) malloc (projectnumber * sizeof (vexnode));
CreateGraphic (Graphicmap projectnumber, activenumber);
SearchMapPath (Graphicmap projectnumber, activenumber, totaltime);
Printf (" used in the shortest time for the whole project: % d \ n units of time ", totaltime);
system("pause");
}
Int main ()
{

Char ch;
int i;
For (;; )
{
Do
{
System (" CLS ");
Printf (" | | welcome to beg the critical path algorithm program ");
for( i=0; i<80; I++) printf (" * ");
printf("\n");
Printf (" % s ", "(s) tart to input node data of engineering and the critical path \ n");
printf("\n");
Printf (" % s ", "(E) xit exit \ n");
printf("\n");
Printf (" % s ", "please enter a choice:");
The scanf (" % c ", & amp; Ch);
Ch=toupper (ch);
If (ch!='S' & amp; & Ch! )
='E'Printf (" please enter the correct characters! \n");
system("pause");
} while (ch!='S' & amp; & Ch!='E');
The switch (ch)
{
In case the 'S' :
Seekkeyroot ();
break;
Case 'E' :
return 1;
}
}
}
  • Related