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

详解openGauss多线程架构启动过程

记可视化项目代码设计的心路历程以及理解

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

How to use yincan IS903 to master DIY's own USB flash disk? (good items for practicing BGA welding)

0.1-----用AD画PCB的流程

A homekit enabled camera? Zhiting IPC camera IC1 unpacking experience

实验七 触发器

Common technical notes

Chapter I 100 hot questions (1-5)

Recommend an anatomy website
随机推荐
结构型模式之代理模式
Shell script explanation (IV) -- while loop and until loop of loop statements (additional examples and analysis)
Teachers, I want to ask you a question. I run flinkcdc locally to synchronize MySQL data. The timestamp field parsing is normal,
使用 Order by 与 rownum SQL 优化案例一则
lua--数据类型、变量、循环、函数、运算符的使用
小甲鱼老师《带你学C带你飞》的后续课程补充
MySQL数据库DQL查询操作
Calendar control programming
Weizhi technology appeared in the Western Digital Expo, and the space-time AI technology was highly recognized
Do you use thread or service?
Altium Designer中off grid pin解决方法
C#,入门教程——关于函数参数ref的一点知识与源程序
Shell script explanation (VII) -- regular expression, sort, uniq, tr
Nrf51822 peripheral learning
0.0 - Solidworks如何才能卸载干净?
How to judge whether text is an array in the slot
Openpnp调试 ------ 0816飞达推0402编带
Digital supply chain centralized purchase platform solution for mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
Problems of different renderers running on the web with flutter2.0
给对象赋值