当前位置:网站首页>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);
}
}
}
边栏推荐
猜你喜欢

One of the Taobao short video pit avoidance Guide Series -- thoroughly understand Taobao short video

com.netflix.client.ClientException: Load balancer does not have available server for client: userser

Canvas fire burning H5 animation JS special effects

Online communication skill network: a sparse model for solving multi task and multi-modal problems (Qingyuan talk, issue 19, tangduyu)

matplotlib plt. Specific usage of text() - labeling points in a drawing

传统企业在进行信息化升级的过程中,如何做好信息化顶层设计

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

Canvas大火燃烧h5动画js特效

C# 根据EXCEL自动生成oracle建表语句

【AXI】解读AXI协议双向握手机制的原理
随机推荐
yml文件配置参数定义字典和列表
CUDA编程(一):实现两个数组相加
Abbexa丙烯酰胺-PEG-NHS说明书
High number_ Chapter 6 infinite series__ Absolute convergence_ Conditional convergence
淘宝短视频避坑指南系列之一--彻底了解淘宝短视频
Canvas fire burning H5 animation JS special effects
软考不通过能不能补考?解答来了
Snabbdom virtual DOM (I)
Play with pytoch's function class
JS blur shadow follow animation JS special effect plug-in
Numpy np set_ Usage of printoptions () -- control output mode
小程序积分商城如何实现营销目的
Nacos注册中心
Abbkine柱式法ExKine Pro动物细胞/组织总蛋白提取试剂盒
Abbexa 细菌基因组 DNA 试剂盒介绍
Jouer avec la classe de fonctions de pytorch
matplotlib plt.text()的具体用法——画图时给图中的点加标签
There is an urgent need to enrich the smart home product line. Can fluorite be crowded on the sweeping robot track?
LeetCode树经典题目(一)
Abbexa 8-OHdG CLIA 试剂盒解决方案