当前位置:网站首页>关键路径
关键路径
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 );
}
}
}
}
边栏推荐
- Focal and global knowledge distillation for detectors
- Array objects can be compared one by one (the original data with the same index and ID will be retained, and the data not in the original array will be added from the default list)
- [dry goods | necessary skills for interface testing common interface protocol analysis]
- 第一章 力扣热题100道(1-5)
- C WinForm embedded flash
- delegate
- Canvas picture frame
- 84. (cesium chapter) movement of cesium model on terrain
- 修改隐含参数造成SQL性能下降案例之二
- Recommend an anatomy website
猜你喜欢

Service practice: use service to complete a download task

Shell script explanation (IV) -- while loop and until loop of loop statements (additional examples and analysis)

Creator mode summary

远程访问及控制——SSH远程管理及TCP Wrappers 访问控制

华为云招募工业智能领域合作伙伴,强力扶持+商业变现

A homekit enabled camera? Zhiting IPC camera IC1 unpacking experience

3D打印机耗材受潮

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

0.1----- process of drawing PCB with AD

Agent model of structured model
随机推荐
Adapter mode of structural mode
K8s deploy MySQL
Follow up course supplement of little turtle teacher "take you to learn C and take you to fly"
将一维数据(序列)转化为二维数据(图像)的方法汇总GAFS, MTF, Recurrence plot,STFT
Modify the antd tree component so that its subclasses are arranged horizontally.
1.2-----机械设计工具(CAD软件)和硬件设计工具(EDA软件)及对比
修改antd tree组件,使其子类横向排列。
自定义控件AutoScaleMode为Font造成宽度增加的问题
Shell script explanation (VII) -- regular expression, sort, uniq, tr
Canvas picture frame
Interface development component devaxpress asp Net core v21.2 - UI component enhancements
NAND闪存(NAND Flash)颗粒SLC,MLC,TLC,QLC的对比
84.(cesium篇)cesium模型在地形上运动
从11小时到25秒--还有优化空间吗?
vim中快速缩进用法
数组对象根据id一 一对应填入(将arr1填入arr2中)
Wavelet transform DB4 for four layer decomposition and signal reconstruction matlab analysis and C language implementation
0.0 - how can SolidWorks be uninstalled cleanly?
canvas给图片画框框
数字货币钱包开发不知道怎么选?