当前位置:网站首页>关键路径
关键路径
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 );
}
}
}
}
边栏推荐
- 08_ One word sobers you up
- 区间检索SQL性能优化方法
- Xintang nuc980 usage record: basic description of development environment preparation and compilation configuration
- Openpnp debugging ------ 0816 Feida Tui 0402 taping
- Recommend an anatomy website
- Damp 3D printer consumables
- Velocity syntax
- Div horizontal layout
- 再谈SQL profile : 到底能不能固定执行计划?
- 技术管理进阶——你了解成长的全貌吗?
猜你喜欢

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

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

界面开发组件DevExpress ASP.NET Core v21.2 - UI组件增强

Modify the antd tree component so that its subclasses are arranged horizontally.

2. what is mechanical design?

Service practice: use service to complete a download task

1.2-----机械设计工具(CAD软件)和硬件设计工具(EDA软件)及对比

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

0.0 - how can SolidWorks be uninstalled cleanly?

创建者模式大汇总
随机推荐
Follow up course supplement of little turtle teacher "take you to learn C and take you to fly"
About Random Forest
C WinForm embedded flash
Common technical notes
Creator mode summary
小波变换db4进行四层分解及其信号重构—matlab分析及C语言实现
what? Homekit, Micah, aqara and other ecosystems can also be linked with tmall elf ecology through zhiting?
Screw数据库文档生成器
Initial experience of ABAQUS using RSG drawing plug-in
canvas给图片画框框
实践出真知:全网最强秒杀系统架构解密,不是所有的秒杀都是秒杀!!
产品几何技术规范(GPS) 线性尺寸公差ISO代号体系
Focal and global knowledge distillation for detectors
1.4-----PCB设计?(电路设计)确定方案
Decorator mode of structural mode
1.4----- PCB design? (circuit design) determination scheme
Screw database document generator
510000 prize pool invites you to join the war! The second Alibaba cloud ECS cloudbuild developer competition is coming
0.0 - how can SolidWorks be uninstalled cleanly?
Flutter series -dart basic grammar learning