AOE Critical Path

There is a time limit on the order in which time occurs. Time A cannot occur until its precursor activities have completed.
Edge: Represents the duration of the activity, and the corresponding activity time must be performed between the two events.
Point: Represents an event

Four key attributes

Ve[i]: Indicates the earliest time that event I occurred;
Vl[i]: Indicates the latest occurrence of event I
e[i]: indicates the earliest occurrence of activity i;
l[i]: Indicates the latest occurrence of activity i;

Calculation process:

Make l[i] = e[i] indicate that an activity can be performed immediately as long as it is possible;

#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

const int maxn = 1e4 + 10;
const int maxm = 1e6 + 10;
const int INF = 0x3f3f3f3f;
int head1[maxn], pnt1[maxm], nxt1[maxm], cost1[maxm], ecnt1;
int head2[maxn], pnt2[maxm], nxt2[maxm], cost2[maxm], ecnt2;
inline void addedge(int u, int v, int c) {
    pnt1[ecnt1] = v, cost1[ecnt1] = c, nxt1[ecnt1] = head1[u], head1[u] = ecnt1++;
    pnt2[ecnt2] = u, cost2[ecnt2] = c, nxt2[ecnt2] = head2[v], head2[v] = ecnt2++;
}
int dis1[maxn];//dis1[i] denotes the earliest time that event I can occur
int dis2[maxn];//dis2[i] indicates the latest time that event I can occur
bool mark[maxn];
void HeadToTail(int st, int ed) {
    queue<int> que;
    memset(mark, false, sizeof mark);
    memset(dis1, -1, sizeof dis1);
    que.push(st);
    dis1[st] = 0;
    while(!que.empty()) {
        int u = que.front();
        que.pop();
        mark[u] = false;

        for (int i = head1[u];~i;i = nxt1[i]) {
            int v = pnt1[i], c = cost1[i];
            //Finding the Longest Path
            if (dis1[u] + cost1[i] > dis1[v]) {
                dis1[v] = dis1[u] + cost1[i];
                if (!mark[v]) {
                    mark[v] = true;
                    que.push(v);
                }
            }
        }
    }
}
void TailToHead(int st, int ed) {
    queue<int> que;
    memset(mark, false, sizeof mark);
    memset(dis2, INF, sizeof dis2);
    dis2[ed] = dis1[ed];//The earliest time inherited
    mark[ed] = true;
    que.push(ed);
    while(!que.empty()) {
        int u = que.front();
        que.pop();
        mark[u] = false;
        for (int i = head2[u];~i;i = nxt2[i]) {
            int v = pnt2[i], c = cost2[i];
            if (dis2[v] > dis2[u] - c) {//Shortest path, no loops
                dis2[v] = dis2[u] - c;
                if (!mark[v]) {
                    mark[v] = true;
                    que.push(v);
                }
            }
        }

    }
}
inline void AOENetWork(int st, int ed) {
    HeadToTail(st, ed);
    TailToHead(ed, ed);
}
int main() {
    return 0;
}

Posted on Tue, 07 Jul 2020 12:34:49 -0400 by Theramore