diff --git a/deferred_planarity_test/include/mps.h b/deferred_planarity_test/include/mps.h index 4b40fa3..cd3dd22 100644 --- a/deferred_planarity_test/include/mps.h +++ b/deferred_planarity_test/include/mps.h @@ -164,6 +164,7 @@ public: int compute_removed_edge_size(string input_file, vector post_order, int mutate_point); void print_removed_edge_size(string input_file, vector post_order, int mutate_point); vector generate_post_order(string input_file); + vector generate_guided_post_order(string input_file, vector post_order); vector generate_mutated_post_order(string input_file, vector post_order, int mutate_point); void set_mutate_point(int mutate_point); int get_mutate_point(); diff --git a/deferred_planarity_test/src/main.cpp b/deferred_planarity_test/src/main.cpp index 807f24a..679bf49 100644 --- a/deferred_planarity_test/src/main.cpp +++ b/deferred_planarity_test/src/main.cpp @@ -21,6 +21,8 @@ void print_removed_edge_size(string input_file, vector post_order, int muta vector generate_post_order(string input_file); +vector generate_guided_post_order(string input_file, vector post_order); + vector generate_mutated_post_order_at_x(string input_file, vector post_order, int mutate_point); @@ -30,29 +32,36 @@ void measure_removed_edges(string input_file, int k_max, int mutate_point) { vector state_old = generate_post_order(input_file); vector state_new; - std::cout << "first generated order" << std::endl; - for (int i = 0; i < state_old.size(); i++) { - std::cout << state_old[i] << ", "; - } - std::cout << std::endl; + // std::cout << "first generated order" << std::endl; + // for (int i = 0; i < state_old.size(); i++) { + // std::cout << state_old[i] << ", "; + // } + // std::cout << std::endl; - int removed_old; + int removed_old = compute_removed_edge_size(input_file, state_old, mutate_point); int removed_new; for (int k = 0; k < k_max; ++k) { - std::cout << std::endl; - std::cout << "new generated order" << std::endl; - state_new = generate_mutated_post_order_at_x(input_file, state_old, mutate_point); - removed_old = compute_removed_edge_size(input_file, state_old, mutate_point); + // std::cout << std::endl; + // std::cout << "new generated order" << std::endl; + // rotate to prep for next run + state_new = generate_guided_post_order(input_file, state_old); + // rotate to prep for next run + // tree produced should be the same as earlier given tree, except from the mutate point + state_new = generate_mutated_post_order_at_x(input_file, state_new, mutate_point); + // for (int i = 0; i < state_new.size(); i++) { + // std::cout << state_new[i] << ", "; + // } + // std::cout << std::endl; + + // rotate to prep for next run + state_new = generate_guided_post_order(input_file, state_new); + // tree produced should be the same as tree from mutation removed_new = compute_removed_edge_size(input_file, state_new, mutate_point); - for (int i = 0; i < state_new.size(); i++) { - std::cout << state_new[i] << ", "; - } - std::cout << std::endl; - - std::cout << "removed edges in old: " << removed_old << std::endl; - std::cout << "removed edges in new: " << removed_new << std::endl; + + // std::cout << "removed edges in old: " << removed_old << std::endl; + // std::cout << "removed edges in new: " << removed_new << std::endl; print_removed_edge_size(input_file, state_new, mutate_point); diff --git a/deferred_planarity_test/src/mps.cpp b/deferred_planarity_test/src/mps.cpp index 1612f88..3bf3a74 100644 --- a/deferred_planarity_test/src/mps.cpp +++ b/deferred_planarity_test/src/mps.cpp @@ -180,14 +180,18 @@ maximal_planar_subgraph_finder::determine_edges() { //The main part of the whole algorithm: Back-edge-traversal void maximal_planar_subgraph_finder::back_edge_traversal() { - node* i_node = 0; - node* current_node = 0; + node* i_node = nullptr; + node* current_node = nullptr; int dfs_mutate_point = get_mutate_point(); int node_list_last_index = _node_list.size() - 1; - int post_order_mutate_point = node_list_last_index - dfs_mutate_point - 1; + // dfs_mutate_point starts counting from the DFS head + // post_order starts from the last leaf of the DFS tree + // hence we start counting from the post_order last index + int post_order_mutate_point = node_list_last_index - dfs_mutate_point; std::cout << "post_order_mutate_point: " << post_order_mutate_point << std::endl; // back_edge first node is higher than the second for (int i = 0; i < _back_edge_list.size(); ++i) { + // current node is the lower current_node = _back_edge_list[i].second; i_node = _back_edge_list[i].first; // back_edge_traversal returns true if it should be included diff --git a/deferred_planarity_test/src/mps_test.cpp b/deferred_planarity_test/src/mps_test.cpp index c975e6d..0977bc4 100644 --- a/deferred_planarity_test/src/mps_test.cpp +++ b/deferred_planarity_test/src/mps_test.cpp @@ -34,6 +34,11 @@ vector generate_post_order(string input_file) { return m.generate_post_order(input_file); } +vector generate_guided_post_order(string input_file, vector post_order) { + maximal_planar_subgraph_finder m; + return m.generate_guided_post_order(input_file, post_order); +} + vector generate_mutated_post_order_at_x(string input_file, vector post_order, int mutate_point) { maximal_planar_subgraph_finder m; return m.generate_mutated_post_order(input_file, post_order, mutate_point); @@ -58,6 +63,14 @@ vector maximal_planar_subgraph_finder::generate_post_order(string input_fil return return_post_order(); } +vector maximal_planar_subgraph_finder::generate_guided_post_order(string input_file, vector post_order) { + read_from_gml(input_file); + set_mutate_point(INT_MAX); // essentially remove mutate point + guidedPostOrderTraversal(post_order); + return return_post_order(); +} + + vector maximal_planar_subgraph_finder::generate_mutated_post_order(string input_file, vector post_order, int mutate_point) { read_from_gml(input_file); set_mutate_point(INT_MAX);