当前位置:网站首页>关键路径
关键路径
2022-06-22 18:28:00 【单单一个越字】
B站小甲鱼视频
https://www.bilibili.com/video/BV1jW411K7yg?p=69
– etv(Earliest Time Of Vertex):事件最早发生时间,就是顶点的最早发生时间;
– ltv(Latest Time Of Vertex):事件最晚发生时间,就是每个顶点对应的事件最晚需要开始的时间,如果超出此时间将会延误整个工期。
– ete(Earliest Time Of Edge):活动的最早开工时间,就是弧的最早发生时间。
– lte(Latest Time Of Edge):活动的最晚发生时间,就是不推迟工期的最晚开工时间。

etv和ete都是从源点向汇点推算;
ltv和lte都是从汇点向源点推算;

邻接表:
关键路径代码:
// 边表结点声明
typedef struct EdgeNode
{
int adjvex;
struct EdgeNode *next;
}EdgeNode;
// 顶点表结点声明
typedef struct VertexNode
{
int in; // 顶点入度
int data;
EdgeNode *firstedge;
}VertexNode, AdjList[MAXVEX];
typedef struct
{
AdjList adjList;
int numVertexes, numEdges;
}graphAdjList, *GraphAdjList;
int *etv, *ltv;
int *stack2; // 用于存储拓扑序列的栈
int top2; // 用于stack2的栈顶指针
// 拓扑排序算法
// 若GL无回路,则输出拓扑排序序列并返回OK,否则返回ERROR
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; // 将度为0的顶点下标入栈
}
}
// 初始化etv都为0
top2 = 0;
etv = (int *)malloc(GL->numVertexes*sizeof(int));
for( i=0; i < GL->numVertexes; i++ )
{
etv[i] = 0;
}
stack2 = (int *)malloc(GL->numVertexes*sizeof(int));
while( 0 != top )
{
gettop = stack[top--]; // 出栈
// printf("%d -> ", GL->adjList[gettop].data);
stack2[++top2] = gettop; // 保存拓扑序列顺序 C1 C2 C3 C4 .... C9
count++;
for( e=GL->adjList[gettop].firstedge; e; e=e->next )
{
k = e->adjvex;
// 注意:下边这个if条件是分析整个程序的要点!
// 将k号顶点邻接点的入度-1,因为他的前驱已经消除
// 接着判断-1后入度是否为0,如果为0则也入栈
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 ) // 如果count小于顶点数,说明存在环
{
return ERROR;
}
else
{
return OK;
}
}
// 求关键路径,GL为有向图,输出GL的各项关键活动
void CriticalPath(GraphAdjList GL)
{
EdgeNode *e;
int i, gettop, k, j;
int ete, lte;
// 调用改进后的拓扑排序,求出etv和stack2的值
TopologicalSort(GL);
// 初始化ltv都为汇点的时间
ltv = (int *)malloc(GL->numVertexes*sizeof(int));
for( i=0; i < GL->numVertexes; i++ )
{
ltv[i] = etv[GL->numVertexes-1];
}
// 从汇点倒过来逐个计算ltv
while( 0 != top2 )
{
gettop = stack2[top2--]; // 注意,第一个出栈是汇点
for( e=GL->adjList[gettop].firstedge; e; e=e->next )
{
k = e->adjvex;
if( (ltv[k] - e->weight) < ltv[gettop] )
{
ltv[gettop] = ltv[k] - e->weight;
}
}
}
// 通过etv和ltv求ete和lte
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 );
}
}
}
}
边栏推荐
- lua--迭代器、模块、元表
- Div horizontal layout
- Digital commerce cloud: analyze the design idea of B2B2C multi-user mall system architecture, and open a new era of intelligent mall
- 51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
- 数字货币钱包开发不知道怎么选?
- mini-Web框架:模板替换与路由列表功能开发 | 黑马程序员
- Some problem records of openpnp using process
- 从11小时到25秒--还有优化空间吗?
- [dry goods | necessary skills for interface testing common interface protocol analysis]
- 1.2----- mechanical design tools (CAD software) and hardware design tools (EDA software) and comparison
猜你喜欢

Chapter I 100 hot questions (1-5)

实验4 NoSQL和关系数据库的操作比较

Altium Designer中off grid pin解决方法

1.3-----Simplify 3D切片软件简单设置

【干货|接口测试必备技能-常见接口协议解析】

Creator mode summary

将一维数据(序列)转化为二维数据(图像)的方法汇总GAFS, MTF, Recurrence plot,STFT

深入浅出聊布隆过滤器(Bloom Filter)

Digital enabling machinery manufacturing industry, supply chain collaborative management system solution helps enterprises upgrade their supply chain

Solution of off grid pin in Altium Designer
随机推荐
产品几何技术规范(GPS) 线性尺寸公差ISO代号体系
[nfs无法挂载问题] mount.nfs: access denied by server while mounting localhost:/data/dev/mysql
修改隐含参数造成SQL性能下降案例之一
Xintang nuc980 usage record: basic description of development environment preparation and compilation configuration
Solution of off grid pin in Altium Designer
51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
Do you use thread or service?
510000 prize pool invites you to join the war! The second Alibaba cloud ECS cloudbuild developer competition is coming
再谈SQL profile : 到底能不能固定执行计划?
lua--迭代器、模块、元表
推荐一个解剖学网站
1.3-----Simplify 3D切片软件简单设置
从11小时到25秒--还有优化空间吗?
如何用银灿IS903主控DIY自己的U盘?(练习BGA焊接的好项目)
Upgrade VS2008 crystal report to the corresponding version of vs2013
误用append案例一则
Digital enabling machinery manufacturing industry, supply chain collaborative management system solution helps enterprises upgrade their supply chain
calendar控件编程
Service practice: use service to complete a download task
编译报错:/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata‘