22 #ifndef TULIP_PLANARITYIMPL_H
23 #define TULIP_PLANARITYIMPL_H
25 #ifndef DOXYGEN_NOTFOR_USER
29 #include <tulip/ObservableGraph.h>
30 #include <tulip/Edge.h>
31 #include <tulip/MutableContainer.h>
32 #include <tulip/BmdList.h>
36 enum { NOT_VISITED, VISITED, TERMINAL, VISITED_IN_RBC };
37 static const node NULL_NODE = node();
38 static const edge NULL_EDGE = edge();
40 class TLP_SCOPE PlanarityTestImpl {
43 PlanarityTestImpl(Graph *sg);
44 bool isPlanar(
bool embedsg =
false);
45 static bool isPlanarEmbedding(
const Graph *sG);
46 std::list<edge> getObstructions();
49 bool compute(Graph *);
52 edge edgeReversal( edge e);
53 void makeBidirected(Graph *sG);
54 void swapNode(node &n1, node &n2);
55 void findTerminalNodes(Graph *sG, node n, std::list<node>& listOfComponents,
56 std::map<node, std::list<node> > &terminalNodes);
57 bool findObstruction(Graph *sG, node n, std::list<node>& terminalNodes);
58 void setInfoForNewCNode(Graph *sG, node n, node newCNode,
59 std::list<node>& terminalNodes);
60 node findActiveCNode(node, node, std::list<node>&);
61 void preProcessing(Graph *);
62 tlp::BmdLink<node>* searchRBC(
int, tlp::BmdLink<node>*, node, std::list<node>&);
63 bool isT0Edge(Graph *, edge);
64 bool isBackEdge(Graph *, edge);
66 void sortNodesIncreasingOrder(Graph *, MutableContainer<int>&, std::vector<node>&);
67 node activeCNodeOf(
bool, node);
68 void addOldCNodeRBCToNewRBC(node, node, node, node, node, BmdList<node>&);
69 void updateLabelB(node);
70 void calcNewRBCFromTerminalNode(node, node, node, node, BmdList<node>&);
71 node lastPNode(node, node);
72 node lcaBetween(node, node,
const MutableContainer<node>&);
73 node lcaBetweenTermNodes(node, node);
74 void calculateNewRBC(Graph *, node, node, std::list<node>&);
75 node findNodeWithLabelBGreaterThanDfsN(
bool, Graph *, node, node);
76 void setPossibleK33Obstruction(node, node, node, node);
77 bool testCNodeCounter(Graph *, node, node, node, node, node&, node&);
78 bool testObstructionFromTerminalNode(Graph *, node, node, node);
81 bool listEdgesUpwardT0(node n1, node n2);
82 void extractBoundaryCycle(Graph *sG, node cNode, std::list<edge>& listEdges);
84 void obstrEdgesTerminal(Graph* G, node w, node t, node u);
85 void addPartOfBc(Graph *sG, node cNode, node n1, node n2, node n3);
86 void sortByLabelB(node &n1, node &n2, node &n3);
87 void obstrEdgesPNode(Graph *sG, node p, node u);
88 void calcInfo3Terminals(node &t1, node &t2, node &t3,
int &countMin,
int &countF, node &cNode, node &q);
89 void obstructionEdgesT0(Graph *sG, node w, node t1, node t2, node t3, node v);
90 void obstructionEdgesCountMin1(Graph *sG, node n, node cNode, node t1, node t2, node t3);
91 void obstructionEdgesCountMin23(Graph *sG, node n, node cNode, node t1, node t2, node t3, node q, node v);
93 void obstructionEdgesK5(Graph *sG, node w, node cNode, node t1, node t2, node t3);
94 void obstructionEdgesPossibleObstrConfirmed(Graph *sG, node w, node t, node v);
95 void obstructionEdgesCNodeCounter(Graph *sG, node cNode, node w, node jl, node jr, node t1, node t2);
98 void embedRoot(Graph *sG,
int n);
99 void calculatePartialEmbedding(Graph *sG, node w, node newCNode, std::list<edge>& listBackEdges, std::list<node>& terminalNodes);
100 void markPathInT(node t, node w, std::map<node, node>& backEdgeRepresentant, std::list<node>& traversedNodes);
101 std::map< node, std::list<edge> > groupBackEdgesByRepr(Graph *sG, std::list<edge>& listBackEdges,
102 std::map<node, node>& backEdgeRepresentant,
103 std::list<node>& traversedNodes,
104 std::list<node>& listRepresentants);
105 std::list<node> embedUpwardT(
bool embBackEdgesOutW, node t1, node t2, Graph *sG, node w,
106 std::map< node, std::list<edge> > &bEdgesRepres,
107 std::list<node>& traversedNodes,
108 BmdList<edge>& embList);
109 void addOldCNodeToEmbedding(
bool embBackEdgesOutW, Graph *sG, node w, node oldCNode, node u,
110 std::map<node,std::list<edge> >& bEdgesRepres,
111 std::list<node>& traversedNodes,
112 std::list<node>& toEmbedLater,
113 BmdList<edge>& embList);
114 void embedBackEdges(
bool embBackEdgesOutW, Graph *sG, node repr,
115 std::list<node>& traversedNodes,
116 std::list<edge>& listBackEdges,
117 BmdList<edge>& embList);
118 int sortBackEdgesByDfs(Graph *sG, node w, node repr,
119 std::list<edge>& listBackEdges,
120 std::vector<edge>& backEdge);
126 bool embed, biconnected;
127 node lastNodeInQLinha;
128 std::map<edge, edge> bidirectedEdges;
129 std::map<edge, edge> reversalEdge;
132 node cNodeOfPossibleK33Obstruction;
139 std::map<node, std::list<node> > childrenInT0;
146 std::map<node, std::list<edge> > listBackEdges;
150 std::map<node, BmdList<node> > RBC;
155 std::map<node, BmdList<edge> > embedList;
158 std::map<tlp::BmdLink<node>*, node> activeCNode;
162 BmdList<edge> listBackEdgesOutW;
166 std::list<node> obstructionNodes;
169 std::list<edge> obstructionEdges;
175 MutableContainer< tlp::BmdLink<node>*> ptrItem;
178 MutableContainer<int> dfsPosNum;
181 MutableContainer<node> nodeWithDfsPos;
185 MutableContainer<edge> T0EdgeIn;
189 MutableContainer<node> parent;
190 MutableContainer<node> p0;
195 MutableContainer<int> largestNeighbor;
201 MutableContainer<int> labelB;
207 MutableContainer<node> nodeLabelB;
211 MutableContainer<node> lastVisited;
216 MutableContainer<node> neighborWTerminal;
221 MutableContainer<int> state;
225 MutableContainer<int> counter;
229 MutableContainer<bool> hasBackEdge;
230 unsigned int numberOfNodesInG;
237 std::list<tlp::edge> posDFS(
tlp::Graph *sG, tlp::MutableContainer<int> &dfsPos);