From 6c14e739aeded0638209c35e9c927536ddcceaaf Mon Sep 17 00:00:00 2001 From: Richard Wong Date: Fri, 23 Feb 2024 12:20:52 +0900 Subject: [PATCH] Finding: backedge reuse from the head of DFS tree doesn't work --- deferred_planarity_test/include/mps.h | 4 +-- deferred_planarity_test/makefile | 2 +- deferred_planarity_test/src/main.cpp | 44 +++++++++++------------- deferred_planarity_test/src/mps.cpp | 7 ++-- deferred_planarity_test/src/mps_test.cpp | 10 +++--- 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/deferred_planarity_test/include/mps.h b/deferred_planarity_test/include/mps.h index cd3dd22..1a86cb6 100644 --- a/deferred_planarity_test/include/mps.h +++ b/deferred_planarity_test/include/mps.h @@ -162,7 +162,7 @@ public: ~maximal_planar_subgraph_finder(); int find_mps(string input_file); 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); + void print_removed_edge_stats(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); @@ -170,7 +170,7 @@ public: int get_mutate_point(); node* get_new_node(node_type t); void read_from_gml(string input_file); - void output_print_removed_edge_size(); + void output_print_removed_edge_stats(); int output_int_removed_edge_size(); vector return_post_order(); void postOrderTraversal(); diff --git a/deferred_planarity_test/makefile b/deferred_planarity_test/makefile index 8a8fac8..d4b8ada 100644 --- a/deferred_planarity_test/makefile +++ b/deferred_planarity_test/makefile @@ -31,4 +31,4 @@ $(BIN_DIR) $(OBJ_DIR): .PHONY: clean clean: - rm -r $(BIN_DIR) $(OBJ_DIR) + rm -r $(OBJ_DIR) diff --git a/deferred_planarity_test/src/main.cpp b/deferred_planarity_test/src/main.cpp index 679bf49..2af5a71 100644 --- a/deferred_planarity_test/src/main.cpp +++ b/deferred_planarity_test/src/main.cpp @@ -15,55 +15,51 @@ using namespace std; + +// functions defined in mps_test.cpp 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); - +void print_removed_edge_stats(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_at_x(string input_file, vector post_order, int mutate_point); +void vector_printer(vector state) { + for (int i = 0; i < state.size(); ++i) { + std::cout << state[i] << ","; + } + std::cout << std::endl; +} + + void measure_removed_edges(string input_file, int k_max, int mutate_point) { // generate first state 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; 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; - // 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; + std::cout << "first post order" << std::endl; + vector_printer(state_old); - // rotate to prep for next run + // run mutation on canonical representation directly + state_new = generate_mutated_post_order_at_x(input_file, state_old, mutate_point); + // rotate output of mutated state to canonical representation 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); + std::cout << "mutated post order" << std::endl; + vector_printer(state_new); + // 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); - + print_removed_edge_stats(input_file, state_new, mutate_point); } diff --git a/deferred_planarity_test/src/mps.cpp b/deferred_planarity_test/src/mps.cpp index 3bf3a74..3799743 100644 --- a/deferred_planarity_test/src/mps.cpp +++ b/deferred_planarity_test/src/mps.cpp @@ -188,7 +188,7 @@ maximal_planar_subgraph_finder::back_edge_traversal() { // 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; + // 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 @@ -199,13 +199,16 @@ maximal_planar_subgraph_finder::back_edge_traversal() { if (!back_edge_traversal(current_node, i_node->post_order_index())) { // if current_node is higher than post_order_mutate_point // then it is the preserved section - if (current_node->post_order_index() >= post_order_mutate_point) { + if (current_node->post_order_index() > post_order_mutate_point) { + std::cout << "(" << current_node->node_id() << "[" << current_node->post_order_index() << "]" + << "," << i_node->node_id() << "[" << i_node->post_order_index() << "]" << ") "; _is_back_edge_eliminate[i] = NON_MUTATED_REMOVE; } else { _is_back_edge_eliminate[i] = MUTATED_REMOVE; } } } + std::cout << std::endl; } //sub-function for the for-loop of back_edge_traversal(). diff --git a/deferred_planarity_test/src/mps_test.cpp b/deferred_planarity_test/src/mps_test.cpp index 0977bc4..b3f3d3e 100644 --- a/deferred_planarity_test/src/mps_test.cpp +++ b/deferred_planarity_test/src/mps_test.cpp @@ -24,9 +24,9 @@ int compute_removed_edge_size(string input_file, vector post_order, int mut return m.compute_removed_edge_size(input_file, post_order, mutate_point); } -void print_removed_edge_size(string input_file, vector post_order, int mutate_point) { +void print_removed_edge_stats(string input_file, vector post_order, int mutate_point) { maximal_planar_subgraph_finder m; - m.print_removed_edge_size(input_file, post_order, mutate_point); + m.print_removed_edge_stats(input_file, post_order, mutate_point); } vector generate_post_order(string input_file) { @@ -90,7 +90,7 @@ int maximal_planar_subgraph_finder::compute_removed_edge_size(string input_file, return output_int_removed_edge_size(); } -void maximal_planar_subgraph_finder::print_removed_edge_size(string input_file, vector post_order, int mutate_point) { +void maximal_planar_subgraph_finder::print_removed_edge_stats(string input_file, vector post_order, int mutate_point) { read_from_gml(input_file); set_mutate_point(mutate_point); guidedPostOrderTraversal(post_order); @@ -98,7 +98,7 @@ void maximal_planar_subgraph_finder::print_removed_edge_size(string input_file, sort_adj_list(); determine_edges(); back_edge_traversal(); - output_print_removed_edge_size(); + output_print_removed_edge_stats(); } @@ -144,7 +144,7 @@ void maximal_planar_subgraph_finder::read_from_gml(string input_file) { // count the number of removed edges -void maximal_planar_subgraph_finder::output_print_removed_edge_size() { +void maximal_planar_subgraph_finder::output_print_removed_edge_stats() { int mutated_sum = 0; int preserved_sum = 0;