Adaptagrams
mtst.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libavoid - Fast, Incremental, Object-avoiding Line Router
5  *
6  * Copyright (C) 2011-2013 Monash University
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  * See the file LICENSE.LGPL distributed with the library.
13  *
14  * Licensees holding a valid commercial license may use this file in
15  * accordance with the commercial license agreement provided with the
16  * library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Michael Wybrow
23 */
24 
25 #ifndef AVOID_MTST_H
26 #define AVOID_MTST_H
27 
28 #include <cstdio>
29 #include <set>
30 #include <list>
31 #include <utility>
32 
33 #include "libavoid/vertices.h"
34 #include "libavoid/hyperedgetree.h"
35 
36 
37 namespace Avoid {
38 
39 class VertInf;
40 class Router;
41 class ConnRef;
42 class EdgeInf;
43 
44 typedef std::list<VertexSet> VertexSetList;
45 
46 typedef std::pair<EdgeInf *, VertInf *> LayeredOrthogonalEdge;
47 typedef std::list<LayeredOrthogonalEdge> LayeredOrthogonalEdgeList;
48 
49 // Comparison for the vertex heap in the extended Dijkstra's algorithm.
50 struct HeapCmpVertInf
51 {
52  bool operator()(const VertInf *a, const VertInf *b) const;
53 };
54 
55 
56 // Comparison for the bridging edge heap in the extended Kruskal's algorithm.
57 struct CmpEdgeInf
58 {
59  bool operator()(const EdgeInf *a, const EdgeInf *b) const;
60 };
61 
62 
63 // This class is not intended for public use.
64 // It is used by the hyperedge routing code to build a minimum terminal
65 // spanning tree for a set of terminal vertices.
66 class MinimumTerminalSpanningTree
67 {
68  public:
69  MinimumTerminalSpanningTree(Router *router,
70  std::set<VertInf *> terminals,
71  JunctionHyperedgeTreeNodeMap *hyperedgeTreeJunctions = nullptr);
72  ~MinimumTerminalSpanningTree();
73 
74  // Uses Interleaved construction of the MTST and SPTF (heuristic 2
75  // from paper). This is the preferred construction approach.
76  void constructInterleaved(void);
77  // Uses Sequential construction of the MTST (heuristic 1 from paper).
78  void constructSequential(void);
79 
80  void setDebuggingOutput(FILE *fp, unsigned int counter);
81  HyperedgeTreeNode *rootJunction(void) const;
82 
83  private:
84  void buildHyperedgeTreeToRoot(VertInf *curr,
85  HyperedgeTreeNode *prevNode, VertInf *prevVert,
86  bool markEdges = false);
87  VertInf **resetDistsForPath(VertInf *currVert, VertInf **newRootVertPtr);
88  void rewriteRestOfHyperedge(VertInf *vert, VertInf **newTreeRootPtr);
89  void drawForest(VertInf *vert, VertInf *prev);
90 
91  void makeSet(VertInf *vertex);
92  VertexSetList::iterator findSet(VertInf *vertex);
93  void unionSets(VertexSetList::iterator s1, VertexSetList::iterator s2);
94  HyperedgeTreeNode *addNode(VertInf *vertex, HyperedgeTreeNode *prevNode);
95 
96  void removeInvalidBridgingEdges(void);
97  void commitToBridgingEdge(EdgeInf *e);
98  bool connectsWithoutBend(VertInf *oldLeaf, VertInf *newLeaf);
99  LayeredOrthogonalEdgeList getOrthogonalEdgesFromVertex(VertInf *vert,
100  VertInf *prev);
101  VertInf *orthogonalPartner(VertInf *vert, double penalty = 0);
102  VertexPair realVerticesCountingPartners(EdgeInf *edge);
103 
104 
105  Router *router;
106  bool isOrthogonal;
107  std::set<VertInf *> terminals;
108  std::set<VertInf *> origTerminals;
109  JunctionHyperedgeTreeNodeMap *hyperedgeTreeJunctions;
110 
111  VertexNodeMap nodes;
112  HyperedgeTreeNode *m_rootJunction;
113  double bendPenalty;
114  VertexSetList allsets;
115  std::list<VertInf *> visitedVertices;
116  std::list<VertInf *> extraVertices;
117  std::list<VertInf *> unusedVertices;
118  std::list<VertInf **> rootVertexPointers;
119 
120  // Vertex heap for extended Dijkstra's algorithm.
121  std::vector<VertInf *> vHeap;
122  HeapCmpVertInf vHeapCompare;
123 
124  // Bridging edge heap for the extended Kruskal's algorithm.
125  std::vector<EdgeInf *> beHeap;
126  CmpEdgeInf beHeapCompare;
127 
128  const VertID dimensionChangeVertexID;
129 };
130 
131 
132 }
133 
134 #endif
libavoid: Object-avoiding orthogonal and polyline connector routing library.
Definition: actioninfo.cpp:33