I will introduce the basic storage methods, DFS and BFS, undirected graphs, Minimum Spanning Tree, shortest path, and active network (AOV and AOE) in detail.C ++Graph application. We have already introduced the first five aspects in the previous article. Today we will introduce the last one --Activity Network(AOV,AOE).
Activity Network (AOV, AOE)
This part is related to engineering. That is to say, when AOV and AOE are very complicated, the value of this part can be displayed. in simple words, the manual operation is faster than the program, the manual result is displayed when the data is input. I don't have any examples. It always gives me a feeling of no confidence. It's hard to finish writing the program. Compared with the frontend, this is a professional. In other words, not everyone is interested. If you don't want to watch it, just jump over.
Preparations
The active network mainly has two algorithms: topological sorting and Key Path determination. The latter is based on the previous algorithm. Build an "algorithm class" based on the previous article. When you need an algorithm, bind the graph to the algorithm.
- #include "Network.h"
- #define iterator list ::edge>::iterator
- #define begin(i) G->data.vertices[i].e->begin()
- #define end(i) G->data.vertices[i].e->end()
- struct CriAct
- {
- CriAct() {}
- CriAct(int source, int dest) : s(source), d(dest) {}
- int s, d;
- };
- template <class name, class dist>
- class ActivityNetwork
- {
- public:
- ActivityNetwork(Network >* G) : G(G), N(G->vNum()), outCriAct(CA)
- {
- count = new int[N]; result = new int[N];
- }
- ~ActivityNetwork()
- {
- delete []count; delete []result;
- }
- const vector & outCriAct;
- const int* out;
- private:
- void initialize()
- {
- for (int j = 0; j < N; j++) count[j] = 0;
- for (int i = 0; i < N; i++)
- {
- for (iterator iter = begin(i); iter != end(i); iter++) count[iter->vID]++;
- }
- out = result;
- }
- Network >* G;
- vector CA;
- int N, *count, *result;
- };
Because AOV and AOE do not have too many edges (Imagine if there are too many edges, the events are all trivial), so the storage structure directly selects the adjacent table. In addition, to reflect the advantages of the adjacent table, you need to directly operate on private data. Therefore, you need to declare this class as a friend of the Link class and the Network class. In addition, because this class is behind, therefore, the forward declaration is required. The details are as follows:
- template <class name, class dist> class ActivityNetwork;
- template <class name, class dist> class Link
- {friend class ActivityNetwork ;};
- template <class name, class dist, class mem> class Network
- { friend class ActivityNetwork ;};