当前位置:网站首页>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);
}
}
}
边栏推荐
- There is an urgent need to enrich the smart home product line. Can fluorite be crowded on the sweeping robot track?
- 力扣 20. 有效的括号
- IIS installation and deployment web site
- yml文件配置参数定义字典和列表
- 红色垂直左侧边菜单导航代码
- sense of security
- protoc-gen-go-grpc‘不是内部或外部命令,也不是可运行的程序 或批处理文件
- .NET 开源的免费午餐结束了?
- Canvas大火燃烧h5动画js特效
- pands pd. Detailed parsing of dataframe() function
猜你喜欢

《华为数据之道》读书笔记

Gateway服务网关

红色垂直左侧边菜单导航代码

PCA主成分分析教程(origin分析&绘制,无须R语言)

JS special effect of canvas divergent particle H5 animation

亟需丰富智能家居产品线,扫地机器人赛道上挤得下萤石吗?

High number_ Chapter 6 infinite series__ Properties of positive series

Mapbox GL development tutorial (11): loading line layers

PCA principal component analysis tutorial (origin analysis & drawing, without R language)

掌握高性能计算前,我们先了解一下它的历史
随机推荐
PMP考生,深圳2022年6月PMP考试地点有这些
LoRa模块无线收发通信技术详解
canvas发散的粒子h5动画js特效
Classic topics of leetcode tree (I)
IIS安装 部署网站
Wireshark学习笔记(一)常用功能案例和技巧
牛客网:表达式求值
[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language
Leetcode 929. 独特的电子邮件地址
Lifeifei: I am more like a scientist in physics than an engineer
mapbox-gl开发教程(十一):加载线图层
Canvas fire burning H5 animation JS special effects
线性移动棋
2022版IDEA图形界面GUI乱码解决方法超详细简单版
Feign based remote call
Gateway服务网关
聊聊消息中间件(1),AMQP那些事儿
OpenJudge NOI 1.13 15:求序列中的众数
红色垂直左侧边菜单导航代码
numpy——记录