当前位置:网站首页>AOE网关键路径
AOE网关键路径
2022-06-10 17:21:00 【ScarboroughFair#】
目录
1.概念


四个需要的变量



求关键路径的步骤

由e(i) = ve(j) I(i) = vl(k)-w (w为j活动到k活动的权值)

2.关键路径算法的实现

int *etv, *ltv; //事件最早发生时间和最迟发生时间数组
int *stack2; //用于存储拓扑序列的栈
int top2; //用于stack2的指针其中stack2用来存储拓扑序列,以便后面求关键路径时使用。下面是改进过的求拓扑序列算法
Status TopologicalSort(GraphAdjList GL)
{
EdgeNode* e;
int i, k, gettop;
int top = 0; //用于栈指针下标
int count = 0; //用于统计输出顶点个数
int* stack; //建栈将入度为0的顶点入栈
stack = (int*)malloc(GL->numVertexes * sizeof(int));
for (i = 0; i < GL->numVertexes; i++)
if (0 == GL->adjList[i].in)
stack[++top] = i;
top2 = 0; //初始化为0##
etv=(int*)malloc(GL->numVertexes * sizeof(int));//事件最早发生时间##
for (i = 0; i < GL->numVertexes; i++)//##
etc[i] = 0; //初始化为0 //##
stack2 = (int*)malloc(GL->numVertexes * sizeof(int));//初始化//##
while (top != 0)
{
gettop = stack[top--];
count++;
stack2[++top2] = gettop; //将弹出的顶点序号压入拓扑排序的栈//##
for (e = GL->adjList[gettop].firstedge; e; e = e->next)
{
k = e->adjvex;
if (!(--GL->adjList[k].in))
stack[++top] = k;
if ((etv[gettop] + e->weight) > etv[k])//求各顶点事件最早发生时间值//##
etv[k] = etv[gettop] + e->weight; //##
}
}
if (count < GL->numVertexes)
return ERROR;
else
return OK;
}下面指代的加粗的部分即为上述代码中注释加上##的部分

下面展示关键路径的算法代码
//求关键路径,GL为有向网,输出GL的各项关键活动
void CriticalPath(GraphAdjList GL)
{
EdgeNode* e;
int i, gettop, k, j;
int ete, lte; //声明活动最早发生时间和最迟发生时间变量
TopologicalSort(GL); //求拓扑排序,计算数组etv和stack2的值
ltv = (int*)malloc(GL->numVertexes * sizeof(int)); //事件最晚发生时间
for (i = 0; i < GL->numVertexes; i++)
ltv[i] = etv[GL->numVertexes - 1]; //初始化ltv
while (top2 != 0) //计算ltv
{
gettop = stack2[top2--]; //将拓扑序列出栈,后进先出
for(e = GL->adjList[gettop].firstedge; e; e = e->next)
{
//求各顶点事件的最迟发生时间ltv值
k = e->adjvex;
if (ltv[k] - e->weight < ltv[gettop]) //求各顶点事件最晚发生时间ltv
ltv[gettop] = ltv[k] - e->weight;
}
for (j = 0; j < GL->numVertexes; j++)
{
for (e = GL->adjList[j].firstedge; e; e = e->next)
{
k = e->adjvex;
ete = etv[j]; //活动最早发生时间
lte = ltv[k] - e->weight; //活动最迟发生时间
if (ete == lte) //两者相等即在关键路径上
printf("<v%d,v%d> length: %d , ",
GL->adjList[j].data, GL->adjList[k].data, e->weight);
}
}
}
边栏推荐
猜你喜欢

Canvas fire burning H5 animation JS special effects

High number_ Chapter 6 infinite series__ Absolute convergence_ Conditional convergence

Red vertical left side menu navigation code

PCA主成分分析教程(origin分析&绘制,无须R语言)
![[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language](/img/53/d6f05e8050e27dc9d59f1196753512.png)
[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language

Swift 3pThread tool Promise Pipeline Master/Slave Serial Thread confinement Serial queue

LeetCode树经典题目(一)

There is an urgent need to enrich the smart home product line. Can fluorite be crowded on the sweeping robot track?

使用Canvas实现的噪音线条h5js特效

Nacos configuration management
随机推荐
元宇宙的定义和 7 大无限特征
Unity踩坑记录:如果继承MonoBehaviour,类的构造函数可能会被Unity调用多次,不要在构造函数做初始化工作
信息学奥赛一本通 1280:【例9.24】滑雪 | OpenJudge NOI 2.6 90:滑雪 | 洛谷 P1434 [SHOI2002] 滑雪
JS special effect of canvas divergent particle H5 animation
Nacos注册中心
PMP考生,深圳2022年6月PMP考试地点有这些
高数_第6章无穷级数__绝对收敛_条件收敛
电商行业转账返款方案分析
线性移动棋
The short ticket hypothesis: finding sparse, trainable neural networks
CDGA|工业企业进行数据治理的六个关键点
Draw confusion matrix
pands pd. Detailed parsing of dataframe() function
Leetcode 875. Coco, who likes bananas
yml文件配置参数定义字典和列表
LoRa模块无线收发通信技术详解
企鹅电竞停步,虎牙也难行
Snabbdom 虚拟 dom(一)
CUDA实现高效查找--审核未通过?
为什么 0.1+0.2=0.30000000000000004