Feat/Fix: add guided post traversal to rotate the tree to the correct
orientation before mutation
This commit is contained in:
parent
8794837369
commit
be49c6cfe0
|
@ -164,6 +164,7 @@ public:
|
|||
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);
|
||||
vector<int> generate_post_order(string input_file);
|
||||
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);
|
||||
void set_mutate_point(int mutate_point);
|
||||
int get_mutate_point();
|
||||
|
|
|
@ -21,6 +21,8 @@ void print_removed_edge_size(string input_file, vector<int> post_order, int muta
|
|||
|
||||
vector<int> generate_post_order(string input_file);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
@ -30,29 +32,36 @@ void measure_removed_edges(string input_file, int k_max, int mutate_point) {
|
|||
vector<int> state_old = generate_post_order(input_file);
|
||||
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;
|
||||
// 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);
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,6 +34,11 @@ vector<int> generate_post_order(string input_file) {
|
|||
return m.generate_post_order(input_file);
|
||||
}
|
||||
|
||||
vector<int> generate_guided_post_order(string input_file, vector<int> post_order) {
|
||||
maximal_planar_subgraph_finder m;
|
||||
return m.generate_guided_post_order(input_file, post_order);
|
||||
}
|
||||
|
||||
vector<int> generate_mutated_post_order_at_x(string input_file, vector<int> 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<int> maximal_planar_subgraph_finder::generate_post_order(string input_fil
|
|||
return return_post_order();
|
||||
}
|
||||
|
||||
vector<int> maximal_planar_subgraph_finder::generate_guided_post_order(string input_file, vector<int> post_order) {
|
||||
read_from_gml(input_file);
|
||||
set_mutate_point(INT_MAX); // essentially remove mutate point
|
||||
guidedPostOrderTraversal(post_order);
|
||||
return return_post_order();
|
||||
}
|
||||
|
||||
|
||||
vector<int> maximal_planar_subgraph_finder::generate_mutated_post_order(string input_file, vector<int> post_order, int mutate_point) {
|
||||
read_from_gml(input_file);
|
||||
set_mutate_point(INT_MAX);
|
||||
|
|
Loading…
Reference in New Issue