Finding: backedge reuse from the head of DFS tree doesn't work

This commit is contained in:
Richard Wong 2024-02-23 12:20:52 +09:00
parent be49c6cfe0
commit 6c14e739ae
Signed by: richard
GPG Key ID: 5BD36BA2E9EE33D0
5 changed files with 33 additions and 34 deletions

View File

@ -162,7 +162,7 @@ public:
~maximal_planar_subgraph_finder(); ~maximal_planar_subgraph_finder();
int find_mps(string input_file); int find_mps(string input_file);
int compute_removed_edge_size(string input_file, vector<int> post_order, int mutate_point); int compute_removed_edge_size(string input_file, vector<int> post_order, int mutate_point);
void print_removed_edge_size(string input_file, vector<int> post_order, int mutate_point); void print_removed_edge_stats(string input_file, vector<int> post_order, int mutate_point);
vector<int> generate_post_order(string input_file); vector<int> generate_post_order(string input_file);
vector<int> generate_guided_post_order(string input_file, vector<int> post_order); vector<int> generate_guided_post_order(string input_file, vector<int> post_order);
vector<int> generate_mutated_post_order(string input_file, vector<int> post_order, int mutate_point); vector<int> generate_mutated_post_order(string input_file, vector<int> post_order, int mutate_point);
@ -170,7 +170,7 @@ public:
int get_mutate_point(); int get_mutate_point();
node* get_new_node(node_type t); node* get_new_node(node_type t);
void read_from_gml(string input_file); 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(); int output_int_removed_edge_size();
vector<int> return_post_order(); vector<int> return_post_order();
void postOrderTraversal(); void postOrderTraversal();

View File

@ -31,4 +31,4 @@ $(BIN_DIR) $(OBJ_DIR):
.PHONY: clean .PHONY: clean
clean: clean:
rm -r $(BIN_DIR) $(OBJ_DIR) rm -r $(OBJ_DIR)

View File

@ -15,55 +15,51 @@
using namespace std; using namespace std;
// functions defined in mps_test.cpp
int compute_removed_edge_size(string input_file, vector<int> post_order, int mutate_point); int compute_removed_edge_size(string input_file, vector<int> post_order, int mutate_point);
void print_removed_edge_stats(string input_file, vector<int> post_order, int mutate_point);
void print_removed_edge_size(string input_file, vector<int> post_order, int mutate_point);
vector<int> generate_post_order(string input_file); vector<int> generate_post_order(string input_file);
vector<int> generate_guided_post_order(string input_file, vector<int> post_order); vector<int> generate_guided_post_order(string input_file, vector<int> post_order);
vector<int> generate_mutated_post_order_at_x(string input_file, vector<int> post_order, int mutate_point); vector<int> generate_mutated_post_order_at_x(string input_file, vector<int> post_order, int mutate_point);
void vector_printer(vector<int> 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) { void measure_removed_edges(string input_file, int k_max, int mutate_point) {
// generate first state // generate first state
vector<int> state_old = generate_post_order(input_file); vector<int> state_old = generate_post_order(input_file);
vector<int> state_new; vector<int> 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_old = compute_removed_edge_size(input_file, state_old, mutate_point);
int removed_new; int removed_new;
for (int k = 0; k < k_max; ++k) { for (int k = 0; k < k_max; ++k) {
// std::cout << std::endl; std::cout << "first post order" << std::endl;
// std::cout << "new generated order" << std::endl; vector_printer(state_old);
// 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 // 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); state_new = generate_guided_post_order(input_file, state_new);
// tree produced should be the same as tree from mutation // tree produced should be the same as tree from mutation
removed_new = compute_removed_edge_size(input_file, state_new, mutate_point); 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 old: " << removed_old << std::endl;
// std::cout << "removed edges in new: " << removed_new << 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);
} }

View File

@ -188,7 +188,7 @@ maximal_planar_subgraph_finder::back_edge_traversal() {
// post_order starts from the last leaf of the DFS tree // post_order starts from the last leaf of the DFS tree
// hence we start counting from the post_order last index // hence we start counting from the post_order last index
int post_order_mutate_point = node_list_last_index - dfs_mutate_point; 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 // back_edge first node is higher than the second
for (int i = 0; i < _back_edge_list.size(); ++i) { for (int i = 0; i < _back_edge_list.size(); ++i) {
// current node is the lower // 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 (!back_edge_traversal(current_node, i_node->post_order_index())) {
// if current_node is higher than post_order_mutate_point // if current_node is higher than post_order_mutate_point
// then it is the preserved section // 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; _is_back_edge_eliminate[i] = NON_MUTATED_REMOVE;
} else { } else {
_is_back_edge_eliminate[i] = MUTATED_REMOVE; _is_back_edge_eliminate[i] = MUTATED_REMOVE;
} }
} }
} }
std::cout << std::endl;
} }
//sub-function for the for-loop of back_edge_traversal(). //sub-function for the for-loop of back_edge_traversal().

View File

@ -24,9 +24,9 @@ int compute_removed_edge_size(string input_file, vector<int> post_order, int mut
return m.compute_removed_edge_size(input_file, post_order, mutate_point); return m.compute_removed_edge_size(input_file, post_order, mutate_point);
} }
void print_removed_edge_size(string input_file, vector<int> post_order, int mutate_point) { void print_removed_edge_stats(string input_file, vector<int> post_order, int mutate_point) {
maximal_planar_subgraph_finder m; 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<int> generate_post_order(string input_file) { vector<int> 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(); return output_int_removed_edge_size();
} }
void maximal_planar_subgraph_finder::print_removed_edge_size(string input_file, vector<int> post_order, int mutate_point) { void maximal_planar_subgraph_finder::print_removed_edge_stats(string input_file, vector<int> post_order, int mutate_point) {
read_from_gml(input_file); read_from_gml(input_file);
set_mutate_point(mutate_point); set_mutate_point(mutate_point);
guidedPostOrderTraversal(post_order); guidedPostOrderTraversal(post_order);
@ -98,7 +98,7 @@ void maximal_planar_subgraph_finder::print_removed_edge_size(string input_file,
sort_adj_list(); sort_adj_list();
determine_edges(); determine_edges();
back_edge_traversal(); 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 // 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 mutated_sum = 0;
int preserved_sum = 0; int preserved_sum = 0;