6. Application of C ++ diagrams 6. Active Networks (AOV and AOE) (1)

Source: Internet
Author: User

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.

 
 
  1. #include "Network.h"   
  2. #define iterator list ::edge>::iterator   
  3. #define begin(i) G->data.vertices[i].e->begin()   
  4. #define end(i) G->data.vertices[i].e->end()   
  5. struct CriAct   
  6. {   
  7. CriAct() {}   
  8. CriAct(int source, int dest) : s(source), d(dest) {}   
  9. int s, d;   
  10. };   
  11. template <class name, class dist>   
  12. class ActivityNetwork   
  13. {   
  14. public:   
  15. ActivityNetwork(Network  >* G) : G(G), N(G->vNum()), outCriAct(CA)   
  16. {   
  17. count = new int[N]; result = new int[N];   
  18. }   
  19. ~ActivityNetwork()   
  20. {   
  21. delete []count; delete []result;   
  22. }   
  23. const vector & outCriAct;   
  24. const int* out;   
  25. private:   
  26. void initialize()   
  27. {   
  28. for (int j = 0; j < N; j++) count[j] = 0;   
  29. for (int i = 0; i < N; i++)   
  30. {   
  31. for (iterator iter = begin(i); iter != end(i); iter++) count[iter->vID]++;   
  32. }   
  33. out = result;   
  34. }   
  35. Network  >* G;   
  36. vector  CA;   
  37. int N, *count, *result;   
  38. };  

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:

 
 
  1. template <class name, class dist> class ActivityNetwork;   
  2. template <class name, class dist> class Link   
  3. {friend class ActivityNetwork ;};   
  4. template <class name, class dist, class mem> class Network   
  5. { friend class ActivityNetwork ;};  


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.