21 # ifndef SEARCH_MEMORY_LEAKS_ENABLED
22 # error SEARCH NOT ENABLED
24 # define new DEBUG_NEW
26 static char THIS_FILE[] = __FILE__;
76 while (edge_it != edge_end) {
77 if ((*edge_it).source() != (*edge_it).target()) {
94 for (;edge_it != edge_end; ++edge_it) {
95 em.
self.push_back (*edge_it);
104 int res = st_.
check(G);
114 list<pq_leaf*> neighbors;
121 list<edge> self_loops;
125 vector< list<pq_leaf*> > leaves (size);
127 for (; o_it != o_end; ++o_it) {
131 if (visited_from[opp] == st_[curr] &&
emp) {
132 em.
multi.push_back (*o_it);
134 visited_from[opp] = st_[curr];
135 tmp_leaf =
new pq_leaf (st_[opp], st_[curr], *o_it, opp);
136 leaves[st_[opp]-1].push_back (tmp_leaf);
137 neighbors.push_back (tmp_leaf);
141 em.
self.push_back (*o_it);
145 for (; i_it != i_end; ++i_it) {
149 if (visited_from[opp] == st_[curr] &&
emp) {
150 em.
multi.push_back (*i_it);
152 visited_from[opp] = st_[curr];
153 tmp_leaf =
new pq_leaf (st_[opp], st_[curr], *i_it, opp);
154 leaves[st_[opp]-1].push_back (tmp_leaf);
155 neighbors.push_back (tmp_leaf);
172 pq_tree PQ (st_[curr], curr, neighbors);
173 neighbors.erase (neighbors.begin(), neighbors.end());
177 while (st_[curr] < size) {
183 _snprintf (buffer, 12,
"%s%d.gml", filename, st_[curr]);
185 snprintf (buffer, 12,
"%s%d.gml", filename, st_[curr]);
194 if (!PQ.
reduce (leaves[st_[curr]-1])) {
196 os.open (
"fail.gml",
ios::out | ios::trunc);
218 o_it = curr.out_edges_begin();
219 o_end = curr.out_edges_end();
220 i_it = curr.in_edges_begin();
221 i_end = curr.in_edges_end();
223 for (; o_it != o_end; ++o_it) {
226 if (st_[opp] > st_[curr]) {
227 if (visited_from[opp] == st_[curr] &&
emp) {
228 em.
multi.push_back (*o_it);
230 visited_from[opp] = st_[curr];
231 tmp_leaf =
new pq_leaf (st_[opp], st_[curr], *o_it, opp);
232 leaves[st_[opp]-1].push_back (tmp_leaf);
233 neighbors.push_back (tmp_leaf);
236 }
else if (st_[opp] == st_[curr] &&
emp) {
237 em.
self.push_back (*o_it);
241 for (; i_it != i_end; ++i_it) {
244 if (st_[opp] > st_[curr]) {
245 if (visited_from[opp] == st_[curr] &&
emp) {
246 em.
multi.push_back (*i_it);
248 visited_from[opp] = st_[curr];
249 tmp_leaf =
new pq_leaf (st_[opp], st_[curr], *i_it, opp);
250 leaves[st_[opp]-1].push_back (tmp_leaf);
251 neighbors.push_back (tmp_leaf);
257 PQ.
replace_pert (st_[curr], curr, neighbors, &em, &(dirs[curr]));
265 GTL_debug::os() <<
"Direction Indicators for: " << st_[curr] <<
":: ";
266 list<direction_indicator>::iterator dit, dend;
268 for (dit = dirs[curr].
begin(), dend = dirs[curr].
end(); dit != dend; ++dit) {
270 if ((*dit).direction)
286 neighbors.erase (neighbors.begin(), neighbors.end());
299 o_it = curr.out_edges_begin();
300 o_end = curr.out_edges_end();
302 for (; o_it != o_end; ++o_it) {
303 if ((*o_it).target() == (*o_it).source()) {
304 em.
self.push_back (*o_it);
318 upward_begin.
init (G);
334 bool directed =
false;
362 c_it != c_end; ++c_it) {
406 list<edge>::iterator
it,
end;
410 for (; it !=
end; ++
it) {
413 node s = (*it).source();
414 node t = (*it).target();
438 for (; it !=
end; ++
it) {
467 node_map<list<direction_indicator> >& dirs)
471 bool* turn =
new bool[st_[*
it]];
473 for (
int i = 0;
i < st_[*
it]; ++
i) {
480 if (turn[st_[curr] - 1]) {
484 list<direction_indicator>::iterator d_it = dirs[curr].begin();
486 while (!dirs[curr].empty()) {
488 if ((*d_it).direction && turn[st_[curr] - 1] ||
489 !(*d_it).direction && !turn[st_[curr] - 1]) {
490 turn[(*d_it).id - 1] =
true;
493 d_it = dirs[curr].erase (d_it);
515 for (; it !=
end; ++
it) {
516 em.
pos (n, *it) =
it;
520 if (mark[other] == 0) {
540 list<node>::iterator
it = (*c_it).first.begin();
541 list<node>::iterator
end = (*c_it).first.end();
543 for (; it !=
end; ++
it) {
551 list<edge>::iterator e_it = (*c_it).second.begin();
552 list<edge>::iterator e_end = (*c_it).second.end();
554 for (; e_it != e_end; ++e_it) {
565 node_map<list<direction_indicator> >& dirs,
592 node greatest = fail->
n;
594 while (s_it != s_end) {
599 if (++tmp == ++(dir->
pos)) {
605 dirs[act].push_back (*dir);
620 if (st_[(*s_it)->up] > st_[greatest]) {
621 greatest = (*s_it)->up;
632 upward_begin.
init (G);
674 GTL_debug::os() <<
"Embedding so far (st_numbered): " << endl;
697 nodes[0] = (*tmp)->up;
701 nodes[2] = (*tmp)->up;
709 nodes[1] = (*tmp)->up;
711 case_C (nodes, leaves, st_, to_father, G, q_fail);
713 }
else if (!(*(q_fail->
pert_end))->is_endmost && !is_root) {
720 nodes[0] = (*tmp)->up;
724 nodes[2] = (*tmp)->up;
728 nodes[1] = (*tmp)->up;
730 case_D (nodes, leaves, st_, to_father, G, q_fail);
739 nodes[0] = (*tmp)->up;
743 nodes[2] = (*tmp)->up;
747 nodes[1] = (*tmp)->up;
749 case_D (nodes, leaves, st_, to_father, G, q_fail);
756 nodes[0] = (*tmp)->up;
760 nodes[2] = (*tmp)->up;
764 nodes[1] = (*tmp)->up;
767 case_C (nodes, leaves, st_, to_father, G, q_fail);
785 nodes[0] = (*tmp)->up;
790 nodes[1] = (*tmp)->up;
793 case_E (nodes, leaves, st_, to_father, G, q_fail);
806 nodes[0] = (*tmp)->up;
810 nodes[2] = (*tmp)->up;
819 nodes[1] = (*tmp)->up;
821 case_D (nodes, leaves, st_, to_father, G, q_fail);
834 nodes[0] = (*tmp)->up;
838 nodes[2] = (*tmp)->up;
842 nodes[1] = (*tmp)->up;
844 case_C (nodes, leaves, st_, to_father, G, q_fail);
853 GTL_debug::debug_message (
"CASE C (q_node with at least two partial children, at least one surrounded by pertinent)\n");
858 nodes[0] = (*tmp)->up;
862 nodes[2] = (*tmp)->up;
871 nodes[1] = (*tmp)->up;
873 case_C (nodes, leaves, st_, to_father, G, q_fail);
886 case_B (p_fail, act, st_, to_father, G);
895 case_A (p_fail, act, st_, to_father, G);
908 node art = p_fail->
n;
917 for (i = 0; i < 3; ++
i) {
918 q_node* q_part = (*part_pos)->
Q();
927 for (i = 0; i < 3; ++
i) {
931 assert (tmp[0] == t_node);
941 if (st_[tmp[1]] < st_[tmp[2]]) {
950 if (tmp_node != t_node) {
951 list<edge>::iterator
it,
end;
952 int max_st = st_[tmp_node];
960 if (st_[cur.
source()] > max_st || st_[cur.
target()] > max_st) {
982 node art = p_fail->
n;
1004 q_node* q_part = (*part_pos)->
Q();
1017 q_part = (*part_pos)->
Q();
1033 if (below[act.
opposite (*a_it)] == 0 && st_[act.
opposite (*a_it)] < st_[act]) {
1071 node y_0 = q_fail->
n;
1073 for (i = 0; i < 3; ++
i) {
1075 edge tmp_edge = leaves[
i]->
e;
1076 node tmp_node = leaves[
i]->
n;
1079 assert (tmp_node == nodes[i]);
1111 node y_0 = q_fail->
n;
1114 node act = leaves[1]->
n;
1123 if (below[act.
opposite (*a_it)] == 0 && st_[act.
opposite (*a_it)] < st_[act]) {
1140 for (i = 0; i < 3; ++
i) {
1142 edge tmp_edge = leaves[
i]->
e;
1143 node tmp_node = leaves[
i]->
n;
1146 assert (tmp_node == nodes[i]);
1163 if (tmp != st_.
s_node()) {
1164 list<edge>::iterator
it,
end;
1165 int min_st = st_[
tmp];
1172 if (st_[cur.
source()] < min_st || st_[cur.
target()] < min_st) {
1186 for (i = 0; i < 3; ++
i) {
1190 assert (tmp_nodes[0] == t_node);
1199 if (st_[tmp_nodes[1]] < st_[tmp_nodes[2]]) {
1208 if (tmp != t_node) {
1209 list<edge>::iterator
it,
end;
1210 int max_st = st_[
tmp];
1217 if (st_[cur.
source()] > max_st || st_[cur.
target()] > max_st) {
1239 node y_0 = q_fail->
n;
1242 node act = leaves[1]->
n;
1251 if (below[act.
opposite (*a_it)] == 0 && st_[act.
opposite (*a_it)] < st_[act]) {
1271 list<edge>::iterator paths_begin[3];
1272 list<edge>::iterator l_it, l_end;
1275 for (l_it =
ob_edges.begin(), l_end =
ob_edges.end(); l_it != l_end; ++l_it) {
1278 if (next == nodes[1]) {
1280 nodes[1] = nodes[0];
1282 pq_leaf* tmp_leaf = leaves[2];
1283 leaves[2] = leaves[0];
1284 leaves[0] = tmp_leaf;
1285 tmp_leaf = leaves[3];
1286 leaves[3] = leaves[1];
1287 leaves[1] = tmp_leaf;
1289 paths_begin[0] = l_it;
1292 }
else if (next == nodes[0]) {
1293 paths_begin[0] = l_it;
1303 for (; l_it != l_end; ++l_it) {
1306 if (next == nodes[1]) {
1307 paths_begin[1] = l_it;
1315 paths_begin[2] = --l_end;
1320 list<edge> from_act[3];
1321 list<edge>::iterator
pos;
1323 for (i = 0; i < 2; ++
i) {
1325 edge tmp_edge = leaves[2 *
i]->
e;
1326 node tmp_node = leaves[2 *
i]->
n;
1329 assert (tmp_node == nodes[i]);
1330 tmp_edge = leaves[2 * i + 1]->
e;
1331 tmp_node = leaves[2 * i + 1]->
n;
1349 for (i = 0; i < 2; ++
i) {
1352 for (l_it = ++pos, l_end =
ob_edges.end(); l_it != l_end; ++l_it) {
1353 from_where[(*l_it).source()] = i + 1;
1354 from_where[(*l_it).target()] = i + 1;
1358 assert (tmp_nodes[0] == t_node);
1368 l_it = paths_begin[0];
1369 l_end = paths_begin[1];
1372 for (i = 0; i < 3; ++
i) {
1378 }
else if (nodes[0] != y[1]) {
1385 l_it = paths_begin[1];
1386 l_end = paths_begin[2];
1390 for (i = 0; i < 3; ++
i) {
1396 }
else if (nodes[1] != y[2]) {
1404 l_end = paths_begin[0];
1407 for (i = 0; i < 3; ++
i) {
1421 if (st_[tmp_nodes[1]] < st_[tmp_nodes[2]]) {
1423 l_it = paths_begin[0];
1424 l_end = paths_begin[1];
1427 for (i = 1; i < 3; ++
i) {
1433 }
else if (st_[tmp_nodes[1]] > st_[tmp_nodes[2]]) {
1436 ob_edges.splice (
ob_edges.end(), from_act[0], from_act[0].begin(), from_act[0].end());
1439 if (from_where[last_edge.
source()] > 0) {
1440 from = from_where[last_edge.
source()];
1442 from = from_where[last_edge.
target()];
1448 ob_edges.splice (
ob_edges.end(), from_act[2], from_act[2].begin(), from_act[2].end());
1450 l_it = paths_begin[1];
1451 l_end = paths_begin[2];
1456 ob_edges.splice (
ob_edges.end(), from_act[1], from_act[1].begin(), from_act[1].end());
1459 l_end = paths_begin[0];
1466 for (i = 0; i < 3; ++
i) {
1480 switch (n->
kind()) {
1497 switch (n->
kind()) {
1530 edge tmp_edge = tmp->
e;
1531 node tmp_node = tmp->
n;
1549 while (mark[act] == 0) {
1561 while (mark[act] == 0) {
1568 if (st_[opp] > st_[act]) {
1587 while (next != start) {
1608 if (used[other] == 0 && st_[other] < stop) {
1609 to_father[other] = *
it;
1617 void planarity::write_node(ostream&
os,
int id,
int label,
int mark) {
1618 os <<
"node [\n" <<
"id " <<
id << endl;
1619 os <<
"label \"" << label <<
"\"\n";
1620 os <<
"graphics [\n" <<
"x 100\n" <<
"y 100 \n";
1622 os <<
"outline \"#ff0000\"\n";
1639 os <<
"graph [\n" <<
"directed 1" << endl;
1641 for (st_it = st_.
begin(), st_end = st_.
end(); st_it != st_end && st_[*st_it] <=
k; ++st_it) {
1642 write_node(os,
id, st_[*st_it], mark[*st_it]);
1647 for (st_it = st_.begin(), st_end = st_.end(); st_it != st_end && st_[*st_it] <=
k; ++st_it) {
1650 for (ait = (*st_it).adj_edges_begin(), aend = (*st_it).adj_edges_end(); ait != aend; ait++) {
1653 if (st_[*st_it] < st_[other]) {
1654 if(st_[other] > k) {
1655 write_node(os,
id, st_[other], mark[other]);
1659 other_id =
ids[other];
1662 os <<
"edge [\n" <<
"source " <<
ids[*st_it] <<
"\ntarget " << other_id << endl;
1663 if (*ait == to_father[*st_it] || *ait == to_father[other]) {
1664 os <<
"graphics [\n" <<
"fill \"#0000ff\"" << endl;
1665 os <<
"width 4.0\n]" << endl;
1667 os <<
"\n]" << endl;