boyer_myrvold_impl.hpp 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012
  1. //=======================================================================
  2. // Copyright (c) Aaron Windsor 2007
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //=======================================================================
  8. #ifndef __BOYER_MYRVOLD_IMPL_HPP__
  9. #define __BOYER_MYRVOLD_IMPL_HPP__
  10. #include <vector>
  11. #include <list>
  12. #include <boost/next_prior.hpp>
  13. #include <boost/config.hpp> //for std::min macros
  14. #include <boost/shared_ptr.hpp>
  15. #include <boost/tuple/tuple.hpp>
  16. #include <boost/property_map/property_map.hpp>
  17. #include <boost/graph/graph_traits.hpp>
  18. #include <boost/graph/depth_first_search.hpp>
  19. #include <boost/graph/planar_detail/face_handles.hpp>
  20. #include <boost/graph/planar_detail/face_iterators.hpp>
  21. #include <boost/graph/planar_detail/bucket_sort.hpp>
  22. namespace boost
  23. {
  24. namespace detail {
  25. enum bm_case_t{BM_NO_CASE_CHOSEN, BM_CASE_A, BM_CASE_B, BM_CASE_C, BM_CASE_D, BM_CASE_E};
  26. }
  27. template<typename LowPointMap, typename DFSParentMap,
  28. typename DFSNumberMap, typename LeastAncestorMap,
  29. typename DFSParentEdgeMap, typename SizeType>
  30. struct planar_dfs_visitor : public dfs_visitor<>
  31. {
  32. planar_dfs_visitor(LowPointMap lpm, DFSParentMap dfs_p,
  33. DFSNumberMap dfs_n, LeastAncestorMap lam,
  34. DFSParentEdgeMap dfs_edge)
  35. : low(lpm),
  36. parent(dfs_p),
  37. df_number(dfs_n),
  38. least_ancestor(lam),
  39. df_edge(dfs_edge),
  40. count(0)
  41. {}
  42. template <typename Vertex, typename Graph>
  43. void start_vertex(const Vertex& u, Graph&)
  44. {
  45. put(parent, u, u);
  46. put(least_ancestor, u, count);
  47. }
  48. template <typename Vertex, typename Graph>
  49. void discover_vertex(const Vertex& u, Graph&)
  50. {
  51. put(low, u, count);
  52. put(df_number, u, count);
  53. ++count;
  54. }
  55. template <typename Edge, typename Graph>
  56. void tree_edge(const Edge& e, Graph& g)
  57. {
  58. typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
  59. vertex_t s(source(e,g));
  60. vertex_t t(target(e,g));
  61. put(parent, t, s);
  62. put(df_edge, t, e);
  63. put(least_ancestor, t, get(df_number, s));
  64. }
  65. template <typename Edge, typename Graph>
  66. void back_edge(const Edge& e, Graph& g)
  67. {
  68. typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
  69. typedef typename graph_traits<Graph>::vertices_size_type v_size_t;
  70. vertex_t s(source(e,g));
  71. vertex_t t(target(e,g));
  72. BOOST_USING_STD_MIN();
  73. if ( t != get(parent, s) ) {
  74. v_size_t s_low_df_number = get(low, s);
  75. v_size_t t_df_number = get(df_number, t);
  76. v_size_t s_least_ancestor_df_number = get(least_ancestor, s);
  77. put(low, s,
  78. min BOOST_PREVENT_MACRO_SUBSTITUTION(s_low_df_number,
  79. t_df_number)
  80. );
  81. put(least_ancestor, s,
  82. min BOOST_PREVENT_MACRO_SUBSTITUTION(s_least_ancestor_df_number,
  83. t_df_number
  84. )
  85. );
  86. }
  87. }
  88. template <typename Vertex, typename Graph>
  89. void finish_vertex(const Vertex& u, Graph&)
  90. {
  91. typedef typename graph_traits<Graph>::vertices_size_type v_size_t;
  92. Vertex u_parent = get(parent, u);
  93. v_size_t u_parent_lowpoint = get(low, u_parent);
  94. v_size_t u_lowpoint = get(low, u);
  95. BOOST_USING_STD_MIN();
  96. if (u_parent != u)
  97. {
  98. put(low, u_parent,
  99. min BOOST_PREVENT_MACRO_SUBSTITUTION(u_lowpoint,
  100. u_parent_lowpoint
  101. )
  102. );
  103. }
  104. }
  105. LowPointMap low;
  106. DFSParentMap parent;
  107. DFSNumberMap df_number;
  108. LeastAncestorMap least_ancestor;
  109. DFSParentEdgeMap df_edge;
  110. SizeType count;
  111. };
  112. template <typename Graph,
  113. typename VertexIndexMap,
  114. typename StoreOldHandlesPolicy = graph::detail::store_old_handles,
  115. typename StoreEmbeddingPolicy = graph::detail::recursive_lazy_list
  116. >
  117. class boyer_myrvold_impl
  118. {
  119. typedef typename graph_traits<Graph>::vertices_size_type v_size_t;
  120. typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
  121. typedef typename graph_traits<Graph>::edge_descriptor edge_t;
  122. typedef typename graph_traits<Graph>::vertex_iterator vertex_iterator_t;
  123. typedef typename graph_traits<Graph>::edge_iterator edge_iterator_t;
  124. typedef typename graph_traits<Graph>::out_edge_iterator
  125. out_edge_iterator_t;
  126. typedef graph::detail::face_handle
  127. <Graph, StoreOldHandlesPolicy, StoreEmbeddingPolicy> face_handle_t;
  128. typedef std::vector<vertex_t> vertex_vector_t;
  129. typedef std::vector<edge_t> edge_vector_t;
  130. typedef std::list<vertex_t> vertex_list_t;
  131. typedef std::list< face_handle_t > face_handle_list_t;
  132. typedef boost::shared_ptr< face_handle_list_t > face_handle_list_ptr_t;
  133. typedef boost::shared_ptr< vertex_list_t > vertex_list_ptr_t;
  134. typedef boost::tuple<vertex_t, bool, bool> merge_stack_frame_t;
  135. typedef std::vector<merge_stack_frame_t> merge_stack_t;
  136. template <typename T>
  137. struct map_vertex_to_
  138. {
  139. typedef iterator_property_map
  140. <typename std::vector<T>::iterator, VertexIndexMap> type;
  141. };
  142. typedef typename map_vertex_to_<v_size_t>::type vertex_to_v_size_map_t;
  143. typedef typename map_vertex_to_<vertex_t>::type vertex_to_vertex_map_t;
  144. typedef typename map_vertex_to_<edge_t>::type vertex_to_edge_map_t;
  145. typedef typename map_vertex_to_<vertex_list_ptr_t>::type
  146. vertex_to_vertex_list_ptr_map_t;
  147. typedef typename map_vertex_to_< edge_vector_t >::type
  148. vertex_to_edge_vector_map_t;
  149. typedef typename map_vertex_to_<bool>::type vertex_to_bool_map_t;
  150. typedef typename map_vertex_to_<face_handle_t>::type
  151. vertex_to_face_handle_map_t;
  152. typedef typename map_vertex_to_<face_handle_list_ptr_t>::type
  153. vertex_to_face_handle_list_ptr_map_t;
  154. typedef typename map_vertex_to_<typename vertex_list_t::iterator>::type
  155. vertex_to_separated_node_map_t;
  156. template <typename BicompSideToTraverse = single_side,
  157. typename VisitorType = lead_visitor,
  158. typename Time = current_iteration>
  159. struct face_vertex_iterator
  160. {
  161. typedef face_iterator<Graph,
  162. vertex_to_face_handle_map_t,
  163. vertex_t,
  164. BicompSideToTraverse,
  165. VisitorType,
  166. Time>
  167. type;
  168. };
  169. template <typename BicompSideToTraverse = single_side,
  170. typename Time = current_iteration>
  171. struct face_edge_iterator
  172. {
  173. typedef face_iterator<Graph,
  174. vertex_to_face_handle_map_t,
  175. edge_t,
  176. BicompSideToTraverse,
  177. lead_visitor,
  178. Time>
  179. type;
  180. };
  181. public:
  182. boyer_myrvold_impl(const Graph& arg_g, VertexIndexMap arg_vm):
  183. g(arg_g),
  184. vm(arg_vm),
  185. low_point_vector(num_vertices(g)),
  186. dfs_parent_vector(num_vertices(g)),
  187. dfs_number_vector(num_vertices(g)),
  188. least_ancestor_vector(num_vertices(g)),
  189. pertinent_roots_vector(num_vertices(g)),
  190. backedge_flag_vector(num_vertices(g), num_vertices(g) + 1),
  191. visited_vector(num_vertices(g), num_vertices(g) + 1),
  192. face_handles_vector(num_vertices(g)),
  193. dfs_child_handles_vector(num_vertices(g)),
  194. separated_dfs_child_list_vector(num_vertices(g)),
  195. separated_node_in_parent_list_vector(num_vertices(g)),
  196. canonical_dfs_child_vector(num_vertices(g)),
  197. flipped_vector(num_vertices(g), false),
  198. backedges_vector(num_vertices(g)),
  199. dfs_parent_edge_vector(num_vertices(g)),
  200. vertices_by_dfs_num(num_vertices(g)),
  201. low_point(low_point_vector.begin(), vm),
  202. dfs_parent(dfs_parent_vector.begin(), vm),
  203. dfs_number(dfs_number_vector.begin(), vm),
  204. least_ancestor(least_ancestor_vector.begin(), vm),
  205. pertinent_roots(pertinent_roots_vector.begin(), vm),
  206. backedge_flag(backedge_flag_vector.begin(), vm),
  207. visited(visited_vector.begin(), vm),
  208. face_handles(face_handles_vector.begin(), vm),
  209. dfs_child_handles(dfs_child_handles_vector.begin(), vm),
  210. separated_dfs_child_list(separated_dfs_child_list_vector.begin(), vm),
  211. separated_node_in_parent_list
  212. (separated_node_in_parent_list_vector.begin(), vm),
  213. canonical_dfs_child(canonical_dfs_child_vector.begin(), vm),
  214. flipped(flipped_vector.begin(), vm),
  215. backedges(backedges_vector.begin(), vm),
  216. dfs_parent_edge(dfs_parent_edge_vector.begin(), vm)
  217. {
  218. planar_dfs_visitor
  219. <vertex_to_v_size_map_t, vertex_to_vertex_map_t,
  220. vertex_to_v_size_map_t, vertex_to_v_size_map_t,
  221. vertex_to_edge_map_t, v_size_t> vis
  222. (low_point, dfs_parent, dfs_number, least_ancestor, dfs_parent_edge);
  223. // Perform a depth-first search to find each vertex's low point, least
  224. // ancestor, and dfs tree information
  225. depth_first_search(g, visitor(vis).vertex_index_map(vm));
  226. // Sort vertices by their lowpoint - need this later in the constructor
  227. vertex_vector_t vertices_by_lowpoint(num_vertices(g));
  228. std::copy( vertices(g).first, vertices(g).second,
  229. vertices_by_lowpoint.begin()
  230. );
  231. bucket_sort(vertices_by_lowpoint.begin(),
  232. vertices_by_lowpoint.end(),
  233. low_point,
  234. num_vertices(g)
  235. );
  236. // Sort vertices by their dfs number - need this to iterate by reverse
  237. // DFS number in the main loop.
  238. std::copy( vertices(g).first, vertices(g).second,
  239. vertices_by_dfs_num.begin()
  240. );
  241. bucket_sort(vertices_by_dfs_num.begin(),
  242. vertices_by_dfs_num.end(),
  243. dfs_number,
  244. num_vertices(g)
  245. );
  246. // Initialize face handles. A face handle is an abstraction that serves
  247. // two uses in our implementation - it allows us to efficiently move
  248. // along the outer face of embedded bicomps in a partially embedded
  249. // graph, and it provides storage for the planar embedding. Face
  250. // handles are implemented by a sequence of edges and are associated
  251. // with a particular vertex - the sequence of edges represents the
  252. // current embedding of edges around that vertex, and the first and
  253. // last edges in the sequence represent the pair of edges on the outer
  254. // face that are adjacent to the associated vertex. This lets us embed
  255. // edges in the graph by just pushing them on the front or back of the
  256. // sequence of edges held by the face handles.
  257. //
  258. // Our algorithm starts with a DFS tree of edges (where every vertex is
  259. // an articulation point and every edge is a singleton bicomp) and
  260. // repeatedly merges bicomps by embedding additional edges. Note that
  261. // any bicomp at any point in the algorithm can be associated with a
  262. // unique edge connecting the vertex of that bicomp with the lowest DFS
  263. // number (which we refer to as the "root" of the bicomp) with its DFS
  264. // child in the bicomp: the existence of two such edges would contradict
  265. // the properties of a DFS tree. We refer to the DFS child of the root
  266. // of a bicomp as the "canonical DFS child" of the bicomp. Note that a
  267. // vertex can be the root of more than one bicomp.
  268. //
  269. // We move around the external faces of a bicomp using a few property
  270. // maps, which we'll initialize presently:
  271. //
  272. // - face_handles: maps a vertex to a face handle that can be used to
  273. // move "up" a bicomp. For a vertex that isn't an articulation point,
  274. // this holds the face handles that can be used to move around that
  275. // vertex's unique bicomp. For a vertex that is an articulation point,
  276. // this holds the face handles associated with the unique bicomp that
  277. // the vertex is NOT the root of. These handles can therefore be used
  278. // to move from any point on the outer face of the tree of bicomps
  279. // around the current outer face towards the root of the DFS tree.
  280. //
  281. // - dfs_child_handles: these are used to hold face handles for
  282. // vertices that are articulation points - dfs_child_handles[v] holds
  283. // the face handles corresponding to vertex u in the bicomp with root
  284. // u and canonical DFS child v.
  285. //
  286. // - canonical_dfs_child: this property map allows one to determine the
  287. // canonical DFS child of a bicomp while traversing the outer face.
  288. // This property map is only valid when applied to one of the two
  289. // vertices adjacent to the root of the bicomp on the outer face. To
  290. // be more precise, if v is the canonical DFS child of a bicomp,
  291. // canonical_dfs_child[dfs_child_handles[v].first_vertex()] == v and
  292. // canonical_dfs_child[dfs_child_handles[v].second_vertex()] == v.
  293. //
  294. // - pertinent_roots: given a vertex v, pertinent_roots[v] contains a
  295. // list of face handles pointing to the top of bicomps that need to
  296. // be visited by the current walkdown traversal (since they lead to
  297. // backedges that need to be embedded). These lists are populated by
  298. // the walkup and consumed by the walkdown.
  299. vertex_iterator_t vi, vi_end;
  300. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  301. {
  302. vertex_t v(*vi);
  303. vertex_t parent = dfs_parent[v];
  304. if (parent != v)
  305. {
  306. edge_t parent_edge = dfs_parent_edge[v];
  307. add_to_embedded_edges(parent_edge, StoreOldHandlesPolicy());
  308. face_handles[v] = face_handle_t(v, parent_edge, g);
  309. dfs_child_handles[v] = face_handle_t(parent, parent_edge, g);
  310. }
  311. else
  312. {
  313. face_handles[v] = face_handle_t(v);
  314. dfs_child_handles[v] = face_handle_t(parent);
  315. }
  316. canonical_dfs_child[v] = v;
  317. pertinent_roots[v] = face_handle_list_ptr_t(new face_handle_list_t);
  318. separated_dfs_child_list[v] = vertex_list_ptr_t(new vertex_list_t);
  319. }
  320. // We need to create a list of not-yet-merged depth-first children for
  321. // each vertex that will be updated as bicomps get merged. We sort each
  322. // list by ascending lowpoint, which allows the externally_active
  323. // function to run in constant time, and we keep a pointer to each
  324. // vertex's representation in its parent's list, which allows merging
  325. //in constant time.
  326. for(typename vertex_vector_t::iterator itr =
  327. vertices_by_lowpoint.begin();
  328. itr != vertices_by_lowpoint.end(); ++itr)
  329. {
  330. vertex_t v(*itr);
  331. vertex_t parent(dfs_parent[v]);
  332. if (v != parent)
  333. {
  334. separated_node_in_parent_list[v] =
  335. separated_dfs_child_list[parent]->insert
  336. (separated_dfs_child_list[parent]->end(), v);
  337. }
  338. }
  339. // The merge stack holds path information during a walkdown iteration
  340. merge_stack.reserve(num_vertices(g));
  341. }
  342. bool is_planar()
  343. {
  344. // This is the main algorithm: starting with a DFS tree of embedded
  345. // edges (which, since it's a tree, is planar), iterate through all
  346. // vertices by reverse DFS number, attempting to embed all backedges
  347. // connecting the current vertex to vertices with higher DFS numbers.
  348. //
  349. // The walkup is a procedure that examines all such backedges and sets
  350. // up the required data structures so that they can be searched by the
  351. // walkdown in linear time. The walkdown does the actual work of
  352. // embedding edges and flipping bicomps, and can identify when it has
  353. // come across a kuratowski subgraph.
  354. //
  355. // store_old_face_handles caches face handles from the previous
  356. // iteration - this is used only for the kuratowski subgraph isolation,
  357. // and is therefore dispatched based on the StoreOldHandlesPolicy.
  358. //
  359. // clean_up_embedding does some clean-up and fills in values that have
  360. // to be computed lazily during the actual execution of the algorithm
  361. // (for instance, whether or not a bicomp is flipped in the final
  362. // embedding). It's dispatched on the the StoreEmbeddingPolicy, since
  363. // it's not needed if an embedding isn't desired.
  364. typename vertex_vector_t::reverse_iterator vi, vi_end;
  365. vi_end = vertices_by_dfs_num.rend();
  366. for(vi = vertices_by_dfs_num.rbegin(); vi != vi_end; ++vi)
  367. {
  368. store_old_face_handles(StoreOldHandlesPolicy());
  369. vertex_t v(*vi);
  370. walkup(v);
  371. if (!walkdown(v))
  372. return false;
  373. }
  374. clean_up_embedding(StoreEmbeddingPolicy());
  375. return true;
  376. }
  377. private:
  378. void walkup(vertex_t v)
  379. {
  380. // The point of the walkup is to follow all backedges from v to
  381. // vertices with higher DFS numbers, and update pertinent_roots
  382. // for the bicomp roots on the path from backedge endpoints up
  383. // to v. This will set the stage for the walkdown to efficiently
  384. // traverse the graph of bicomps down from v.
  385. typedef typename face_vertex_iterator<both_sides>::type walkup_iterator_t;
  386. out_edge_iterator_t oi, oi_end;
  387. for(boost::tie(oi,oi_end) = out_edges(v,g); oi != oi_end; ++oi)
  388. {
  389. edge_t e(*oi);
  390. vertex_t e_source(source(e,g));
  391. vertex_t e_target(target(e,g));
  392. if (e_source == e_target)
  393. {
  394. self_loops.push_back(e);
  395. continue;
  396. }
  397. vertex_t w(e_source == v ? e_target : e_source);
  398. //continue if not a back edge or already embedded
  399. if (dfs_number[w] < dfs_number[v] || e == dfs_parent_edge[w])
  400. continue;
  401. backedges[w].push_back(e);
  402. v_size_t timestamp = dfs_number[v];
  403. backedge_flag[w] = timestamp;
  404. walkup_iterator_t walkup_itr(w, face_handles);
  405. walkup_iterator_t walkup_end;
  406. vertex_t lead_vertex = w;
  407. while (true)
  408. {
  409. // Move to the root of the current bicomp or the first visited
  410. // vertex on the bicomp by going up each side in parallel
  411. while(walkup_itr != walkup_end &&
  412. visited[*walkup_itr] != timestamp
  413. )
  414. {
  415. lead_vertex = *walkup_itr;
  416. visited[lead_vertex] = timestamp;
  417. ++walkup_itr;
  418. }
  419. // If we've found the root of a bicomp through a path we haven't
  420. // seen before, update pertinent_roots with a handle to the
  421. // current bicomp. Otherwise, we've just seen a path we've been
  422. // up before, so break out of the main while loop.
  423. if (walkup_itr == walkup_end)
  424. {
  425. vertex_t dfs_child = canonical_dfs_child[lead_vertex];
  426. vertex_t parent = dfs_parent[dfs_child];
  427. visited[dfs_child_handles[dfs_child].first_vertex()]
  428. = timestamp;
  429. visited[dfs_child_handles[dfs_child].second_vertex()]
  430. = timestamp;
  431. if (low_point[dfs_child] < dfs_number[v] ||
  432. least_ancestor[dfs_child] < dfs_number[v]
  433. )
  434. {
  435. pertinent_roots[parent]->push_back
  436. (dfs_child_handles[dfs_child]);
  437. }
  438. else
  439. {
  440. pertinent_roots[parent]->push_front
  441. (dfs_child_handles[dfs_child]);
  442. }
  443. if (parent != v && visited[parent] != timestamp)
  444. {
  445. walkup_itr = walkup_iterator_t(parent, face_handles);
  446. lead_vertex = parent;
  447. }
  448. else
  449. break;
  450. }
  451. else
  452. break;
  453. }
  454. }
  455. }
  456. bool walkdown(vertex_t v)
  457. {
  458. // This procedure is where all of the action is - pertinent_roots
  459. // has already been set up by the walkup, so we just need to move
  460. // down bicomps from v until we find vertices that have been
  461. // labeled as backedge endpoints. Once we find such a vertex, we
  462. // embed the corresponding edge and glue together the bicomps on
  463. // the path connecting the two vertices in the edge. This may
  464. // involve flipping bicomps along the way.
  465. vertex_t w; //the other endpoint of the edge we're embedding
  466. while (!pertinent_roots[v]->empty())
  467. {
  468. face_handle_t root_face_handle = pertinent_roots[v]->front();
  469. face_handle_t curr_face_handle = root_face_handle;
  470. pertinent_roots[v]->pop_front();
  471. merge_stack.clear();
  472. while(true)
  473. {
  474. typename face_vertex_iterator<>::type
  475. first_face_itr, second_face_itr, face_end;
  476. vertex_t first_side_vertex
  477. = graph_traits<Graph>::null_vertex();
  478. vertex_t second_side_vertex;
  479. vertex_t first_tail, second_tail;
  480. first_tail = second_tail = curr_face_handle.get_anchor();
  481. first_face_itr = typename face_vertex_iterator<>::type
  482. (curr_face_handle, face_handles, first_side());
  483. second_face_itr = typename face_vertex_iterator<>::type
  484. (curr_face_handle, face_handles, second_side());
  485. for(; first_face_itr != face_end; ++first_face_itr)
  486. {
  487. vertex_t face_vertex(*first_face_itr);
  488. if (pertinent(face_vertex, v) ||
  489. externally_active(face_vertex, v)
  490. )
  491. {
  492. first_side_vertex = face_vertex;
  493. second_side_vertex = face_vertex;
  494. break;
  495. }
  496. first_tail = face_vertex;
  497. }
  498. if (first_side_vertex == graph_traits<Graph>::null_vertex() ||
  499. first_side_vertex == curr_face_handle.get_anchor()
  500. )
  501. break;
  502. for(;second_face_itr != face_end; ++second_face_itr)
  503. {
  504. vertex_t face_vertex(*second_face_itr);
  505. if (pertinent(face_vertex, v) ||
  506. externally_active(face_vertex, v)
  507. )
  508. {
  509. second_side_vertex = face_vertex;
  510. break;
  511. }
  512. second_tail = face_vertex;
  513. }
  514. vertex_t chosen;
  515. bool chose_first_upper_path;
  516. if (internally_active(first_side_vertex, v))
  517. {
  518. chosen = first_side_vertex;
  519. chose_first_upper_path = true;
  520. }
  521. else if (internally_active(second_side_vertex, v))
  522. {
  523. chosen = second_side_vertex;
  524. chose_first_upper_path = false;
  525. }
  526. else if (pertinent(first_side_vertex, v))
  527. {
  528. chosen = first_side_vertex;
  529. chose_first_upper_path = true;
  530. }
  531. else if (pertinent(second_side_vertex, v))
  532. {
  533. chosen = second_side_vertex;
  534. chose_first_upper_path = false;
  535. }
  536. else
  537. {
  538. // If there's a pertinent vertex on the lower face
  539. // between the first_face_itr and the second_face_itr,
  540. // this graph isn't planar.
  541. for(;
  542. *first_face_itr != second_side_vertex;
  543. ++first_face_itr
  544. )
  545. {
  546. vertex_t p(*first_face_itr);
  547. if (pertinent(p,v))
  548. {
  549. //Found a Kuratowski subgraph
  550. kuratowski_v = v;
  551. kuratowski_x = first_side_vertex;
  552. kuratowski_y = second_side_vertex;
  553. return false;
  554. }
  555. }
  556. // Otherwise, the fact that we didn't find a pertinent
  557. // vertex on this face is fine - we should set the
  558. // short-circuit edges and break out of this loop to
  559. // start looking at a different pertinent root.
  560. if (first_side_vertex == second_side_vertex)
  561. {
  562. if (first_tail != v)
  563. {
  564. vertex_t first
  565. = face_handles[first_tail].first_vertex();
  566. vertex_t second
  567. = face_handles[first_tail].second_vertex();
  568. boost::tie(first_side_vertex, first_tail)
  569. = make_tuple(first_tail,
  570. first == first_side_vertex ?
  571. second : first
  572. );
  573. }
  574. else if (second_tail != v)
  575. {
  576. vertex_t first
  577. = face_handles[second_tail].first_vertex();
  578. vertex_t second
  579. = face_handles[second_tail].second_vertex();
  580. boost::tie(second_side_vertex, second_tail)
  581. = make_tuple(second_tail,
  582. first == second_side_vertex ?
  583. second : first);
  584. }
  585. else
  586. break;
  587. }
  588. canonical_dfs_child[first_side_vertex]
  589. = canonical_dfs_child[root_face_handle.first_vertex()];
  590. canonical_dfs_child[second_side_vertex]
  591. = canonical_dfs_child[root_face_handle.second_vertex()];
  592. root_face_handle.set_first_vertex(first_side_vertex);
  593. root_face_handle.set_second_vertex(second_side_vertex);
  594. if (face_handles[first_side_vertex].first_vertex() ==
  595. first_tail
  596. )
  597. face_handles[first_side_vertex].set_first_vertex(v);
  598. else
  599. face_handles[first_side_vertex].set_second_vertex(v);
  600. if (face_handles[second_side_vertex].first_vertex() ==
  601. second_tail
  602. )
  603. face_handles[second_side_vertex].set_first_vertex(v);
  604. else
  605. face_handles[second_side_vertex].set_second_vertex(v);
  606. break;
  607. }
  608. // When we unwind the stack, we need to know which direction
  609. // we came down from on the top face handle
  610. bool chose_first_lower_path =
  611. (chose_first_upper_path &&
  612. face_handles[chosen].first_vertex() == first_tail)
  613. ||
  614. (!chose_first_upper_path &&
  615. face_handles[chosen].first_vertex() == second_tail);
  616. //If there's a backedge at the chosen vertex, embed it now
  617. if (backedge_flag[chosen] == dfs_number[v])
  618. {
  619. w = chosen;
  620. backedge_flag[chosen] = num_vertices(g) + 1;
  621. add_to_merge_points(chosen, StoreOldHandlesPolicy());
  622. typename edge_vector_t::iterator ei, ei_end;
  623. ei_end = backedges[chosen].end();
  624. for(ei = backedges[chosen].begin(); ei != ei_end; ++ei)
  625. {
  626. edge_t e(*ei);
  627. add_to_embedded_edges(e, StoreOldHandlesPolicy());
  628. if (chose_first_lower_path)
  629. face_handles[chosen].push_first(e, g);
  630. else
  631. face_handles[chosen].push_second(e, g);
  632. }
  633. }
  634. else
  635. {
  636. merge_stack.push_back(make_tuple
  637. (chosen, chose_first_upper_path, chose_first_lower_path)
  638. );
  639. curr_face_handle = *pertinent_roots[chosen]->begin();
  640. continue;
  641. }
  642. //Unwind the merge stack to the root, merging all bicomps
  643. bool bottom_path_follows_first;
  644. bool top_path_follows_first;
  645. bool next_bottom_follows_first = chose_first_upper_path;
  646. vertex_t merge_point = chosen;
  647. while(!merge_stack.empty())
  648. {
  649. bottom_path_follows_first = next_bottom_follows_first;
  650. boost::tie(merge_point,
  651. next_bottom_follows_first,
  652. top_path_follows_first
  653. ) = merge_stack.back();
  654. merge_stack.pop_back();
  655. face_handle_t top_handle(face_handles[merge_point]);
  656. face_handle_t bottom_handle
  657. (*pertinent_roots[merge_point]->begin());
  658. vertex_t bottom_dfs_child = canonical_dfs_child
  659. [pertinent_roots[merge_point]->begin()->first_vertex()];
  660. remove_vertex_from_separated_dfs_child_list(
  661. canonical_dfs_child
  662. [pertinent_roots[merge_point]->begin()->first_vertex()]
  663. );
  664. pertinent_roots[merge_point]->pop_front();
  665. add_to_merge_points(top_handle.get_anchor(),
  666. StoreOldHandlesPolicy()
  667. );
  668. if (top_path_follows_first && bottom_path_follows_first)
  669. {
  670. bottom_handle.flip();
  671. top_handle.glue_first_to_second(bottom_handle);
  672. }
  673. else if (!top_path_follows_first &&
  674. bottom_path_follows_first
  675. )
  676. {
  677. flipped[bottom_dfs_child] = true;
  678. top_handle.glue_second_to_first(bottom_handle);
  679. }
  680. else if (top_path_follows_first &&
  681. !bottom_path_follows_first
  682. )
  683. {
  684. flipped[bottom_dfs_child] = true;
  685. top_handle.glue_first_to_second(bottom_handle);
  686. }
  687. else //!top_path_follows_first && !bottom_path_follows_first
  688. {
  689. bottom_handle.flip();
  690. top_handle.glue_second_to_first(bottom_handle);
  691. }
  692. }
  693. //Finally, embed all edges (v,w) at their upper end points
  694. canonical_dfs_child[w]
  695. = canonical_dfs_child[root_face_handle.first_vertex()];
  696. add_to_merge_points(root_face_handle.get_anchor(),
  697. StoreOldHandlesPolicy()
  698. );
  699. typename edge_vector_t::iterator ei, ei_end;
  700. ei_end = backedges[chosen].end();
  701. for(ei = backedges[chosen].begin(); ei != ei_end; ++ei)
  702. {
  703. if (next_bottom_follows_first)
  704. root_face_handle.push_first(*ei, g);
  705. else
  706. root_face_handle.push_second(*ei, g);
  707. }
  708. backedges[chosen].clear();
  709. curr_face_handle = root_face_handle;
  710. }//while(true)
  711. }//while(!pertinent_roots[v]->empty())
  712. return true;
  713. }
  714. void store_old_face_handles(graph::detail::no_old_handles) {}
  715. void store_old_face_handles(graph::detail::store_old_handles)
  716. {
  717. for(typename std::vector<vertex_t>::iterator mp_itr
  718. = current_merge_points.begin();
  719. mp_itr != current_merge_points.end(); ++mp_itr)
  720. {
  721. face_handles[*mp_itr].store_old_face_handles();
  722. }
  723. current_merge_points.clear();
  724. }
  725. void add_to_merge_points(vertex_t, graph::detail::no_old_handles) {}
  726. void add_to_merge_points(vertex_t v, graph::detail::store_old_handles)
  727. {
  728. current_merge_points.push_back(v);
  729. }
  730. void add_to_embedded_edges(edge_t, graph::detail::no_old_handles) {}
  731. void add_to_embedded_edges(edge_t e, graph::detail::store_old_handles)
  732. {
  733. embedded_edges.push_back(e);
  734. }
  735. void clean_up_embedding(graph::detail::no_embedding) {}
  736. void clean_up_embedding(graph::detail::store_embedding)
  737. {
  738. // If the graph isn't biconnected, we'll still have entries
  739. // in the separated_dfs_child_list for some vertices. Since
  740. // these represent articulation points, we can obtain a
  741. // planar embedding no matter what order we embed them in.
  742. vertex_iterator_t xi, xi_end;
  743. for(boost::tie(xi,xi_end) = vertices(g); xi != xi_end; ++xi)
  744. {
  745. if (!separated_dfs_child_list[*xi]->empty())
  746. {
  747. typename vertex_list_t::iterator yi, yi_end;
  748. yi_end = separated_dfs_child_list[*xi]->end();
  749. for(yi = separated_dfs_child_list[*xi]->begin();
  750. yi != yi_end; ++yi
  751. )
  752. {
  753. dfs_child_handles[*yi].flip();
  754. face_handles[*xi].glue_first_to_second
  755. (dfs_child_handles[*yi]);
  756. }
  757. }
  758. }
  759. // Up until this point, we've flipped bicomps lazily by setting
  760. // flipped[v] to true if the bicomp rooted at v was flipped (the
  761. // lazy aspect of this flip is that all descendents of that vertex
  762. // need to have their orientations reversed as well). Now, we
  763. // traverse the DFS tree by DFS number and perform the actual
  764. // flipping as needed
  765. typedef typename vertex_vector_t::iterator vertex_vector_itr_t;
  766. vertex_vector_itr_t vi_end = vertices_by_dfs_num.end();
  767. for(vertex_vector_itr_t vi = vertices_by_dfs_num.begin();
  768. vi != vi_end; ++vi
  769. )
  770. {
  771. vertex_t v(*vi);
  772. bool v_flipped = flipped[v];
  773. bool p_flipped = flipped[dfs_parent[v]];
  774. if (v_flipped && !p_flipped)
  775. {
  776. face_handles[v].flip();
  777. }
  778. else if (p_flipped && !v_flipped)
  779. {
  780. face_handles[v].flip();
  781. flipped[v] = true;
  782. }
  783. else
  784. {
  785. flipped[v] = false;
  786. }
  787. }
  788. // If there are any self-loops in the graph, they were flagged
  789. // during the walkup, and we should add them to the embedding now.
  790. // Adding a self loop anywhere in the embedding could never
  791. // invalidate the embedding, but they would complicate the traversal
  792. // if they were added during the walkup/walkdown.
  793. typename edge_vector_t::iterator ei, ei_end;
  794. ei_end = self_loops.end();
  795. for(ei = self_loops.begin(); ei != ei_end; ++ei)
  796. {
  797. edge_t e(*ei);
  798. face_handles[source(e,g)].push_second(e,g);
  799. }
  800. }
  801. bool pertinent(vertex_t w, vertex_t v)
  802. {
  803. // w is pertinent with respect to v if there is a backedge (v,w) or if
  804. // w is the root of a bicomp that contains a pertinent vertex.
  805. return backedge_flag[w] == dfs_number[v] || !pertinent_roots[w]->empty();
  806. }
  807. bool externally_active(vertex_t w, vertex_t v)
  808. {
  809. // Let a be any proper depth-first search ancestor of v. w is externally
  810. // active with respect to v if there exists a backedge (a,w) or a
  811. // backedge (a,w_0) for some w_0 in a descendent bicomp of w.
  812. v_size_t dfs_number_of_v = dfs_number[v];
  813. return (least_ancestor[w] < dfs_number_of_v) ||
  814. (!separated_dfs_child_list[w]->empty() &&
  815. low_point[separated_dfs_child_list[w]->front()] < dfs_number_of_v);
  816. }
  817. bool internally_active(vertex_t w, vertex_t v)
  818. {
  819. return pertinent(w,v) && !externally_active(w,v);
  820. }
  821. void remove_vertex_from_separated_dfs_child_list(vertex_t v)
  822. {
  823. typename vertex_list_t::iterator to_delete
  824. = separated_node_in_parent_list[v];
  825. garbage.splice(garbage.end(),
  826. *separated_dfs_child_list[dfs_parent[v]],
  827. to_delete,
  828. boost::next(to_delete)
  829. );
  830. }
  831. // End of the implementation of the basic Boyer-Myrvold Algorithm. The rest
  832. // of the code below implements the isolation of a Kuratowski subgraph in
  833. // the case that the input graph is not planar. This is by far the most
  834. // complicated part of the implementation.
  835. public:
  836. template <typename EdgeToBoolPropertyMap, typename EdgeContainer>
  837. vertex_t kuratowski_walkup(vertex_t v,
  838. EdgeToBoolPropertyMap forbidden_edge,
  839. EdgeToBoolPropertyMap goal_edge,
  840. EdgeToBoolPropertyMap is_embedded,
  841. EdgeContainer& path_edges
  842. )
  843. {
  844. vertex_t current_endpoint;
  845. bool seen_goal_edge = false;
  846. out_edge_iterator_t oi, oi_end;
  847. for(boost::tie(oi,oi_end) = out_edges(v,g); oi != oi_end; ++oi)
  848. forbidden_edge[*oi] = true;
  849. for(boost::tie(oi,oi_end) = out_edges(v,g); oi != oi_end; ++oi)
  850. {
  851. path_edges.clear();
  852. edge_t e(*oi);
  853. current_endpoint = target(*oi,g) == v ?
  854. source(*oi,g) : target(*oi,g);
  855. if (dfs_number[current_endpoint] < dfs_number[v] ||
  856. is_embedded[e] ||
  857. v == current_endpoint //self-loop
  858. )
  859. {
  860. //Not a backedge
  861. continue;
  862. }
  863. path_edges.push_back(e);
  864. if (goal_edge[e])
  865. {
  866. return current_endpoint;
  867. }
  868. typedef typename face_edge_iterator<>::type walkup_itr_t;
  869. walkup_itr_t
  870. walkup_itr(current_endpoint, face_handles, first_side());
  871. walkup_itr_t walkup_end;
  872. seen_goal_edge = false;
  873. while (true)
  874. {
  875. if (walkup_itr != walkup_end && forbidden_edge[*walkup_itr])
  876. break;
  877. while(walkup_itr != walkup_end &&
  878. !goal_edge[*walkup_itr] &&
  879. !forbidden_edge[*walkup_itr]
  880. )
  881. {
  882. edge_t f(*walkup_itr);
  883. forbidden_edge[f] = true;
  884. path_edges.push_back(f);
  885. current_endpoint =
  886. source(f, g) == current_endpoint ?
  887. target(f, g) :
  888. source(f,g);
  889. ++walkup_itr;
  890. }
  891. if (walkup_itr != walkup_end && goal_edge[*walkup_itr])
  892. {
  893. path_edges.push_back(*walkup_itr);
  894. seen_goal_edge = true;
  895. break;
  896. }
  897. walkup_itr
  898. = walkup_itr_t(current_endpoint, face_handles, first_side());
  899. }
  900. if (seen_goal_edge)
  901. break;
  902. }
  903. if (seen_goal_edge)
  904. return current_endpoint;
  905. else
  906. return graph_traits<Graph>::null_vertex();
  907. }
  908. template <typename OutputIterator, typename EdgeIndexMap>
  909. void extract_kuratowski_subgraph(OutputIterator o_itr, EdgeIndexMap em)
  910. {
  911. // If the main algorithm has failed to embed one of the back-edges from
  912. // a vertex v, we can use the current state of the algorithm to isolate
  913. // a Kuratowksi subgraph. The isolation process breaks down into five
  914. // cases, A - E. The general configuration of all five cases is shown in
  915. // figure 1. There is a vertex v from which the planar
  916. // v embedding process could not proceed. This means that
  917. // | there exists some bicomp containing three vertices
  918. // ----- x,y, and z as shown such that x and y are externally
  919. // | | active with respect to v (which means that there are
  920. // x y two vertices x_0 and y_0 such that (1) both x_0 and
  921. // | | y_0 are proper depth-first search ancestors of v and
  922. // --z-- (2) there are two disjoint paths, one connecting x
  923. // and x_0 and one connecting y and y_0, both consisting
  924. // fig. 1 entirely of unembedded edges). Furthermore, there
  925. // exists a vertex z_0 such that z is a depth-first
  926. // search ancestor of z_0 and (v,z_0) is an unembedded back-edge from v.
  927. // x,y and z all exist on the same bicomp, which consists entirely of
  928. // embedded edges. The five subcases break down as follows, and are
  929. // handled by the algorithm logically in the order A-E: First, if v is
  930. // not on the same bicomp as x,y, and z, a K_3_3 can be isolated - this
  931. // is case A. So, we'll assume that v is on the same bicomp as x,y, and
  932. // z. If z_0 is on a different bicomp than x,y, and z, a K_3_3 can also
  933. // be isolated - this is a case B - so we'll assume from now on that v
  934. // is on the same bicomp as x, y, and z=z_0. In this case, one can use
  935. // properties of the Boyer-Myrvold algorithm to show the existence of an
  936. // "x-y path" connecting some vertex on the "left side" of the x,y,z
  937. // bicomp with some vertex on the "right side" of the bicomp (where the
  938. // left and right are split by a line drawn through v and z.If either of
  939. // the endpoints of the x-y path is above x or y on the bicomp, a K_3_3
  940. // can be isolated - this is a case C. Otherwise, both endpoints are at
  941. // or below x and y on the bicomp. If there is a vertex alpha on the x-y
  942. // path such that alpha is not x or y and there's a path from alpha to v
  943. // that's disjoint from any of the edges on the bicomp and the x-y path,
  944. // a K_3_3 can be isolated - this is a case D. Otherwise, properties of
  945. // the Boyer-Myrvold algorithm can be used to show that another vertex
  946. // w exists on the lower half of the bicomp such that w is externally
  947. // active with respect to v. w can then be used to isolate a K_5 - this
  948. // is the configuration of case E.
  949. vertex_iterator_t vi, vi_end;
  950. edge_iterator_t ei, ei_end;
  951. out_edge_iterator_t oei, oei_end;
  952. typename std::vector<edge_t>::iterator xi, xi_end;
  953. // Clear the short-circuit edges - these are needed for the planar
  954. // testing/embedding algorithm to run in linear time, but they'll
  955. // complicate the kuratowski subgraph isolation
  956. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  957. {
  958. face_handles[*vi].reset_vertex_cache();
  959. dfs_child_handles[*vi].reset_vertex_cache();
  960. }
  961. vertex_t v = kuratowski_v;
  962. vertex_t x = kuratowski_x;
  963. vertex_t y = kuratowski_y;
  964. typedef iterator_property_map
  965. <typename std::vector<bool>::iterator, EdgeIndexMap>
  966. edge_to_bool_map_t;
  967. std::vector<bool> is_in_subgraph_vector(num_edges(g), false);
  968. edge_to_bool_map_t is_in_subgraph(is_in_subgraph_vector.begin(), em);
  969. std::vector<bool> is_embedded_vector(num_edges(g), false);
  970. edge_to_bool_map_t is_embedded(is_embedded_vector.begin(), em);
  971. typename std::vector<edge_t>::iterator embedded_itr, embedded_end;
  972. embedded_end = embedded_edges.end();
  973. for(embedded_itr = embedded_edges.begin();
  974. embedded_itr != embedded_end; ++embedded_itr
  975. )
  976. is_embedded[*embedded_itr] = true;
  977. // upper_face_vertex is true for x,y, and all vertices above x and y in
  978. // the bicomp
  979. std::vector<bool> upper_face_vertex_vector(num_vertices(g), false);
  980. vertex_to_bool_map_t upper_face_vertex
  981. (upper_face_vertex_vector.begin(), vm);
  982. std::vector<bool> lower_face_vertex_vector(num_vertices(g), false);
  983. vertex_to_bool_map_t lower_face_vertex
  984. (lower_face_vertex_vector.begin(), vm);
  985. // These next few variable declarations are all things that we need
  986. // to find.
  987. vertex_t z = graph_traits<Graph>::null_vertex();
  988. vertex_t bicomp_root;
  989. vertex_t w = graph_traits<Graph>::null_vertex();
  990. face_handle_t w_handle;
  991. face_handle_t v_dfchild_handle;
  992. vertex_t first_x_y_path_endpoint = graph_traits<Graph>::null_vertex();
  993. vertex_t second_x_y_path_endpoint = graph_traits<Graph>::null_vertex();
  994. vertex_t w_ancestor = v;
  995. detail::bm_case_t chosen_case = detail::BM_NO_CASE_CHOSEN;
  996. std::vector<edge_t> x_external_path;
  997. std::vector<edge_t> y_external_path;
  998. std::vector<edge_t> case_d_edges;
  999. std::vector<edge_t> z_v_path;
  1000. std::vector<edge_t> w_path;
  1001. //first, use a walkup to find a path from V that starts with a
  1002. //backedge from V, then goes up until it hits either X or Y
  1003. //(but doesn't find X or Y as the root of a bicomp)
  1004. typename face_vertex_iterator<>::type
  1005. x_upper_itr(x, face_handles, first_side());
  1006. typename face_vertex_iterator<>::type
  1007. x_lower_itr(x, face_handles, second_side());
  1008. typename face_vertex_iterator<>::type face_itr, face_end;
  1009. // Don't know which path from x is the upper or lower path -
  1010. // we'll find out here
  1011. for(face_itr = x_upper_itr; face_itr != face_end; ++face_itr)
  1012. {
  1013. if (*face_itr == y)
  1014. {
  1015. std::swap(x_upper_itr, x_lower_itr);
  1016. break;
  1017. }
  1018. }
  1019. upper_face_vertex[x] = true;
  1020. vertex_t current_vertex = x;
  1021. vertex_t previous_vertex;
  1022. for(face_itr = x_upper_itr; face_itr != face_end; ++face_itr)
  1023. {
  1024. previous_vertex = current_vertex;
  1025. current_vertex = *face_itr;
  1026. upper_face_vertex[current_vertex] = true;
  1027. }
  1028. v_dfchild_handle
  1029. = dfs_child_handles[canonical_dfs_child[previous_vertex]];
  1030. for(face_itr = x_lower_itr; *face_itr != y; ++face_itr)
  1031. {
  1032. vertex_t current_vertex(*face_itr);
  1033. lower_face_vertex[current_vertex] = true;
  1034. typename face_handle_list_t::iterator roots_itr, roots_end;
  1035. if (w == graph_traits<Graph>::null_vertex()) //haven't found a w yet
  1036. {
  1037. roots_end = pertinent_roots[current_vertex]->end();
  1038. for(roots_itr = pertinent_roots[current_vertex]->begin();
  1039. roots_itr != roots_end; ++roots_itr
  1040. )
  1041. {
  1042. if (low_point[canonical_dfs_child[roots_itr->first_vertex()]]
  1043. < dfs_number[v]
  1044. )
  1045. {
  1046. w = current_vertex;
  1047. w_handle = *roots_itr;
  1048. break;
  1049. }
  1050. }
  1051. }
  1052. }
  1053. for(; face_itr != face_end; ++face_itr)
  1054. {
  1055. vertex_t current_vertex(*face_itr);
  1056. upper_face_vertex[current_vertex] = true;
  1057. bicomp_root = current_vertex;
  1058. }
  1059. typedef typename face_edge_iterator<>::type walkup_itr_t;
  1060. std::vector<bool> outer_face_edge_vector(num_edges(g), false);
  1061. edge_to_bool_map_t outer_face_edge(outer_face_edge_vector.begin(), em);
  1062. walkup_itr_t walkup_end;
  1063. for(walkup_itr_t walkup_itr(x, face_handles, first_side());
  1064. walkup_itr != walkup_end; ++walkup_itr
  1065. )
  1066. {
  1067. outer_face_edge[*walkup_itr] = true;
  1068. is_in_subgraph[*walkup_itr] = true;
  1069. }
  1070. for(walkup_itr_t walkup_itr(x, face_handles, second_side());
  1071. walkup_itr != walkup_end; ++walkup_itr
  1072. )
  1073. {
  1074. outer_face_edge[*walkup_itr] = true;
  1075. is_in_subgraph[*walkup_itr] = true;
  1076. }
  1077. std::vector<bool> forbidden_edge_vector(num_edges(g), false);
  1078. edge_to_bool_map_t forbidden_edge(forbidden_edge_vector.begin(), em);
  1079. std::vector<bool> goal_edge_vector(num_edges(g), false);
  1080. edge_to_bool_map_t goal_edge(goal_edge_vector.begin(), em);
  1081. //Find external path to x and to y
  1082. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1083. {
  1084. edge_t e(*ei);
  1085. goal_edge[e]
  1086. = !outer_face_edge[e] && (source(e,g) == x || target(e,g) == x);
  1087. forbidden_edge[*ei] = outer_face_edge[*ei];
  1088. }
  1089. vertex_t x_ancestor = v;
  1090. vertex_t x_endpoint = graph_traits<Graph>::null_vertex();
  1091. while(x_endpoint == graph_traits<Graph>::null_vertex())
  1092. {
  1093. x_ancestor = dfs_parent[x_ancestor];
  1094. x_endpoint = kuratowski_walkup(x_ancestor,
  1095. forbidden_edge,
  1096. goal_edge,
  1097. is_embedded,
  1098. x_external_path
  1099. );
  1100. }
  1101. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1102. {
  1103. edge_t e(*ei);
  1104. goal_edge[e]
  1105. = !outer_face_edge[e] && (source(e,g) == y || target(e,g) == y);
  1106. forbidden_edge[*ei] = outer_face_edge[*ei];
  1107. }
  1108. vertex_t y_ancestor = v;
  1109. vertex_t y_endpoint = graph_traits<Graph>::null_vertex();
  1110. while(y_endpoint == graph_traits<Graph>::null_vertex())
  1111. {
  1112. y_ancestor = dfs_parent[y_ancestor];
  1113. y_endpoint = kuratowski_walkup(y_ancestor,
  1114. forbidden_edge,
  1115. goal_edge,
  1116. is_embedded,
  1117. y_external_path
  1118. );
  1119. }
  1120. vertex_t parent, child;
  1121. //If v isn't on the same bicomp as x and y, it's a case A
  1122. if (bicomp_root != v)
  1123. {
  1124. chosen_case = detail::BM_CASE_A;
  1125. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  1126. if (lower_face_vertex[*vi])
  1127. for(boost::tie(oei,oei_end) = out_edges(*vi,g); oei != oei_end; ++oei)
  1128. if(!outer_face_edge[*oei])
  1129. goal_edge[*oei] = true;
  1130. for(boost::tie(ei,ei_end) = edges(g); ei != ei_end; ++ei)
  1131. forbidden_edge[*ei] = outer_face_edge[*ei];
  1132. z = kuratowski_walkup
  1133. (v, forbidden_edge, goal_edge, is_embedded, z_v_path);
  1134. }
  1135. else if (w != graph_traits<Graph>::null_vertex())
  1136. {
  1137. chosen_case = detail::BM_CASE_B;
  1138. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1139. {
  1140. edge_t e(*ei);
  1141. goal_edge[e] = false;
  1142. forbidden_edge[e] = outer_face_edge[e];
  1143. }
  1144. goal_edge[w_handle.first_edge()] = true;
  1145. goal_edge[w_handle.second_edge()] = true;
  1146. z = kuratowski_walkup(v,
  1147. forbidden_edge,
  1148. goal_edge,
  1149. is_embedded,
  1150. z_v_path
  1151. );
  1152. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1153. {
  1154. forbidden_edge[*ei] = outer_face_edge[*ei];
  1155. }
  1156. typename std::vector<edge_t>::iterator pi, pi_end;
  1157. pi_end = z_v_path.end();
  1158. for(pi = z_v_path.begin(); pi != pi_end; ++pi)
  1159. {
  1160. goal_edge[*pi] = true;
  1161. }
  1162. w_ancestor = v;
  1163. vertex_t w_endpoint = graph_traits<Graph>::null_vertex();
  1164. while(w_endpoint == graph_traits<Graph>::null_vertex())
  1165. {
  1166. w_ancestor = dfs_parent[w_ancestor];
  1167. w_endpoint = kuratowski_walkup(w_ancestor,
  1168. forbidden_edge,
  1169. goal_edge,
  1170. is_embedded,
  1171. w_path
  1172. );
  1173. }
  1174. // We really want both the w walkup and the z walkup to finish on
  1175. // exactly the same edge, but for convenience (since we don't have
  1176. // control over which side of a bicomp a walkup moves up) we've
  1177. // defined the walkup to either end at w_handle.first_edge() or
  1178. // w_handle.second_edge(). If both walkups ended at different edges,
  1179. // we'll do a little surgery on the w walkup path to make it follow
  1180. // the other side of the final bicomp.
  1181. if ((w_path.back() == w_handle.first_edge() &&
  1182. z_v_path.back() == w_handle.second_edge())
  1183. ||
  1184. (w_path.back() == w_handle.second_edge() &&
  1185. z_v_path.back() == w_handle.first_edge())
  1186. )
  1187. {
  1188. walkup_itr_t wi, wi_end;
  1189. edge_t final_edge = w_path.back();
  1190. vertex_t anchor
  1191. = source(final_edge, g) == w_handle.get_anchor() ?
  1192. target(final_edge, g) : source(final_edge, g);
  1193. if (face_handles[anchor].first_edge() == final_edge)
  1194. wi = walkup_itr_t(anchor, face_handles, second_side());
  1195. else
  1196. wi = walkup_itr_t(anchor, face_handles, first_side());
  1197. w_path.pop_back();
  1198. for(; wi != wi_end; ++wi)
  1199. {
  1200. edge_t e(*wi);
  1201. if (w_path.back() == e)
  1202. w_path.pop_back();
  1203. else
  1204. w_path.push_back(e);
  1205. }
  1206. }
  1207. }
  1208. else
  1209. {
  1210. //We need to find a valid z, since the x-y path re-defines the lower
  1211. //face, and the z we found earlier may now be on the upper face.
  1212. chosen_case = detail::BM_CASE_E;
  1213. // The z we've used so far is just an externally active vertex on the
  1214. // lower face path, but may not be the z we need for a case C, D, or
  1215. // E subgraph. the z we need now is any externally active vertex on
  1216. // the lower face path with both old_face_handles edges on the outer
  1217. // face. Since we know an x-y path exists, such a z must also exist.
  1218. //TODO: find this z in the first place.
  1219. //find the new z
  1220. for(face_itr = x_lower_itr; *face_itr != y; ++face_itr)
  1221. {
  1222. vertex_t possible_z(*face_itr);
  1223. if (pertinent(possible_z,v) &&
  1224. outer_face_edge[face_handles[possible_z].old_first_edge()] &&
  1225. outer_face_edge[face_handles[possible_z].old_second_edge()]
  1226. )
  1227. {
  1228. z = possible_z;
  1229. break;
  1230. }
  1231. }
  1232. //find x-y path, and a w if one exists.
  1233. if (externally_active(z,v))
  1234. w = z;
  1235. typedef typename face_edge_iterator
  1236. <single_side, previous_iteration>::type old_face_iterator_t;
  1237. old_face_iterator_t
  1238. first_old_face_itr(z, face_handles, first_side());
  1239. old_face_iterator_t
  1240. second_old_face_itr(z, face_handles, second_side());
  1241. old_face_iterator_t old_face_itr, old_face_end;
  1242. std::vector<old_face_iterator_t> old_face_iterators;
  1243. old_face_iterators.push_back(first_old_face_itr);
  1244. old_face_iterators.push_back(second_old_face_itr);
  1245. std::vector<bool> x_y_path_vertex_vector(num_vertices(g), false);
  1246. vertex_to_bool_map_t x_y_path_vertex
  1247. (x_y_path_vertex_vector.begin(), vm);
  1248. typename std::vector<old_face_iterator_t>::iterator
  1249. of_itr, of_itr_end;
  1250. of_itr_end = old_face_iterators.end();
  1251. for(of_itr = old_face_iterators.begin();
  1252. of_itr != of_itr_end; ++of_itr
  1253. )
  1254. {
  1255. old_face_itr = *of_itr;
  1256. vertex_t previous_vertex;
  1257. bool seen_x_or_y = false;
  1258. vertex_t current_vertex = z;
  1259. for(; old_face_itr != old_face_end; ++old_face_itr)
  1260. {
  1261. edge_t e(*old_face_itr);
  1262. previous_vertex = current_vertex;
  1263. current_vertex = source(e,g) == current_vertex ?
  1264. target(e,g) : source(e,g);
  1265. if (current_vertex == x || current_vertex == y)
  1266. seen_x_or_y = true;
  1267. if (w == graph_traits<Graph>::null_vertex() &&
  1268. externally_active(current_vertex,v) &&
  1269. outer_face_edge[e] &&
  1270. outer_face_edge[*boost::next(old_face_itr)] &&
  1271. !seen_x_or_y
  1272. )
  1273. {
  1274. w = current_vertex;
  1275. }
  1276. if (!outer_face_edge[e])
  1277. {
  1278. if (!upper_face_vertex[current_vertex] &&
  1279. !lower_face_vertex[current_vertex]
  1280. )
  1281. {
  1282. x_y_path_vertex[current_vertex] = true;
  1283. }
  1284. is_in_subgraph[e] = true;
  1285. if (upper_face_vertex[source(e,g)] ||
  1286. lower_face_vertex[source(e,g)]
  1287. )
  1288. {
  1289. if (first_x_y_path_endpoint ==
  1290. graph_traits<Graph>::null_vertex()
  1291. )
  1292. first_x_y_path_endpoint = source(e,g);
  1293. else
  1294. second_x_y_path_endpoint = source(e,g);
  1295. }
  1296. if (upper_face_vertex[target(e,g)] ||
  1297. lower_face_vertex[target(e,g)]
  1298. )
  1299. {
  1300. if (first_x_y_path_endpoint ==
  1301. graph_traits<Graph>::null_vertex()
  1302. )
  1303. first_x_y_path_endpoint = target(e,g);
  1304. else
  1305. second_x_y_path_endpoint = target(e,g);
  1306. }
  1307. }
  1308. else if (previous_vertex == x || previous_vertex == y)
  1309. {
  1310. chosen_case = detail::BM_CASE_C;
  1311. }
  1312. }
  1313. }
  1314. // Look for a case D - one of v's embedded edges will connect to the
  1315. // x-y path along an inner face path.
  1316. //First, get a list of all of v's embedded child edges
  1317. out_edge_iterator_t v_edge_itr, v_edge_end;
  1318. for(boost::tie(v_edge_itr,v_edge_end) = out_edges(v,g);
  1319. v_edge_itr != v_edge_end; ++v_edge_itr
  1320. )
  1321. {
  1322. edge_t embedded_edge(*v_edge_itr);
  1323. if (!is_embedded[embedded_edge] ||
  1324. embedded_edge == dfs_parent_edge[v]
  1325. )
  1326. continue;
  1327. case_d_edges.push_back(embedded_edge);
  1328. vertex_t current_vertex
  1329. = source(embedded_edge,g) == v ?
  1330. target(embedded_edge,g) : source(embedded_edge,g);
  1331. typename face_edge_iterator<>::type
  1332. internal_face_itr, internal_face_end;
  1333. if (face_handles[current_vertex].first_vertex() == v)
  1334. {
  1335. internal_face_itr = typename face_edge_iterator<>::type
  1336. (current_vertex, face_handles, second_side());
  1337. }
  1338. else
  1339. {
  1340. internal_face_itr = typename face_edge_iterator<>::type
  1341. (current_vertex, face_handles, first_side());
  1342. }
  1343. while(internal_face_itr != internal_face_end &&
  1344. !outer_face_edge[*internal_face_itr] &&
  1345. !x_y_path_vertex[current_vertex]
  1346. )
  1347. {
  1348. edge_t e(*internal_face_itr);
  1349. case_d_edges.push_back(e);
  1350. current_vertex =
  1351. source(e,g) == current_vertex ? target(e,g) : source(e,g);
  1352. ++internal_face_itr;
  1353. }
  1354. if (x_y_path_vertex[current_vertex])
  1355. {
  1356. chosen_case = detail::BM_CASE_D;
  1357. break;
  1358. }
  1359. else
  1360. {
  1361. case_d_edges.clear();
  1362. }
  1363. }
  1364. }
  1365. if (chosen_case != detail::BM_CASE_B && chosen_case != detail::BM_CASE_A)
  1366. {
  1367. //Finding z and w.
  1368. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1369. {
  1370. edge_t e(*ei);
  1371. goal_edge[e] = !outer_face_edge[e] &&
  1372. (source(e,g) == z || target(e,g) == z);
  1373. forbidden_edge[e] = outer_face_edge[e];
  1374. }
  1375. kuratowski_walkup(v,
  1376. forbidden_edge,
  1377. goal_edge,
  1378. is_embedded,
  1379. z_v_path
  1380. );
  1381. if (chosen_case == detail::BM_CASE_E)
  1382. {
  1383. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1384. {
  1385. forbidden_edge[*ei] = outer_face_edge[*ei];
  1386. goal_edge[*ei] = !outer_face_edge[*ei] &&
  1387. (source(*ei,g) == w || target(*ei,g) == w);
  1388. }
  1389. for(boost::tie(oei, oei_end) = out_edges(w,g); oei != oei_end; ++oei)
  1390. {
  1391. if (!outer_face_edge[*oei])
  1392. goal_edge[*oei] = true;
  1393. }
  1394. typename std::vector<edge_t>::iterator pi, pi_end;
  1395. pi_end = z_v_path.end();
  1396. for(pi = z_v_path.begin(); pi != pi_end; ++pi)
  1397. {
  1398. goal_edge[*pi] = true;
  1399. }
  1400. w_ancestor = v;
  1401. vertex_t w_endpoint = graph_traits<Graph>::null_vertex();
  1402. while(w_endpoint == graph_traits<Graph>::null_vertex())
  1403. {
  1404. w_ancestor = dfs_parent[w_ancestor];
  1405. w_endpoint = kuratowski_walkup(w_ancestor,
  1406. forbidden_edge,
  1407. goal_edge,
  1408. is_embedded,
  1409. w_path
  1410. );
  1411. }
  1412. }
  1413. }
  1414. //We're done isolating the Kuratowski subgraph at this point -
  1415. //but there's still some cleaning up to do.
  1416. //Update is_in_subgraph with the paths we just found
  1417. xi_end = x_external_path.end();
  1418. for(xi = x_external_path.begin(); xi != xi_end; ++xi)
  1419. is_in_subgraph[*xi] = true;
  1420. xi_end = y_external_path.end();
  1421. for(xi = y_external_path.begin(); xi != xi_end; ++xi)
  1422. is_in_subgraph[*xi] = true;
  1423. xi_end = z_v_path.end();
  1424. for(xi = z_v_path.begin(); xi != xi_end; ++xi)
  1425. is_in_subgraph[*xi] = true;
  1426. xi_end = case_d_edges.end();
  1427. for(xi = case_d_edges.begin(); xi != xi_end; ++xi)
  1428. is_in_subgraph[*xi] = true;
  1429. xi_end = w_path.end();
  1430. for(xi = w_path.begin(); xi != xi_end; ++xi)
  1431. is_in_subgraph[*xi] = true;
  1432. child = bicomp_root;
  1433. parent = dfs_parent[child];
  1434. while(child != parent)
  1435. {
  1436. is_in_subgraph[dfs_parent_edge[child]] = true;
  1437. boost::tie(parent, child) = std::make_pair( dfs_parent[parent], parent );
  1438. }
  1439. // At this point, we've already isolated the Kuratowski subgraph and
  1440. // collected all of the edges that compose it in the is_in_subgraph
  1441. // property map. But we want the verification of such a subgraph to be
  1442. // a deterministic process, and we can simplify the function
  1443. // is_kuratowski_subgraph by cleaning up some edges here.
  1444. if (chosen_case == detail::BM_CASE_B)
  1445. {
  1446. is_in_subgraph[dfs_parent_edge[v]] = false;
  1447. }
  1448. else if (chosen_case == detail::BM_CASE_C)
  1449. {
  1450. // In a case C subgraph, at least one of the x-y path endpoints
  1451. // (call it alpha) is above either x or y on the outer face. The
  1452. // other endpoint may be attached at x or y OR above OR below. In
  1453. // any of these three cases, we can form a K_3_3 by removing the
  1454. // edge attached to v on the outer face that is NOT on the path to
  1455. // alpha.
  1456. typename face_vertex_iterator<single_side, follow_visitor>::type
  1457. face_itr, face_end;
  1458. if (face_handles[v_dfchild_handle.first_vertex()].first_edge() ==
  1459. v_dfchild_handle.first_edge()
  1460. )
  1461. {
  1462. face_itr = typename face_vertex_iterator
  1463. <single_side, follow_visitor>::type
  1464. (v_dfchild_handle.first_vertex(), face_handles, second_side());
  1465. }
  1466. else
  1467. {
  1468. face_itr = typename face_vertex_iterator
  1469. <single_side, follow_visitor>::type
  1470. (v_dfchild_handle.first_vertex(), face_handles, first_side());
  1471. }
  1472. for(; true; ++face_itr)
  1473. {
  1474. vertex_t current_vertex(*face_itr);
  1475. if (current_vertex == x || current_vertex == y)
  1476. {
  1477. is_in_subgraph[v_dfchild_handle.first_edge()] = false;
  1478. break;
  1479. }
  1480. else if (current_vertex == first_x_y_path_endpoint ||
  1481. current_vertex == second_x_y_path_endpoint)
  1482. {
  1483. is_in_subgraph[v_dfchild_handle.second_edge()] = false;
  1484. break;
  1485. }
  1486. }
  1487. }
  1488. else if (chosen_case == detail::BM_CASE_D)
  1489. {
  1490. // Need to remove both of the edges adjacent to v on the outer face.
  1491. // remove the connecting edges from v to bicomp, then
  1492. // is_kuratowski_subgraph will shrink vertices of degree 1
  1493. // automatically...
  1494. is_in_subgraph[v_dfchild_handle.first_edge()] = false;
  1495. is_in_subgraph[v_dfchild_handle.second_edge()] = false;
  1496. }
  1497. else if (chosen_case == detail::BM_CASE_E)
  1498. {
  1499. // Similarly to case C, if the endpoints of the x-y path are both
  1500. // below x and y, we should remove an edge to allow the subgraph to
  1501. // contract to a K_3_3.
  1502. if ((first_x_y_path_endpoint != x && first_x_y_path_endpoint != y) ||
  1503. (second_x_y_path_endpoint != x && second_x_y_path_endpoint != y)
  1504. )
  1505. {
  1506. is_in_subgraph[dfs_parent_edge[v]] = false;
  1507. vertex_t deletion_endpoint, other_endpoint;
  1508. if (lower_face_vertex[first_x_y_path_endpoint])
  1509. {
  1510. deletion_endpoint = second_x_y_path_endpoint;
  1511. other_endpoint = first_x_y_path_endpoint;
  1512. }
  1513. else
  1514. {
  1515. deletion_endpoint = first_x_y_path_endpoint;
  1516. other_endpoint = second_x_y_path_endpoint;
  1517. }
  1518. typename face_edge_iterator<>::type face_itr, face_end;
  1519. bool found_other_endpoint = false;
  1520. for(face_itr = typename face_edge_iterator<>::type
  1521. (deletion_endpoint, face_handles, first_side());
  1522. face_itr != face_end; ++face_itr
  1523. )
  1524. {
  1525. edge_t e(*face_itr);
  1526. if (source(e,g) == other_endpoint ||
  1527. target(e,g) == other_endpoint
  1528. )
  1529. {
  1530. found_other_endpoint = true;
  1531. break;
  1532. }
  1533. }
  1534. if (found_other_endpoint)
  1535. {
  1536. is_in_subgraph[face_handles[deletion_endpoint].first_edge()]
  1537. = false;
  1538. }
  1539. else
  1540. {
  1541. is_in_subgraph[face_handles[deletion_endpoint].second_edge()]
  1542. = false;
  1543. }
  1544. }
  1545. }
  1546. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1547. if (is_in_subgraph[*ei])
  1548. *o_itr = *ei;
  1549. }
  1550. template<typename EdgePermutation>
  1551. void make_edge_permutation(EdgePermutation perm)
  1552. {
  1553. vertex_iterator_t vi, vi_end;
  1554. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  1555. {
  1556. vertex_t v(*vi);
  1557. perm[v].clear();
  1558. face_handles[v].get_list(std::back_inserter(perm[v]));
  1559. }
  1560. }
  1561. private:
  1562. const Graph& g;
  1563. VertexIndexMap vm;
  1564. vertex_t kuratowski_v;
  1565. vertex_t kuratowski_x;
  1566. vertex_t kuratowski_y;
  1567. vertex_list_t garbage; // we delete items from linked lists by
  1568. // splicing them into garbage
  1569. //only need these two for kuratowski subgraph isolation
  1570. std::vector<vertex_t> current_merge_points;
  1571. std::vector<edge_t> embedded_edges;
  1572. //property map storage
  1573. std::vector<v_size_t> low_point_vector;
  1574. std::vector<vertex_t> dfs_parent_vector;
  1575. std::vector<v_size_t> dfs_number_vector;
  1576. std::vector<v_size_t> least_ancestor_vector;
  1577. std::vector<face_handle_list_ptr_t> pertinent_roots_vector;
  1578. std::vector<v_size_t> backedge_flag_vector;
  1579. std::vector<v_size_t> visited_vector;
  1580. std::vector< face_handle_t > face_handles_vector;
  1581. std::vector< face_handle_t > dfs_child_handles_vector;
  1582. std::vector< vertex_list_ptr_t > separated_dfs_child_list_vector;
  1583. std::vector< typename vertex_list_t::iterator >
  1584. separated_node_in_parent_list_vector;
  1585. std::vector<vertex_t> canonical_dfs_child_vector;
  1586. std::vector<bool> flipped_vector;
  1587. std::vector<edge_vector_t> backedges_vector;
  1588. edge_vector_t self_loops;
  1589. std::vector<edge_t> dfs_parent_edge_vector;
  1590. vertex_vector_t vertices_by_dfs_num;
  1591. //property maps
  1592. vertex_to_v_size_map_t low_point;
  1593. vertex_to_vertex_map_t dfs_parent;
  1594. vertex_to_v_size_map_t dfs_number;
  1595. vertex_to_v_size_map_t least_ancestor;
  1596. vertex_to_face_handle_list_ptr_map_t pertinent_roots;
  1597. vertex_to_v_size_map_t backedge_flag;
  1598. vertex_to_v_size_map_t visited;
  1599. vertex_to_face_handle_map_t face_handles;
  1600. vertex_to_face_handle_map_t dfs_child_handles;
  1601. vertex_to_vertex_list_ptr_map_t separated_dfs_child_list;
  1602. vertex_to_separated_node_map_t separated_node_in_parent_list;
  1603. vertex_to_vertex_map_t canonical_dfs_child;
  1604. vertex_to_bool_map_t flipped;
  1605. vertex_to_edge_vector_map_t backedges;
  1606. vertex_to_edge_map_t dfs_parent_edge; //only need for kuratowski
  1607. merge_stack_t merge_stack;
  1608. };
  1609. } //namespace boost
  1610. #endif //__BOYER_MYRVOLD_IMPL_HPP__