当前位置:网站首页>关键路径
关键路径
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 );
}
}
}
}
边栏推荐
- Upgrade VS2008 crystal report to the corresponding version of vs2013
- Decorator mode of structural mode
- 给对象赋值
- Service practice: use service to complete a download task
- Some problem records of openpnp using process
- Nrf51822 peripheral learning
- Recommend an anatomy website
- 记可视化项目代码设计的心路历程以及理解
- [nfs无法挂载问题] mount.nfs: access denied by server while mounting localhost:/data/dev/mysql
- Altium Designer中off grid pin解决方法
猜你喜欢

Flutter series -flutter route management

Solution of off grid pin in Altium Designer

NRF51822外设学习

A homekit enabled camera? Zhiting IPC camera IC1 unpacking experience

结构型模式之适配器模式

what? Homekit, Micah, aqara and other ecosystems can also be linked with tmall elf ecology through zhiting?

1.2----- mechanical design tools (CAD software) and hardware design tools (EDA software) and comparison

新唐NUC980使用记录:开发环境准备与编译配置基础说明

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

Agent model of structured model
随机推荐
Xintang nuc980 usage record: basic description of development environment preparation and compilation configuration
Intelligent procurement system solution for processing and manufacturing industry: help enterprises realize integrated and Collaborative Procurement in the whole process
Service practice: use service to complete a download task
从11小时到25秒--还有优化空间吗?
Altium Designer中off grid pin解决方法
vim中快速缩进用法
Agent model of structured model
数组对象根据id一 一对应填入(将arr1填入arr2中)
How to judge whether text is an array in the slot
Initial experience of ABAQUS using RSG drawing plug-in
Input two strings and output the longest substring with the same length
Longest common subsequence
NAND闪存(NAND Flash)颗粒SLC,MLC,TLC,QLC的对比
Ts as const
Pat a 1093 count Pat's (25 points)
数组对象实现一 一对比(索引和id相同的保留原数据,原数组没有的数据从默认列表加进去)
ActiveReports报表实战应用教程(十九)——多数据源绑定
Quick indent usage in VIM
delegate
Fault analysis | from data_ Free exception