22 #ifndef TULIP_PLANARITYIMPL_H 23 #define TULIP_PLANARITYIMPL_H 29 #include <tulip/Edge.h> 30 #include <tulip/MutableContainer.h> 31 #include <tulip/BmdList.h> 32 #include <tulip/tulipconf.h> 33 #include <tulip/Node.h> 37 enum { NOT_VISITED, VISITED, TERMINAL, VISITED_IN_RBC };
38 static const node NULL_NODE = node();
39 static const edge NULL_EDGE = edge();
41 class TLP_SCOPE PlanarityTestImpl {
44 PlanarityTestImpl(Graph *sg);
45 bool isPlanar(
bool embedsg =
false);
46 static bool isPlanarEmbedding(
const Graph *sG);
47 std::list<edge> getObstructions();
50 bool compute(Graph *);
53 edge edgeReversal( edge e);
54 void makeBidirected(Graph *sG);
55 void swapNode(node &n1, node &n2);
56 void findTerminalNodes(Graph *sG, node n, std::list<node>& listOfComponents,
57 std::map<node, std::list<node> > &terminalNodes);
58 bool findObstruction(Graph *sG, node n, std::list<node>& terminalNodes);
59 void setInfoForNewCNode(Graph *sG, node n, node newCNode,
60 std::list<node>& terminalNodes);
61 node findActiveCNode(node, node, std::list<node>&);
62 void preProcessing(Graph *);
63 tlp::BmdLink<node>* searchRBC(
int, tlp::BmdLink<node>*, node, std::list<node>&);
64 bool isT0Edge(Graph *, edge);
65 bool isBackEdge(Graph *, edge);
67 void sortNodesIncreasingOrder(Graph *, MutableContainer<int>&, std::vector<node>&);
68 node activeCNodeOf(
bool, node);
69 void addOldCNodeRBCToNewRBC(node, node, node, node, node, BmdList<node>&);
70 void updateLabelB(node);
71 void calcNewRBCFromTerminalNode(node, node, node, node, BmdList<node>&);
72 node lastPNode(node, node);
73 node lcaBetween(node, node,
const MutableContainer<node>&);
74 node lcaBetweenTermNodes(node, node);
75 void calculateNewRBC(Graph *, node, node, std::list<node>&);
76 node findNodeWithLabelBGreaterThanDfsN(
bool, Graph *, node, node);
77 void setPossibleK33Obstruction(node, node, node, node);
78 bool testCNodeCounter(Graph *, node, node, node, node, node&, node&);
79 bool testObstructionFromTerminalNode(Graph *, node, node, node);
82 bool listEdgesUpwardT0(node n1, node n2);
83 void extractBoundaryCycle(Graph *sG, node cNode, std::list<edge>& listEdges);
85 void obstrEdgesTerminal(Graph* G, node w, node t, node u);
86 void addPartOfBc(Graph *sG, node cNode, node n1, node n2, node n3);
87 void sortByLabelB(node &n1, node &n2, node &n3);
88 void obstrEdgesPNode(Graph *sG, node p, node u);
89 void calcInfo3Terminals(node &t1, node &t2, node &t3,
int &countMin,
int &countF, node &cNode, node &q);
90 void obstructionEdgesT0(Graph *sG, node w, node t1, node t2, node t3, node v);
91 void obstructionEdgesCountMin1(Graph *sG, node n, node cNode, node t1, node t2, node t3);
92 void obstructionEdgesCountMin23(Graph *sG, node n, node cNode, node t1, node t2, node t3, node q, node v);
94 void obstructionEdgesK5(Graph *sG, node w, node cNode, node t1, node t2, node t3);
95 void obstructionEdgesPossibleObstrConfirmed(Graph *sG, node w, node t, node v);
96 void obstructionEdgesCNodeCounter(Graph *sG, node cNode, node w, node jl, node jr, node t1, node t2);
99 void embedRoot(Graph *sG,
int n);
100 void calculatePartialEmbedding(Graph *sG, node w, node newCNode, std::list<edge>& listBackEdges, std::list<node>& terminalNodes);
101 void markPathInT(node t, node w, std::map<node, node>& backEdgeRepresentant, std::list<node>& traversedNodes);
102 std::map< node, std::list<edge> > groupBackEdgesByRepr(Graph *sG, std::list<edge>& listBackEdges,
103 std::map<node, node>& backEdgeRepresentant,
104 std::list<node>& traversedNodes,
105 std::list<node>& listRepresentants);
106 std::list<node> embedUpwardT(
bool embBackEdgesOutW, node t1, node t2, Graph *sG, node w,
107 std::map< node, std::list<edge> > &bEdgesRepres,
108 std::list<node>& traversedNodes,
109 BmdList<edge>& embList);
110 void addOldCNodeToEmbedding(
bool embBackEdgesOutW, Graph *sG, node w, node oldCNode, node u,
111 std::map<node,std::list<edge> >& bEdgesRepres,
112 std::list<node>& traversedNodes,
113 std::list<node>& toEmbedLater,
114 BmdList<edge>& embList);
115 void embedBackEdges(
bool embBackEdgesOutW, Graph *sG, node repr,
116 std::list<node>& traversedNodes,
117 std::list<edge>& listBackEdges,
118 BmdList<edge>& embList);
119 int sortBackEdgesByDfs(Graph *sG, node w, node repr,
120 std::list<edge>& listBackEdges,
121 std::vector<edge>& backEdge);
127 bool embed, biconnected;
128 node lastNodeInQLinha;
129 std::map<edge, edge> bidirectedEdges;
130 std::map<edge, edge> reversalEdge;
133 node cNodeOfPossibleK33Obstruction;
140 std::map<node, std::list<node> > childrenInT0;
147 std::map<node, std::list<edge> > listBackEdges;
151 std::map<node, BmdList<node> > RBC;
156 std::map<node, BmdList<edge> > embedList;
159 std::map<tlp::BmdLink<node>*, node> activeCNode;
163 BmdList<edge> listBackEdgesOutW;
167 std::list<node> obstructionNodes;
170 std::list<edge> obstructionEdges;
176 MutableContainer< tlp::BmdLink<node>*> ptrItem;
179 MutableContainer<int> dfsPosNum;
182 MutableContainer<node> nodeWithDfsPos;
186 MutableContainer<edge> T0EdgeIn;
190 MutableContainer<node> parent;
191 MutableContainer<node> p0;
196 MutableContainer<int> largestNeighbor;
202 MutableContainer<int> labelB;
208 MutableContainer<node> nodeLabelB;
212 MutableContainer<node> lastVisited;
217 MutableContainer<node> neighborWTerminal;
222 MutableContainer<int> state;
226 MutableContainer<int> counter;
230 MutableContainer<bool> hasBackEdge;
231 unsigned int numberOfNodesInG;
238 std::list<tlp::edge> posDFS(
tlp::Graph *sG, tlp::MutableContainer<int> &dfsPos);