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. = graph_traits<Graph>::null_vertex();
  480. vertex_t first_tail, second_tail;
  481. first_tail = second_tail = curr_face_handle.get_anchor();
  482. first_face_itr = typename face_vertex_iterator<>::type
  483. (curr_face_handle, face_handles, first_side());
  484. second_face_itr = typename face_vertex_iterator<>::type
  485. (curr_face_handle, face_handles, second_side());
  486. for(; first_face_itr != face_end; ++first_face_itr)
  487. {
  488. vertex_t face_vertex(*first_face_itr);
  489. if (pertinent(face_vertex, v) ||
  490. externally_active(face_vertex, v)
  491. )
  492. {
  493. first_side_vertex = face_vertex;
  494. second_side_vertex = face_vertex;
  495. break;
  496. }
  497. first_tail = face_vertex;
  498. }
  499. if (first_side_vertex == graph_traits<Graph>::null_vertex() ||
  500. first_side_vertex == curr_face_handle.get_anchor()
  501. )
  502. break;
  503. for(;second_face_itr != face_end; ++second_face_itr)
  504. {
  505. vertex_t face_vertex(*second_face_itr);
  506. if (pertinent(face_vertex, v) ||
  507. externally_active(face_vertex, v)
  508. )
  509. {
  510. second_side_vertex = face_vertex;
  511. break;
  512. }
  513. second_tail = face_vertex;
  514. }
  515. vertex_t chosen;
  516. bool chose_first_upper_path;
  517. if (internally_active(first_side_vertex, v))
  518. {
  519. chosen = first_side_vertex;
  520. chose_first_upper_path = true;
  521. }
  522. else if (internally_active(second_side_vertex, v))
  523. {
  524. chosen = second_side_vertex;
  525. chose_first_upper_path = false;
  526. }
  527. else if (pertinent(first_side_vertex, v))
  528. {
  529. chosen = first_side_vertex;
  530. chose_first_upper_path = true;
  531. }
  532. else if (pertinent(second_side_vertex, v))
  533. {
  534. chosen = second_side_vertex;
  535. chose_first_upper_path = false;
  536. }
  537. else
  538. {
  539. // If there's a pertinent vertex on the lower face
  540. // between the first_face_itr and the second_face_itr,
  541. // this graph isn't planar.
  542. for(;
  543. *first_face_itr != second_side_vertex;
  544. ++first_face_itr
  545. )
  546. {
  547. vertex_t p(*first_face_itr);
  548. if (pertinent(p,v))
  549. {
  550. //Found a Kuratowski subgraph
  551. kuratowski_v = v;
  552. kuratowski_x = first_side_vertex;
  553. kuratowski_y = second_side_vertex;
  554. return false;
  555. }
  556. }
  557. // Otherwise, the fact that we didn't find a pertinent
  558. // vertex on this face is fine - we should set the
  559. // short-circuit edges and break out of this loop to
  560. // start looking at a different pertinent root.
  561. if (first_side_vertex == second_side_vertex)
  562. {
  563. if (first_tail != v)
  564. {
  565. vertex_t first
  566. = face_handles[first_tail].first_vertex();
  567. vertex_t second
  568. = face_handles[first_tail].second_vertex();
  569. boost::tie(first_side_vertex, first_tail)
  570. = make_tuple(first_tail,
  571. first == first_side_vertex ?
  572. second : first
  573. );
  574. }
  575. else if (second_tail != v)
  576. {
  577. vertex_t first
  578. = face_handles[second_tail].first_vertex();
  579. vertex_t second
  580. = face_handles[second_tail].second_vertex();
  581. boost::tie(second_side_vertex, second_tail)
  582. = make_tuple(second_tail,
  583. first == second_side_vertex ?
  584. second : first);
  585. }
  586. else
  587. break;
  588. }
  589. canonical_dfs_child[first_side_vertex]
  590. = canonical_dfs_child[root_face_handle.first_vertex()];
  591. canonical_dfs_child[second_side_vertex]
  592. = canonical_dfs_child[root_face_handle.second_vertex()];
  593. root_face_handle.set_first_vertex(first_side_vertex);
  594. root_face_handle.set_second_vertex(second_side_vertex);
  595. if (face_handles[first_side_vertex].first_vertex() ==
  596. first_tail
  597. )
  598. face_handles[first_side_vertex].set_first_vertex(v);
  599. else
  600. face_handles[first_side_vertex].set_second_vertex(v);
  601. if (face_handles[second_side_vertex].first_vertex() ==
  602. second_tail
  603. )
  604. face_handles[second_side_vertex].set_first_vertex(v);
  605. else
  606. face_handles[second_side_vertex].set_second_vertex(v);
  607. break;
  608. }
  609. // When we unwind the stack, we need to know which direction
  610. // we came down from on the top face handle
  611. bool chose_first_lower_path =
  612. (chose_first_upper_path &&
  613. face_handles[chosen].first_vertex() == first_tail)
  614. ||
  615. (!chose_first_upper_path &&
  616. face_handles[chosen].first_vertex() == second_tail);
  617. //If there's a backedge at the chosen vertex, embed it now
  618. if (backedge_flag[chosen] == dfs_number[v])
  619. {
  620. w = chosen;
  621. backedge_flag[chosen] = num_vertices(g) + 1;
  622. add_to_merge_points(chosen, StoreOldHandlesPolicy());
  623. typename edge_vector_t::iterator ei, ei_end;
  624. ei_end = backedges[chosen].end();
  625. for(ei = backedges[chosen].begin(); ei != ei_end; ++ei)
  626. {
  627. edge_t e(*ei);
  628. add_to_embedded_edges(e, StoreOldHandlesPolicy());
  629. if (chose_first_lower_path)
  630. face_handles[chosen].push_first(e, g);
  631. else
  632. face_handles[chosen].push_second(e, g);
  633. }
  634. }
  635. else
  636. {
  637. merge_stack.push_back(make_tuple
  638. (chosen, chose_first_upper_path, chose_first_lower_path)
  639. );
  640. curr_face_handle = *pertinent_roots[chosen]->begin();
  641. continue;
  642. }
  643. //Unwind the merge stack to the root, merging all bicomps
  644. bool bottom_path_follows_first;
  645. bool top_path_follows_first;
  646. bool next_bottom_follows_first = chose_first_upper_path;
  647. vertex_t merge_point = chosen;
  648. while(!merge_stack.empty())
  649. {
  650. bottom_path_follows_first = next_bottom_follows_first;
  651. boost::tie(merge_point,
  652. next_bottom_follows_first,
  653. top_path_follows_first
  654. ) = merge_stack.back();
  655. merge_stack.pop_back();
  656. face_handle_t top_handle(face_handles[merge_point]);
  657. face_handle_t bottom_handle
  658. (*pertinent_roots[merge_point]->begin());
  659. vertex_t bottom_dfs_child = canonical_dfs_child
  660. [pertinent_roots[merge_point]->begin()->first_vertex()];
  661. remove_vertex_from_separated_dfs_child_list(
  662. canonical_dfs_child
  663. [pertinent_roots[merge_point]->begin()->first_vertex()]
  664. );
  665. pertinent_roots[merge_point]->pop_front();
  666. add_to_merge_points(top_handle.get_anchor(),
  667. StoreOldHandlesPolicy()
  668. );
  669. if (top_path_follows_first && bottom_path_follows_first)
  670. {
  671. bottom_handle.flip();
  672. top_handle.glue_first_to_second(bottom_handle);
  673. }
  674. else if (!top_path_follows_first &&
  675. bottom_path_follows_first
  676. )
  677. {
  678. flipped[bottom_dfs_child] = true;
  679. top_handle.glue_second_to_first(bottom_handle);
  680. }
  681. else if (top_path_follows_first &&
  682. !bottom_path_follows_first
  683. )
  684. {
  685. flipped[bottom_dfs_child] = true;
  686. top_handle.glue_first_to_second(bottom_handle);
  687. }
  688. else //!top_path_follows_first && !bottom_path_follows_first
  689. {
  690. bottom_handle.flip();
  691. top_handle.glue_second_to_first(bottom_handle);
  692. }
  693. }
  694. //Finally, embed all edges (v,w) at their upper end points
  695. canonical_dfs_child[w]
  696. = canonical_dfs_child[root_face_handle.first_vertex()];
  697. add_to_merge_points(root_face_handle.get_anchor(),
  698. StoreOldHandlesPolicy()
  699. );
  700. typename edge_vector_t::iterator ei, ei_end;
  701. ei_end = backedges[chosen].end();
  702. for(ei = backedges[chosen].begin(); ei != ei_end; ++ei)
  703. {
  704. if (next_bottom_follows_first)
  705. root_face_handle.push_first(*ei, g);
  706. else
  707. root_face_handle.push_second(*ei, g);
  708. }
  709. backedges[chosen].clear();
  710. curr_face_handle = root_face_handle;
  711. }//while(true)
  712. }//while(!pertinent_roots[v]->empty())
  713. return true;
  714. }
  715. void store_old_face_handles(graph::detail::no_old_handles) {}
  716. void store_old_face_handles(graph::detail::store_old_handles)
  717. {
  718. for(typename std::vector<vertex_t>::iterator mp_itr
  719. = current_merge_points.begin();
  720. mp_itr != current_merge_points.end(); ++mp_itr)
  721. {
  722. face_handles[*mp_itr].store_old_face_handles();
  723. }
  724. current_merge_points.clear();
  725. }
  726. void add_to_merge_points(vertex_t, graph::detail::no_old_handles) {}
  727. void add_to_merge_points(vertex_t v, graph::detail::store_old_handles)
  728. {
  729. current_merge_points.push_back(v);
  730. }
  731. void add_to_embedded_edges(edge_t, graph::detail::no_old_handles) {}
  732. void add_to_embedded_edges(edge_t e, graph::detail::store_old_handles)
  733. {
  734. embedded_edges.push_back(e);
  735. }
  736. void clean_up_embedding(graph::detail::no_embedding) {}
  737. void clean_up_embedding(graph::detail::store_embedding)
  738. {
  739. // If the graph isn't biconnected, we'll still have entries
  740. // in the separated_dfs_child_list for some vertices. Since
  741. // these represent articulation points, we can obtain a
  742. // planar embedding no matter what order we embed them in.
  743. vertex_iterator_t xi, xi_end;
  744. for(boost::tie(xi,xi_end) = vertices(g); xi != xi_end; ++xi)
  745. {
  746. if (!separated_dfs_child_list[*xi]->empty())
  747. {
  748. typename vertex_list_t::iterator yi, yi_end;
  749. yi_end = separated_dfs_child_list[*xi]->end();
  750. for(yi = separated_dfs_child_list[*xi]->begin();
  751. yi != yi_end; ++yi
  752. )
  753. {
  754. dfs_child_handles[*yi].flip();
  755. face_handles[*xi].glue_first_to_second
  756. (dfs_child_handles[*yi]);
  757. }
  758. }
  759. }
  760. // Up until this point, we've flipped bicomps lazily by setting
  761. // flipped[v] to true if the bicomp rooted at v was flipped (the
  762. // lazy aspect of this flip is that all descendents of that vertex
  763. // need to have their orientations reversed as well). Now, we
  764. // traverse the DFS tree by DFS number and perform the actual
  765. // flipping as needed
  766. typedef typename vertex_vector_t::iterator vertex_vector_itr_t;
  767. vertex_vector_itr_t vi_end = vertices_by_dfs_num.end();
  768. for(vertex_vector_itr_t vi = vertices_by_dfs_num.begin();
  769. vi != vi_end; ++vi
  770. )
  771. {
  772. vertex_t v(*vi);
  773. bool v_flipped = flipped[v];
  774. bool p_flipped = flipped[dfs_parent[v]];
  775. if (v_flipped && !p_flipped)
  776. {
  777. face_handles[v].flip();
  778. }
  779. else if (p_flipped && !v_flipped)
  780. {
  781. face_handles[v].flip();
  782. flipped[v] = true;
  783. }
  784. else
  785. {
  786. flipped[v] = false;
  787. }
  788. }
  789. // If there are any self-loops in the graph, they were flagged
  790. // during the walkup, and we should add them to the embedding now.
  791. // Adding a self loop anywhere in the embedding could never
  792. // invalidate the embedding, but they would complicate the traversal
  793. // if they were added during the walkup/walkdown.
  794. typename edge_vector_t::iterator ei, ei_end;
  795. ei_end = self_loops.end();
  796. for(ei = self_loops.begin(); ei != ei_end; ++ei)
  797. {
  798. edge_t e(*ei);
  799. face_handles[source(e,g)].push_second(e,g);
  800. }
  801. }
  802. bool pertinent(vertex_t w, vertex_t v)
  803. {
  804. // w is pertinent with respect to v if there is a backedge (v,w) or if
  805. // w is the root of a bicomp that contains a pertinent vertex.
  806. return backedge_flag[w] == dfs_number[v] || !pertinent_roots[w]->empty();
  807. }
  808. bool externally_active(vertex_t w, vertex_t v)
  809. {
  810. // Let a be any proper depth-first search ancestor of v. w is externally
  811. // active with respect to v if there exists a backedge (a,w) or a
  812. // backedge (a,w_0) for some w_0 in a descendent bicomp of w.
  813. v_size_t dfs_number_of_v = dfs_number[v];
  814. return (least_ancestor[w] < dfs_number_of_v) ||
  815. (!separated_dfs_child_list[w]->empty() &&
  816. low_point[separated_dfs_child_list[w]->front()] < dfs_number_of_v);
  817. }
  818. bool internally_active(vertex_t w, vertex_t v)
  819. {
  820. return pertinent(w,v) && !externally_active(w,v);
  821. }
  822. void remove_vertex_from_separated_dfs_child_list(vertex_t v)
  823. {
  824. typename vertex_list_t::iterator to_delete
  825. = separated_node_in_parent_list[v];
  826. garbage.splice(garbage.end(),
  827. *separated_dfs_child_list[dfs_parent[v]],
  828. to_delete,
  829. boost::next(to_delete)
  830. );
  831. }
  832. // End of the implementation of the basic Boyer-Myrvold Algorithm. The rest
  833. // of the code below implements the isolation of a Kuratowski subgraph in
  834. // the case that the input graph is not planar. This is by far the most
  835. // complicated part of the implementation.
  836. public:
  837. template <typename EdgeToBoolPropertyMap, typename EdgeContainer>
  838. vertex_t kuratowski_walkup(vertex_t v,
  839. EdgeToBoolPropertyMap forbidden_edge,
  840. EdgeToBoolPropertyMap goal_edge,
  841. EdgeToBoolPropertyMap is_embedded,
  842. EdgeContainer& path_edges
  843. )
  844. {
  845. vertex_t current_endpoint;
  846. bool seen_goal_edge = false;
  847. out_edge_iterator_t oi, oi_end;
  848. for(boost::tie(oi,oi_end) = out_edges(v,g); oi != oi_end; ++oi)
  849. forbidden_edge[*oi] = true;
  850. for(boost::tie(oi,oi_end) = out_edges(v,g); oi != oi_end; ++oi)
  851. {
  852. path_edges.clear();
  853. edge_t e(*oi);
  854. current_endpoint = target(*oi,g) == v ?
  855. source(*oi,g) : target(*oi,g);
  856. if (dfs_number[current_endpoint] < dfs_number[v] ||
  857. is_embedded[e] ||
  858. v == current_endpoint //self-loop
  859. )
  860. {
  861. //Not a backedge
  862. continue;
  863. }
  864. path_edges.push_back(e);
  865. if (goal_edge[e])
  866. {
  867. return current_endpoint;
  868. }
  869. typedef typename face_edge_iterator<>::type walkup_itr_t;
  870. walkup_itr_t
  871. walkup_itr(current_endpoint, face_handles, first_side());
  872. walkup_itr_t walkup_end;
  873. seen_goal_edge = false;
  874. while (true)
  875. {
  876. if (walkup_itr != walkup_end && forbidden_edge[*walkup_itr])
  877. break;
  878. while(walkup_itr != walkup_end &&
  879. !goal_edge[*walkup_itr] &&
  880. !forbidden_edge[*walkup_itr]
  881. )
  882. {
  883. edge_t f(*walkup_itr);
  884. forbidden_edge[f] = true;
  885. path_edges.push_back(f);
  886. current_endpoint =
  887. source(f, g) == current_endpoint ?
  888. target(f, g) :
  889. source(f,g);
  890. ++walkup_itr;
  891. }
  892. if (walkup_itr != walkup_end && goal_edge[*walkup_itr])
  893. {
  894. path_edges.push_back(*walkup_itr);
  895. seen_goal_edge = true;
  896. break;
  897. }
  898. walkup_itr
  899. = walkup_itr_t(current_endpoint, face_handles, first_side());
  900. }
  901. if (seen_goal_edge)
  902. break;
  903. }
  904. if (seen_goal_edge)
  905. return current_endpoint;
  906. else
  907. return graph_traits<Graph>::null_vertex();
  908. }
  909. template <typename OutputIterator, typename EdgeIndexMap>
  910. void extract_kuratowski_subgraph(OutputIterator o_itr, EdgeIndexMap em)
  911. {
  912. // If the main algorithm has failed to embed one of the back-edges from
  913. // a vertex v, we can use the current state of the algorithm to isolate
  914. // a Kuratowksi subgraph. The isolation process breaks down into five
  915. // cases, A - E. The general configuration of all five cases is shown in
  916. // figure 1. There is a vertex v from which the planar
  917. // v embedding process could not proceed. This means that
  918. // | there exists some bicomp containing three vertices
  919. // ----- x,y, and z as shown such that x and y are externally
  920. // | | active with respect to v (which means that there are
  921. // x y two vertices x_0 and y_0 such that (1) both x_0 and
  922. // | | y_0 are proper depth-first search ancestors of v and
  923. // --z-- (2) there are two disjoint paths, one connecting x
  924. // and x_0 and one connecting y and y_0, both consisting
  925. // fig. 1 entirely of unembedded edges). Furthermore, there
  926. // exists a vertex z_0 such that z is a depth-first
  927. // search ancestor of z_0 and (v,z_0) is an unembedded back-edge from v.
  928. // x,y and z all exist on the same bicomp, which consists entirely of
  929. // embedded edges. The five subcases break down as follows, and are
  930. // handled by the algorithm logically in the order A-E: First, if v is
  931. // not on the same bicomp as x,y, and z, a K_3_3 can be isolated - this
  932. // is case A. So, we'll assume that v is on the same bicomp as x,y, and
  933. // z. If z_0 is on a different bicomp than x,y, and z, a K_3_3 can also
  934. // be isolated - this is a case B - so we'll assume from now on that v
  935. // is on the same bicomp as x, y, and z=z_0. In this case, one can use
  936. // properties of the Boyer-Myrvold algorithm to show the existence of an
  937. // "x-y path" connecting some vertex on the "left side" of the x,y,z
  938. // bicomp with some vertex on the "right side" of the bicomp (where the
  939. // left and right are split by a line drawn through v and z.If either of
  940. // the endpoints of the x-y path is above x or y on the bicomp, a K_3_3
  941. // can be isolated - this is a case C. Otherwise, both endpoints are at
  942. // or below x and y on the bicomp. If there is a vertex alpha on the x-y
  943. // path such that alpha is not x or y and there's a path from alpha to v
  944. // that's disjoint from any of the edges on the bicomp and the x-y path,
  945. // a K_3_3 can be isolated - this is a case D. Otherwise, properties of
  946. // the Boyer-Myrvold algorithm can be used to show that another vertex
  947. // w exists on the lower half of the bicomp such that w is externally
  948. // active with respect to v. w can then be used to isolate a K_5 - this
  949. // is the configuration of case E.
  950. vertex_iterator_t vi, vi_end;
  951. edge_iterator_t ei, ei_end;
  952. out_edge_iterator_t oei, oei_end;
  953. typename std::vector<edge_t>::iterator xi, xi_end;
  954. // Clear the short-circuit edges - these are needed for the planar
  955. // testing/embedding algorithm to run in linear time, but they'll
  956. // complicate the kuratowski subgraph isolation
  957. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  958. {
  959. face_handles[*vi].reset_vertex_cache();
  960. dfs_child_handles[*vi].reset_vertex_cache();
  961. }
  962. vertex_t v = kuratowski_v;
  963. vertex_t x = kuratowski_x;
  964. vertex_t y = kuratowski_y;
  965. typedef iterator_property_map
  966. <typename std::vector<bool>::iterator, EdgeIndexMap>
  967. edge_to_bool_map_t;
  968. std::vector<bool> is_in_subgraph_vector(num_edges(g), false);
  969. edge_to_bool_map_t is_in_subgraph(is_in_subgraph_vector.begin(), em);
  970. std::vector<bool> is_embedded_vector(num_edges(g), false);
  971. edge_to_bool_map_t is_embedded(is_embedded_vector.begin(), em);
  972. typename std::vector<edge_t>::iterator embedded_itr, embedded_end;
  973. embedded_end = embedded_edges.end();
  974. for(embedded_itr = embedded_edges.begin();
  975. embedded_itr != embedded_end; ++embedded_itr
  976. )
  977. is_embedded[*embedded_itr] = true;
  978. // upper_face_vertex is true for x,y, and all vertices above x and y in
  979. // the bicomp
  980. std::vector<bool> upper_face_vertex_vector(num_vertices(g), false);
  981. vertex_to_bool_map_t upper_face_vertex
  982. (upper_face_vertex_vector.begin(), vm);
  983. std::vector<bool> lower_face_vertex_vector(num_vertices(g), false);
  984. vertex_to_bool_map_t lower_face_vertex
  985. (lower_face_vertex_vector.begin(), vm);
  986. // These next few variable declarations are all things that we need
  987. // to find.
  988. vertex_t z = graph_traits<Graph>::null_vertex();
  989. vertex_t bicomp_root;
  990. vertex_t w = graph_traits<Graph>::null_vertex();
  991. face_handle_t w_handle;
  992. face_handle_t v_dfchild_handle;
  993. vertex_t first_x_y_path_endpoint = graph_traits<Graph>::null_vertex();
  994. vertex_t second_x_y_path_endpoint = graph_traits<Graph>::null_vertex();
  995. vertex_t w_ancestor = v;
  996. detail::bm_case_t chosen_case = detail::BM_NO_CASE_CHOSEN;
  997. std::vector<edge_t> x_external_path;
  998. std::vector<edge_t> y_external_path;
  999. std::vector<edge_t> case_d_edges;
  1000. std::vector<edge_t> z_v_path;
  1001. std::vector<edge_t> w_path;
  1002. //first, use a walkup to find a path from V that starts with a
  1003. //backedge from V, then goes up until it hits either X or Y
  1004. //(but doesn't find X or Y as the root of a bicomp)
  1005. typename face_vertex_iterator<>::type
  1006. x_upper_itr(x, face_handles, first_side());
  1007. typename face_vertex_iterator<>::type
  1008. x_lower_itr(x, face_handles, second_side());
  1009. typename face_vertex_iterator<>::type face_itr, face_end;
  1010. // Don't know which path from x is the upper or lower path -
  1011. // we'll find out here
  1012. for(face_itr = x_upper_itr; face_itr != face_end; ++face_itr)
  1013. {
  1014. if (*face_itr == y)
  1015. {
  1016. std::swap(x_upper_itr, x_lower_itr);
  1017. break;
  1018. }
  1019. }
  1020. upper_face_vertex[x] = true;
  1021. vertex_t current_vertex = x;
  1022. vertex_t previous_vertex;
  1023. for(face_itr = x_upper_itr; face_itr != face_end; ++face_itr)
  1024. {
  1025. previous_vertex = current_vertex;
  1026. current_vertex = *face_itr;
  1027. upper_face_vertex[current_vertex] = true;
  1028. }
  1029. v_dfchild_handle
  1030. = dfs_child_handles[canonical_dfs_child[previous_vertex]];
  1031. for(face_itr = x_lower_itr; *face_itr != y; ++face_itr)
  1032. {
  1033. vertex_t current_vertex(*face_itr);
  1034. lower_face_vertex[current_vertex] = true;
  1035. typename face_handle_list_t::iterator roots_itr, roots_end;
  1036. if (w == graph_traits<Graph>::null_vertex()) //haven't found a w yet
  1037. {
  1038. roots_end = pertinent_roots[current_vertex]->end();
  1039. for(roots_itr = pertinent_roots[current_vertex]->begin();
  1040. roots_itr != roots_end; ++roots_itr
  1041. )
  1042. {
  1043. if (low_point[canonical_dfs_child[roots_itr->first_vertex()]]
  1044. < dfs_number[v]
  1045. )
  1046. {
  1047. w = current_vertex;
  1048. w_handle = *roots_itr;
  1049. break;
  1050. }
  1051. }
  1052. }
  1053. }
  1054. for(; face_itr != face_end; ++face_itr)
  1055. {
  1056. vertex_t current_vertex(*face_itr);
  1057. upper_face_vertex[current_vertex] = true;
  1058. bicomp_root = current_vertex;
  1059. }
  1060. typedef typename face_edge_iterator<>::type walkup_itr_t;
  1061. std::vector<bool> outer_face_edge_vector(num_edges(g), false);
  1062. edge_to_bool_map_t outer_face_edge(outer_face_edge_vector.begin(), em);
  1063. walkup_itr_t walkup_end;
  1064. for(walkup_itr_t walkup_itr(x, face_handles, first_side());
  1065. walkup_itr != walkup_end; ++walkup_itr
  1066. )
  1067. {
  1068. outer_face_edge[*walkup_itr] = true;
  1069. is_in_subgraph[*walkup_itr] = true;
  1070. }
  1071. for(walkup_itr_t walkup_itr(x, face_handles, second_side());
  1072. walkup_itr != walkup_end; ++walkup_itr
  1073. )
  1074. {
  1075. outer_face_edge[*walkup_itr] = true;
  1076. is_in_subgraph[*walkup_itr] = true;
  1077. }
  1078. std::vector<bool> forbidden_edge_vector(num_edges(g), false);
  1079. edge_to_bool_map_t forbidden_edge(forbidden_edge_vector.begin(), em);
  1080. std::vector<bool> goal_edge_vector(num_edges(g), false);
  1081. edge_to_bool_map_t goal_edge(goal_edge_vector.begin(), em);
  1082. //Find external path to x and to y
  1083. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1084. {
  1085. edge_t e(*ei);
  1086. goal_edge[e]
  1087. = !outer_face_edge[e] && (source(e,g) == x || target(e,g) == x);
  1088. forbidden_edge[*ei] = outer_face_edge[*ei];
  1089. }
  1090. vertex_t x_ancestor = v;
  1091. vertex_t x_endpoint = graph_traits<Graph>::null_vertex();
  1092. while(x_endpoint == graph_traits<Graph>::null_vertex())
  1093. {
  1094. x_ancestor = dfs_parent[x_ancestor];
  1095. x_endpoint = kuratowski_walkup(x_ancestor,
  1096. forbidden_edge,
  1097. goal_edge,
  1098. is_embedded,
  1099. x_external_path
  1100. );
  1101. }
  1102. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1103. {
  1104. edge_t e(*ei);
  1105. goal_edge[e]
  1106. = !outer_face_edge[e] && (source(e,g) == y || target(e,g) == y);
  1107. forbidden_edge[*ei] = outer_face_edge[*ei];
  1108. }
  1109. vertex_t y_ancestor = v;
  1110. vertex_t y_endpoint = graph_traits<Graph>::null_vertex();
  1111. while(y_endpoint == graph_traits<Graph>::null_vertex())
  1112. {
  1113. y_ancestor = dfs_parent[y_ancestor];
  1114. y_endpoint = kuratowski_walkup(y_ancestor,
  1115. forbidden_edge,
  1116. goal_edge,
  1117. is_embedded,
  1118. y_external_path
  1119. );
  1120. }
  1121. vertex_t parent, child;
  1122. //If v isn't on the same bicomp as x and y, it's a case A
  1123. if (bicomp_root != v)
  1124. {
  1125. chosen_case = detail::BM_CASE_A;
  1126. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  1127. if (lower_face_vertex[*vi])
  1128. for(boost::tie(oei,oei_end) = out_edges(*vi,g); oei != oei_end; ++oei)
  1129. if(!outer_face_edge[*oei])
  1130. goal_edge[*oei] = true;
  1131. for(boost::tie(ei,ei_end) = edges(g); ei != ei_end; ++ei)
  1132. forbidden_edge[*ei] = outer_face_edge[*ei];
  1133. z = kuratowski_walkup
  1134. (v, forbidden_edge, goal_edge, is_embedded, z_v_path);
  1135. }
  1136. else if (w != graph_traits<Graph>::null_vertex())
  1137. {
  1138. chosen_case = detail::BM_CASE_B;
  1139. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1140. {
  1141. edge_t e(*ei);
  1142. goal_edge[e] = false;
  1143. forbidden_edge[e] = outer_face_edge[e];
  1144. }
  1145. goal_edge[w_handle.first_edge()] = true;
  1146. goal_edge[w_handle.second_edge()] = true;
  1147. z = kuratowski_walkup(v,
  1148. forbidden_edge,
  1149. goal_edge,
  1150. is_embedded,
  1151. z_v_path
  1152. );
  1153. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1154. {
  1155. forbidden_edge[*ei] = outer_face_edge[*ei];
  1156. }
  1157. typename std::vector<edge_t>::iterator pi, pi_end;
  1158. pi_end = z_v_path.end();
  1159. for(pi = z_v_path.begin(); pi != pi_end; ++pi)
  1160. {
  1161. goal_edge[*pi] = true;
  1162. }
  1163. w_ancestor = v;
  1164. vertex_t w_endpoint = graph_traits<Graph>::null_vertex();
  1165. while(w_endpoint == graph_traits<Graph>::null_vertex())
  1166. {
  1167. w_ancestor = dfs_parent[w_ancestor];
  1168. w_endpoint = kuratowski_walkup(w_ancestor,
  1169. forbidden_edge,
  1170. goal_edge,
  1171. is_embedded,
  1172. w_path
  1173. );
  1174. }
  1175. // We really want both the w walkup and the z walkup to finish on
  1176. // exactly the same edge, but for convenience (since we don't have
  1177. // control over which side of a bicomp a walkup moves up) we've
  1178. // defined the walkup to either end at w_handle.first_edge() or
  1179. // w_handle.second_edge(). If both walkups ended at different edges,
  1180. // we'll do a little surgery on the w walkup path to make it follow
  1181. // the other side of the final bicomp.
  1182. if ((w_path.back() == w_handle.first_edge() &&
  1183. z_v_path.back() == w_handle.second_edge())
  1184. ||
  1185. (w_path.back() == w_handle.second_edge() &&
  1186. z_v_path.back() == w_handle.first_edge())
  1187. )
  1188. {
  1189. walkup_itr_t wi, wi_end;
  1190. edge_t final_edge = w_path.back();
  1191. vertex_t anchor
  1192. = source(final_edge, g) == w_handle.get_anchor() ?
  1193. target(final_edge, g) : source(final_edge, g);
  1194. if (face_handles[anchor].first_edge() == final_edge)
  1195. wi = walkup_itr_t(anchor, face_handles, second_side());
  1196. else
  1197. wi = walkup_itr_t(anchor, face_handles, first_side());
  1198. w_path.pop_back();
  1199. for(; wi != wi_end; ++wi)
  1200. {
  1201. edge_t e(*wi);
  1202. if (w_path.back() == e)
  1203. w_path.pop_back();
  1204. else
  1205. w_path.push_back(e);
  1206. }
  1207. }
  1208. }
  1209. else
  1210. {
  1211. //We need to find a valid z, since the x-y path re-defines the lower
  1212. //face, and the z we found earlier may now be on the upper face.
  1213. chosen_case = detail::BM_CASE_E;
  1214. // The z we've used so far is just an externally active vertex on the
  1215. // lower face path, but may not be the z we need for a case C, D, or
  1216. // E subgraph. the z we need now is any externally active vertex on
  1217. // the lower face path with both old_face_handles edges on the outer
  1218. // face. Since we know an x-y path exists, such a z must also exist.
  1219. //TODO: find this z in the first place.
  1220. //find the new z
  1221. for(face_itr = x_lower_itr; *face_itr != y; ++face_itr)
  1222. {
  1223. vertex_t possible_z(*face_itr);
  1224. if (pertinent(possible_z,v) &&
  1225. outer_face_edge[face_handles[possible_z].old_first_edge()] &&
  1226. outer_face_edge[face_handles[possible_z].old_second_edge()]
  1227. )
  1228. {
  1229. z = possible_z;
  1230. break;
  1231. }
  1232. }
  1233. //find x-y path, and a w if one exists.
  1234. if (externally_active(z,v))
  1235. w = z;
  1236. typedef typename face_edge_iterator
  1237. <single_side, previous_iteration>::type old_face_iterator_t;
  1238. old_face_iterator_t
  1239. first_old_face_itr(z, face_handles, first_side());
  1240. old_face_iterator_t
  1241. second_old_face_itr(z, face_handles, second_side());
  1242. old_face_iterator_t old_face_itr, old_face_end;
  1243. std::vector<old_face_iterator_t> old_face_iterators;
  1244. old_face_iterators.push_back(first_old_face_itr);
  1245. old_face_iterators.push_back(second_old_face_itr);
  1246. std::vector<bool> x_y_path_vertex_vector(num_vertices(g), false);
  1247. vertex_to_bool_map_t x_y_path_vertex
  1248. (x_y_path_vertex_vector.begin(), vm);
  1249. typename std::vector<old_face_iterator_t>::iterator
  1250. of_itr, of_itr_end;
  1251. of_itr_end = old_face_iterators.end();
  1252. for(of_itr = old_face_iterators.begin();
  1253. of_itr != of_itr_end; ++of_itr
  1254. )
  1255. {
  1256. old_face_itr = *of_itr;
  1257. vertex_t previous_vertex;
  1258. bool seen_x_or_y = false;
  1259. vertex_t current_vertex = z;
  1260. for(; old_face_itr != old_face_end; ++old_face_itr)
  1261. {
  1262. edge_t e(*old_face_itr);
  1263. previous_vertex = current_vertex;
  1264. current_vertex = source(e,g) == current_vertex ?
  1265. target(e,g) : source(e,g);
  1266. if (current_vertex == x || current_vertex == y)
  1267. seen_x_or_y = true;
  1268. if (w == graph_traits<Graph>::null_vertex() &&
  1269. externally_active(current_vertex,v) &&
  1270. outer_face_edge[e] &&
  1271. outer_face_edge[*boost::next(old_face_itr)] &&
  1272. !seen_x_or_y
  1273. )
  1274. {
  1275. w = current_vertex;
  1276. }
  1277. if (!outer_face_edge[e])
  1278. {
  1279. if (!upper_face_vertex[current_vertex] &&
  1280. !lower_face_vertex[current_vertex]
  1281. )
  1282. {
  1283. x_y_path_vertex[current_vertex] = true;
  1284. }
  1285. is_in_subgraph[e] = true;
  1286. if (upper_face_vertex[source(e,g)] ||
  1287. lower_face_vertex[source(e,g)]
  1288. )
  1289. {
  1290. if (first_x_y_path_endpoint ==
  1291. graph_traits<Graph>::null_vertex()
  1292. )
  1293. first_x_y_path_endpoint = source(e,g);
  1294. else
  1295. second_x_y_path_endpoint = source(e,g);
  1296. }
  1297. if (upper_face_vertex[target(e,g)] ||
  1298. lower_face_vertex[target(e,g)]
  1299. )
  1300. {
  1301. if (first_x_y_path_endpoint ==
  1302. graph_traits<Graph>::null_vertex()
  1303. )
  1304. first_x_y_path_endpoint = target(e,g);
  1305. else
  1306. second_x_y_path_endpoint = target(e,g);
  1307. }
  1308. }
  1309. else if (previous_vertex == x || previous_vertex == y)
  1310. {
  1311. chosen_case = detail::BM_CASE_C;
  1312. }
  1313. }
  1314. }
  1315. // Look for a case D - one of v's embedded edges will connect to the
  1316. // x-y path along an inner face path.
  1317. //First, get a list of all of v's embedded child edges
  1318. out_edge_iterator_t v_edge_itr, v_edge_end;
  1319. for(boost::tie(v_edge_itr,v_edge_end) = out_edges(v,g);
  1320. v_edge_itr != v_edge_end; ++v_edge_itr
  1321. )
  1322. {
  1323. edge_t embedded_edge(*v_edge_itr);
  1324. if (!is_embedded[embedded_edge] ||
  1325. embedded_edge == dfs_parent_edge[v]
  1326. )
  1327. continue;
  1328. case_d_edges.push_back(embedded_edge);
  1329. vertex_t current_vertex
  1330. = source(embedded_edge,g) == v ?
  1331. target(embedded_edge,g) : source(embedded_edge,g);
  1332. typename face_edge_iterator<>::type
  1333. internal_face_itr, internal_face_end;
  1334. if (face_handles[current_vertex].first_vertex() == v)
  1335. {
  1336. internal_face_itr = typename face_edge_iterator<>::type
  1337. (current_vertex, face_handles, second_side());
  1338. }
  1339. else
  1340. {
  1341. internal_face_itr = typename face_edge_iterator<>::type
  1342. (current_vertex, face_handles, first_side());
  1343. }
  1344. while(internal_face_itr != internal_face_end &&
  1345. !outer_face_edge[*internal_face_itr] &&
  1346. !x_y_path_vertex[current_vertex]
  1347. )
  1348. {
  1349. edge_t e(*internal_face_itr);
  1350. case_d_edges.push_back(e);
  1351. current_vertex =
  1352. source(e,g) == current_vertex ? target(e,g) : source(e,g);
  1353. ++internal_face_itr;
  1354. }
  1355. if (x_y_path_vertex[current_vertex])
  1356. {
  1357. chosen_case = detail::BM_CASE_D;
  1358. break;
  1359. }
  1360. else
  1361. {
  1362. case_d_edges.clear();
  1363. }
  1364. }
  1365. }
  1366. if (chosen_case != detail::BM_CASE_B && chosen_case != detail::BM_CASE_A)
  1367. {
  1368. //Finding z and w.
  1369. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1370. {
  1371. edge_t e(*ei);
  1372. goal_edge[e] = !outer_face_edge[e] &&
  1373. (source(e,g) == z || target(e,g) == z);
  1374. forbidden_edge[e] = outer_face_edge[e];
  1375. }
  1376. kuratowski_walkup(v,
  1377. forbidden_edge,
  1378. goal_edge,
  1379. is_embedded,
  1380. z_v_path
  1381. );
  1382. if (chosen_case == detail::BM_CASE_E)
  1383. {
  1384. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1385. {
  1386. forbidden_edge[*ei] = outer_face_edge[*ei];
  1387. goal_edge[*ei] = !outer_face_edge[*ei] &&
  1388. (source(*ei,g) == w || target(*ei,g) == w);
  1389. }
  1390. for(boost::tie(oei, oei_end) = out_edges(w,g); oei != oei_end; ++oei)
  1391. {
  1392. if (!outer_face_edge[*oei])
  1393. goal_edge[*oei] = true;
  1394. }
  1395. typename std::vector<edge_t>::iterator pi, pi_end;
  1396. pi_end = z_v_path.end();
  1397. for(pi = z_v_path.begin(); pi != pi_end; ++pi)
  1398. {
  1399. goal_edge[*pi] = true;
  1400. }
  1401. w_ancestor = v;
  1402. vertex_t w_endpoint = graph_traits<Graph>::null_vertex();
  1403. while(w_endpoint == graph_traits<Graph>::null_vertex())
  1404. {
  1405. w_ancestor = dfs_parent[w_ancestor];
  1406. w_endpoint = kuratowski_walkup(w_ancestor,
  1407. forbidden_edge,
  1408. goal_edge,
  1409. is_embedded,
  1410. w_path
  1411. );
  1412. }
  1413. }
  1414. }
  1415. //We're done isolating the Kuratowski subgraph at this point -
  1416. //but there's still some cleaning up to do.
  1417. //Update is_in_subgraph with the paths we just found
  1418. xi_end = x_external_path.end();
  1419. for(xi = x_external_path.begin(); xi != xi_end; ++xi)
  1420. is_in_subgraph[*xi] = true;
  1421. xi_end = y_external_path.end();
  1422. for(xi = y_external_path.begin(); xi != xi_end; ++xi)
  1423. is_in_subgraph[*xi] = true;
  1424. xi_end = z_v_path.end();
  1425. for(xi = z_v_path.begin(); xi != xi_end; ++xi)
  1426. is_in_subgraph[*xi] = true;
  1427. xi_end = case_d_edges.end();
  1428. for(xi = case_d_edges.begin(); xi != xi_end; ++xi)
  1429. is_in_subgraph[*xi] = true;
  1430. xi_end = w_path.end();
  1431. for(xi = w_path.begin(); xi != xi_end; ++xi)
  1432. is_in_subgraph[*xi] = true;
  1433. child = bicomp_root;
  1434. parent = dfs_parent[child];
  1435. while(child != parent)
  1436. {
  1437. is_in_subgraph[dfs_parent_edge[child]] = true;
  1438. boost::tie(parent, child) = std::make_pair( dfs_parent[parent], parent );
  1439. }
  1440. // At this point, we've already isolated the Kuratowski subgraph and
  1441. // collected all of the edges that compose it in the is_in_subgraph
  1442. // property map. But we want the verification of such a subgraph to be
  1443. // a deterministic process, and we can simplify the function
  1444. // is_kuratowski_subgraph by cleaning up some edges here.
  1445. if (chosen_case == detail::BM_CASE_B)
  1446. {
  1447. is_in_subgraph[dfs_parent_edge[v]] = false;
  1448. }
  1449. else if (chosen_case == detail::BM_CASE_C)
  1450. {
  1451. // In a case C subgraph, at least one of the x-y path endpoints
  1452. // (call it alpha) is above either x or y on the outer face. The
  1453. // other endpoint may be attached at x or y OR above OR below. In
  1454. // any of these three cases, we can form a K_3_3 by removing the
  1455. // edge attached to v on the outer face that is NOT on the path to
  1456. // alpha.
  1457. typename face_vertex_iterator<single_side, follow_visitor>::type
  1458. face_itr, face_end;
  1459. if (face_handles[v_dfchild_handle.first_vertex()].first_edge() ==
  1460. v_dfchild_handle.first_edge()
  1461. )
  1462. {
  1463. face_itr = typename face_vertex_iterator
  1464. <single_side, follow_visitor>::type
  1465. (v_dfchild_handle.first_vertex(), face_handles, second_side());
  1466. }
  1467. else
  1468. {
  1469. face_itr = typename face_vertex_iterator
  1470. <single_side, follow_visitor>::type
  1471. (v_dfchild_handle.first_vertex(), face_handles, first_side());
  1472. }
  1473. for(; true; ++face_itr)
  1474. {
  1475. vertex_t current_vertex(*face_itr);
  1476. if (current_vertex == x || current_vertex == y)
  1477. {
  1478. is_in_subgraph[v_dfchild_handle.first_edge()] = false;
  1479. break;
  1480. }
  1481. else if (current_vertex == first_x_y_path_endpoint ||
  1482. current_vertex == second_x_y_path_endpoint)
  1483. {
  1484. is_in_subgraph[v_dfchild_handle.second_edge()] = false;
  1485. break;
  1486. }
  1487. }
  1488. }
  1489. else if (chosen_case == detail::BM_CASE_D)
  1490. {
  1491. // Need to remove both of the edges adjacent to v on the outer face.
  1492. // remove the connecting edges from v to bicomp, then
  1493. // is_kuratowski_subgraph will shrink vertices of degree 1
  1494. // automatically...
  1495. is_in_subgraph[v_dfchild_handle.first_edge()] = false;
  1496. is_in_subgraph[v_dfchild_handle.second_edge()] = false;
  1497. }
  1498. else if (chosen_case == detail::BM_CASE_E)
  1499. {
  1500. // Similarly to case C, if the endpoints of the x-y path are both
  1501. // below x and y, we should remove an edge to allow the subgraph to
  1502. // contract to a K_3_3.
  1503. if ((first_x_y_path_endpoint != x && first_x_y_path_endpoint != y) ||
  1504. (second_x_y_path_endpoint != x && second_x_y_path_endpoint != y)
  1505. )
  1506. {
  1507. is_in_subgraph[dfs_parent_edge[v]] = false;
  1508. vertex_t deletion_endpoint, other_endpoint;
  1509. if (lower_face_vertex[first_x_y_path_endpoint])
  1510. {
  1511. deletion_endpoint = second_x_y_path_endpoint;
  1512. other_endpoint = first_x_y_path_endpoint;
  1513. }
  1514. else
  1515. {
  1516. deletion_endpoint = first_x_y_path_endpoint;
  1517. other_endpoint = second_x_y_path_endpoint;
  1518. }
  1519. typename face_edge_iterator<>::type face_itr, face_end;
  1520. bool found_other_endpoint = false;
  1521. for(face_itr = typename face_edge_iterator<>::type
  1522. (deletion_endpoint, face_handles, first_side());
  1523. face_itr != face_end; ++face_itr
  1524. )
  1525. {
  1526. edge_t e(*face_itr);
  1527. if (source(e,g) == other_endpoint ||
  1528. target(e,g) == other_endpoint
  1529. )
  1530. {
  1531. found_other_endpoint = true;
  1532. break;
  1533. }
  1534. }
  1535. if (found_other_endpoint)
  1536. {
  1537. is_in_subgraph[face_handles[deletion_endpoint].first_edge()]
  1538. = false;
  1539. }
  1540. else
  1541. {
  1542. is_in_subgraph[face_handles[deletion_endpoint].second_edge()]
  1543. = false;
  1544. }
  1545. }
  1546. }
  1547. for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  1548. if (is_in_subgraph[*ei])
  1549. *o_itr = *ei;
  1550. }
  1551. template<typename EdgePermutation>
  1552. void make_edge_permutation(EdgePermutation perm)
  1553. {
  1554. vertex_iterator_t vi, vi_end;
  1555. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  1556. {
  1557. vertex_t v(*vi);
  1558. perm[v].clear();
  1559. face_handles[v].get_list(std::back_inserter(perm[v]));
  1560. }
  1561. }
  1562. private:
  1563. const Graph& g;
  1564. VertexIndexMap vm;
  1565. vertex_t kuratowski_v;
  1566. vertex_t kuratowski_x;
  1567. vertex_t kuratowski_y;
  1568. vertex_list_t garbage; // we delete items from linked lists by
  1569. // splicing them into garbage
  1570. //only need these two for kuratowski subgraph isolation
  1571. std::vector<vertex_t> current_merge_points;
  1572. std::vector<edge_t> embedded_edges;
  1573. //property map storage
  1574. std::vector<v_size_t> low_point_vector;
  1575. std::vector<vertex_t> dfs_parent_vector;
  1576. std::vector<v_size_t> dfs_number_vector;
  1577. std::vector<v_size_t> least_ancestor_vector;
  1578. std::vector<face_handle_list_ptr_t> pertinent_roots_vector;
  1579. std::vector<v_size_t> backedge_flag_vector;
  1580. std::vector<v_size_t> visited_vector;
  1581. std::vector< face_handle_t > face_handles_vector;
  1582. std::vector< face_handle_t > dfs_child_handles_vector;
  1583. std::vector< vertex_list_ptr_t > separated_dfs_child_list_vector;
  1584. std::vector< typename vertex_list_t::iterator >
  1585. separated_node_in_parent_list_vector;
  1586. std::vector<vertex_t> canonical_dfs_child_vector;
  1587. std::vector<bool> flipped_vector;
  1588. std::vector<edge_vector_t> backedges_vector;
  1589. edge_vector_t self_loops;
  1590. std::vector<edge_t> dfs_parent_edge_vector;
  1591. vertex_vector_t vertices_by_dfs_num;
  1592. //property maps
  1593. vertex_to_v_size_map_t low_point;
  1594. vertex_to_vertex_map_t dfs_parent;
  1595. vertex_to_v_size_map_t dfs_number;
  1596. vertex_to_v_size_map_t least_ancestor;
  1597. vertex_to_face_handle_list_ptr_map_t pertinent_roots;
  1598. vertex_to_v_size_map_t backedge_flag;
  1599. vertex_to_v_size_map_t visited;
  1600. vertex_to_face_handle_map_t face_handles;
  1601. vertex_to_face_handle_map_t dfs_child_handles;
  1602. vertex_to_vertex_list_ptr_map_t separated_dfs_child_list;
  1603. vertex_to_separated_node_map_t separated_node_in_parent_list;
  1604. vertex_to_vertex_map_t canonical_dfs_child;
  1605. vertex_to_bool_map_t flipped;
  1606. vertex_to_edge_vector_map_t backedges;
  1607. vertex_to_edge_map_t dfs_parent_edge; //only need for kuratowski
  1608. merge_stack_t merge_stack;
  1609. };
  1610. } //namespace boost
  1611. #endif //__BOYER_MYRVOLD_IMPL_HPP__