21 # ifndef SEARCH_MEMORY_LEAKS_ENABLED
22 # error SEARCH NOT ENABLED
24 # define new DEBUG_NEW
26 static char THIS_FILE[] = __FILE__;
74 this->
side = init_side;
103 this->
side = init_side;
132 while (edge_it != edges_end)
142 while (node_it != nodes_end)
215 while (node_it != nodes_end)
217 if (
side[*node_it] ==
A)
232 while (node_it != nodes_end)
234 if (
side[*node_it] ==
B)
297 while (node_it != nodes_end)
317 while (edge_it != edges_end)
319 if ((*edge_it).source() == (*edge_it).target())
335 bool first_edge_found =
true;
336 bool first_node_found =
true;
341 while (edge_it != edges_end)
343 if (first_edge_found)
346 first_edge_found =
false;
357 while (node_it != nodes_end)
360 if (first_node_found)
363 first_node_found =
false;
384 while (node_it != nodes_end)
386 node_vector[
i] = node_it;
410 for (i = 0; i < no_nodes; i++)
425 for (i = 0; i <= best_pos; i++)
429 side[*node_vector[
i]] =
A;
436 vector<graph::node_iterator>& node_vector)
438 srand((
unsigned)
time(NULL));
440 for (
int i = 1;
i <= vector_size;
i++)
442 int pos_1 = (int)floor((((
double)rand() / (
double)RAND_MAX) *
443 (
double)(vector_size - 1)) + 0.5);
444 int pos_2 = (int)floor((((
double)rand() / (
double)RAND_MAX) *
445 (
double)(vector_size - 1)) + 0.5);
447 temp_it = node_vector[pos_1];
448 node_vector[pos_1] = node_vector[pos_2];
449 node_vector[pos_2] = temp_it;
459 while (node_it != nodes_end)
474 int best_cutsize = -1;
476 bool improved_cutsize;
488 improved_cutsize =
false;
493 improved_cutsize =
true;
497 while (improved_cutsize);
508 while (node_it != nodes_end)
510 dest[*node_it] = source[*node_it];
525 while (edge_it != edges_end)
527 if ((
side[(*edge_it).source()] ==
A) &&
528 (
side[(*edge_it).target()] ==
A))
532 unlockedA[*edge_it].push_back((*edge_it).source());
533 unlockedA[*edge_it].push_back((*edge_it).target());
535 else if ((
side[(*edge_it).source()] ==
B) &&
536 (
side[(*edge_it).target()] ==
B))
540 unlockedB[*edge_it].push_back((*edge_it).source());
541 unlockedB[*edge_it].push_back((*edge_it).target());
543 else if ((
side[(*edge_it).source()] ==
A) &&
544 (
side[(*edge_it).target()] ==
B))
549 unlockedA[*edge_it].push_back((*edge_it).source());
550 unlockedB[*edge_it].push_back((*edge_it).target());
552 else if ((
side[(*edge_it).source()] ==
B) &&
553 (
side[(*edge_it).target()] ==
A))
558 unlockedA[*edge_it].push_back((*edge_it).target());
559 unlockedB[*edge_it].push_back((*edge_it).source());
577 bool first_A_node =
true;
578 bool first_B_node =
true;
585 while (node_it != nodes_end)
587 if (
side[*node_it] ==
A)
597 first_A_node =
false;
621 first_B_node =
false;
645 while (adj_edge_it != adj_edges_end)
647 if (
aside[*adj_edge_it] == 1)
651 if (
bside[*adj_edge_it] == 0)
666 while (adj_edge_it != adj_edges_end)
668 if (
bside[*adj_edge_it] == 1)
672 if (
aside[*adj_edge_it] == 0)
685 int best_tentative_move = 0;
696 tentative_moves[step_number] = moved_node;
697 if (tentative_cutsize[best_tentative_move] >
cur_cutsize)
699 best_tentative_move = step_number;
702 else if (tentative_cutsize[best_tentative_move] ==
cur_cutsize)
706 best_tentative_move = step_number;
712 for (
int i = 1;
i <= best_tentative_move;
i++)
714 if (
side[tentative_moves[
i]] ==
A)
716 side[tentative_moves[
i]] =
B;
720 side[tentative_moves[
i]] =
A;
723 cur_cutsize = tentative_cutsize[best_tentative_move];
745 moved_node = cons_nodeA;
750 moved_node = cons_nodeB;
758 if (bal_diff_A2B < bal_diff_B2A)
761 moved_node = cons_nodeA;
763 else if (bal_diff_B2A < bal_diff_A2B)
766 moved_node = cons_nodeB;
771 moved_node = cons_nodeA;
778 moved_node = cons_nodeA;
783 moved_node = cons_nodeB;
797 if (
side[cur_node] ==
A)
827 while (adj_edge_it != adj_edges_end)
830 unlockedA[*adj_edge_it].remove(cur_node);
831 --
aside[*adj_edge_it];
832 if (
aside[*adj_edge_it] == 0)
834 list<node>::iterator node_it =
unlockedB[*adj_edge_it].begin();
835 list<node>::iterator nodes_end =
unlockedB[*adj_edge_it].end();
836 while (node_it != nodes_end)
844 else if (
aside[*adj_edge_it] == 1)
846 list<node>::iterator node_it =
unlockedA[*adj_edge_it].begin();
847 list<node>::iterator nodes_end =
unlockedA[*adj_edge_it].end();
848 while (node_it != nodes_end)
857 ++
bside[*adj_edge_it];
858 if (
bside[*adj_edge_it] == 1)
860 list<node>::iterator node_it =
unlockedA[*adj_edge_it].begin();
861 list<node>::iterator nodes_end =
unlockedA[*adj_edge_it].end();
862 while (node_it != nodes_end)
870 else if (
bside[*adj_edge_it] == 2)
872 list<node>::iterator node_it =
unlockedB[*adj_edge_it].begin();
873 list<node>::iterator nodes_end =
unlockedB[*adj_edge_it].end();
874 while (node_it != nodes_end)
897 while (adj_edge_it != adj_edges_end)
900 unlockedB[*adj_edge_it].remove(cur_node);
901 bside[*adj_edge_it] -= 1;
902 if (
bside[*adj_edge_it] == 0)
904 list<node>::iterator node_it =
unlockedA[*adj_edge_it].begin();
905 list<node>::iterator nodes_end =
unlockedA[*adj_edge_it].end();
906 while (node_it != nodes_end)
914 else if (
bside[*adj_edge_it] == 1)
916 list<node>::iterator node_it =
unlockedB[*adj_edge_it].begin();
917 list<node>::iterator nodes_end =
unlockedB[*adj_edge_it].end();
918 while (node_it != nodes_end)
927 aside[*adj_edge_it] += 1;
928 if (
aside[*adj_edge_it] == 1)
930 list<node>::iterator node_it =
unlockedB[*adj_edge_it].begin();
931 list<node>::iterator nodes_end =
unlockedB[*adj_edge_it].end();
932 while (node_it != nodes_end)
940 else if (
aside[*adj_edge_it] == 2)
942 list<node>::iterator node_it =
unlockedA[*adj_edge_it].begin();
943 list<node>::iterator nodes_end =
unlockedA[*adj_edge_it].end();
944 while (node_it != nodes_end)
1043 while (edge_it != edges_end)
1066 while (edge_it != edges_end)
1068 if (
side[(*edge_it).source()] !=
side[(*edge_it).target()])
1083 while (node_it != nodes_end)
1085 if (
side[*node_it] ==
A)
1087 nodesA.push_back(*node_it);
1091 nodesB.push_back(*node_it);
1099 void fm_partition::print_bucketA()
1106 list<node>::iterator node_it =
bucketA[
i].begin();
1107 list<node>::iterator nodes_end =
bucketA[
i].end();
1108 while (node_it != nodes_end)
1120 void fm_partition::print_bucketB()
1127 list<node>::iterator node_it =
bucketB[
i].begin();
1128 list<node>::iterator nodes_end =
bucketB[
i].end();
1129 while (node_it != nodes_end)