Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.9 KiB

  1. /***** Header Files *****/
  2. #include "LHMatch.h"
  3. /***** Compilation Settings *****/
  4. /* DBG: Debug build. Check assertions, etc. */
  5. //#define DBG
  6. /* STATS: Report graph statistics and performance counters after each run. */
  7. //#define STATS
  8. /* DUMP: Dump the graph at the beginning and end of each run. */
  9. //#define DUMP
  10. /* WORST_GREEDY: The BFS algorithm starts off by computing a greedy
  11. * matching. Usually, we want to find the best greedy matching that we can
  12. * so that the algorithm will run quickly. For testing purposes, we can define
  13. * this flag and the worst initial greedy matching will be found instead. */
  14. //#define WORST_GREEDY
  15. /***** Constants *****/
  16. #define TRUE 1
  17. #define FALSE 0
  18. #ifndef NULL
  19. #define NULL 0L
  20. #endif
  21. #define MAX_INT ((int)((~((unsigned int)0))>>1))
  22. #define MAGIC1 0x50165315
  23. #define MAGIC2 0x50165315
  24. /***** Macros *****/
  25. #ifdef DBG
  26. #define DPRINT(x) if(gDebugPrint) x
  27. #else
  28. #define DPRINT(x)
  29. #undef assert
  30. #define assert(x)
  31. #endif
  32. #define IS_LHS_VTX(v) ((v)->id < g->numLHSVtx)
  33. #define INTMIN(a,b) ((a<b)?(a):(b))
  34. #define INTMAX(a,b) ((a)>(b)?(a):(b))
  35. /***** Vertex Structure *****/
  36. struct Vertex;
  37. struct Vertex {
  38. /***** Input *****/
  39. /* The following members are input by the user of the library. */
  40. /* degree: How many vertices are adjacent to this vertex.
  41. * Equivalently, the length of the adjacency list. */
  42. int degree;
  43. /* adjList: A list of vertex pointers indicating the vertices
  44. * that are adjacent to this vertex. */
  45. struct Vertex **adjList;
  46. /* adjListSize: The allocated size of the adjacency list. */
  47. int adjListSize;
  48. /* id: Used to identify a vertex, for debug purposes only. */
  49. int id;
  50. /***** Input / Output *****/
  51. /* The following members are used for both input and output. */
  52. /* matchedWith: This member is only used for left-hand vertices
  53. * and is ignored for right-hand vertices. This member may optionally
  54. * be passed as input from the user of the library to specify an initial
  55. * assignment. If this vertex is not initially assigned, this member
  56. * should be NULL. */
  57. struct Vertex *matchedWith;
  58. /***** Output *****/
  59. /* The following members are used for output only. */
  60. /* numMatched: This member is only used for right-hand vertices
  61. * and is ignored for left-hand vertices. */
  62. int numMatched;
  63. /***** Internal *****/
  64. /* The following members are used internally by the algorithms and
  65. * should not be examined by users of the library. */
  66. /* parent: Used by both the BFS algorithm to represent the
  67. * breadth-first search tree. */
  68. struct Vertex *parent;
  69. /* fLink, bLink: Used by both the BFS algorithm to insert this
  70. * vertex into a bucket, which is stored as a doubly-linked list. */
  71. struct Vertex *fLink, *bLink;
  72. };
  73. typedef struct Vertex Vertex;
  74. /***** Stats Structure *****/
  75. typedef struct {
  76. int TotalAugs;
  77. int TotalBFSTrees;
  78. int TotalAugBFSTreeSize;
  79. int TotalAugpathLen;
  80. int TotalRestarts;
  81. } Stats;
  82. /***** Graph Structure *****/
  83. typedef struct {
  84. /* magic1: A magic number to identify our graph structure. */
  85. int magic1;
  86. /* numLHSVtx: The number of vertices on the left-hand side of the graph. */
  87. int numLHSVtx;
  88. /* numRHSVtx: The number of vertices on the right-hand side of the graph. */
  89. int numRHSVtx;
  90. /* lVtx: The array of left-hand vertices in the graph. */
  91. Vertex *lVtx;
  92. /* rVtx: The array of right-hand vertices in the graph. */
  93. Vertex *rVtx;
  94. /* maxRHSLoad: The maximum load of the right-hand vertices */
  95. int maxRHSLoad;
  96. /* minRHSLoad: The minimum load of the right-hand vertices */
  97. int minRHSLoad;
  98. /* Buckets: Used to organize vertices by degree / load */
  99. Vertex **Buckets;
  100. /* Queue: For breadth-first search */
  101. Vertex **Queue;
  102. int Qsize;
  103. /* Counters for monitoring performance */
  104. #ifdef STATS
  105. Stats stats;
  106. #endif
  107. /* magic2: A second magic number to identify our graph structure. */
  108. int magic2;
  109. } Graph;
  110. /***** Function Prototypes *****/
  111. int LHAlgOnline(Graph *g);
  112. int LHAlgBFS(Graph *g);
  113. void AddVtxToBucket(Graph *g, Vertex *v, int b);
  114. void RemoveVtxFromBucket(Graph *g, Vertex *v, int b);
  115. void DestroyBuckets(Graph *g);
  116. int OrderedGreedyAssignment(Graph *g);
  117. int InitializeRHSBuckets(Graph *g);
  118. int InitializeQueue(Graph *g);
  119. void DestroyQueue(Graph *g);
  120. void ClearAlgState(Graph *g);
  121. void DumpGraph(Graph *g);
  122. void DumpLoad(Graph *g);
  123. /***** Globals *****/
  124. #ifdef DBG
  125. extern int gDebugPrint;
  126. #endif