diff --git a/deferred_planarity_test/src/main.cpp b/deferred_planarity_test/src/main.cpp index 7a9f365..d45e3e1 100644 --- a/deferred_planarity_test/src/main.cpp +++ b/deferred_planarity_test/src/main.cpp @@ -50,8 +50,8 @@ vector repeated_mutation(const ogdf::Graph &G, int k_max, trie* trie_store) // compute_mps(G, dist(gen), temp_order, new_removed_size); // we set mutate_start_point to 0 to mutate everything every round - // temp_order = generate_mutated_post_order(G, temp_order, 0); - temp_order = generate_guided_post_order(G, temp_order); + temp_order = generate_mutated_post_order(G, temp_order, 1); + // temp_order = generate_guided_post_order(G, temp_order); temp_order = generate_guided_post_order(G, temp_order); // test if something is in the trie_store // returns false when no order is found in trie_store diff --git a/deferred_planarity_test/src/trie.cpp b/deferred_planarity_test/src/trie.cpp index 32ff1c0..d40bb7c 100644 --- a/deferred_planarity_test/src/trie.cpp +++ b/deferred_planarity_test/src/trie.cpp @@ -29,11 +29,22 @@ void trie::add_new_post_order(vector post_order, int current_position) { if (current_index >= 0) { int node_id = post_order[current_index]; - // std::cout << "added trie node for: " << node_id << std::endl; - trie* new_trie_node = new trie(node_id); - new_trie_node->add_new_post_order(post_order, current_position+1); - _next_node_list.push_back(new_trie_node); - + // only if it doesn't exist yet + // we want to check for existing node_id in the _next_node_list + // Assuming 'it' is an iterator pointing to an element in 'vec' + auto it = std::find_if(_next_node_list.begin(), _next_node_list.end(), [node_id](trie* obj) { + return obj->_node_id == node_id; + }); + // only add if not found + if (it == _next_node_list.end()) { + // std::cout << "added trie node for: " << node_id << std::endl; + trie* new_trie_node = new trie(node_id); + new_trie_node->add_new_post_order(post_order, current_position+1); + _next_node_list.push_back(new_trie_node); + // if found, then just continue + } else { + (*it)->add_new_post_order(post_order, current_position+1); + } } } @@ -51,7 +62,7 @@ bool trie::check_post_order(vector post_order, int current_position) { }); // found if (it != _next_node_list.end()) { - std::cout << (*it)->_node_id << std::endl; + // std::cout << (*it)->_node_id << std::endl; return_value = (*it)->check_post_order(post_order, current_position+1); // not found } else {