Fix: bug when decrementing with size_t
This commit is contained in:
parent
fbbc957fda
commit
0e80061f44
|
@ -10,6 +10,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <limits>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
|
@ -27,7 +27,7 @@ vector<int> generate_mutated_post_order(const ogdf::Graph &G, vector<int> post_o
|
||||||
vector<int> generate_guided_post_order(const ogdf::Graph &G, vector<int> post_order);
|
vector<int> generate_guided_post_order(const ogdf::Graph &G, vector<int> post_order);
|
||||||
|
|
||||||
void vector_printer(const vector<int>& state) {
|
void vector_printer(const vector<int>& state) {
|
||||||
for (int i = 0; i < static_cast<int>(state.size()); ++i) {
|
for (size_t i = 0; i < state.size(); ++i) {
|
||||||
std::cout << state[i] << ",";
|
std::cout << state[i] << ",";
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
@ -49,20 +49,20 @@ vector<int> repeated_mutation(const ogdf::Graph &G, int k_max, int mutate_point)
|
||||||
// mutation produces rotated view
|
// mutation produces rotated view
|
||||||
// state_new = generate_mutated_post_order(G, state_old, mutate_point);
|
// state_new = generate_mutated_post_order(G, state_old, mutate_point);
|
||||||
// simulate a mutation
|
// simulate a mutation
|
||||||
state_new = generate_guided_post_order(G, state_old);
|
// state_new = generate_guided_post_order(G, state_old);
|
||||||
|
|
||||||
// another round of guided post order gives canonical representation
|
// another round of guided post order gives canonical representation
|
||||||
state_new = generate_guided_post_order(G, state_new);
|
// state_new = generate_guided_post_order(G, state_new);
|
||||||
new_edge_size = compute_removed_edge_size(G, state_new);
|
new_edge_size = compute_removed_edge_size(G, state_old);
|
||||||
|
|
||||||
if (new_edge_size < old_edge_size) {
|
// if (new_edge_size < old_edge_size) {
|
||||||
state_old = state_new;
|
// state_old = state_new;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
vector_printer(state_new);
|
// vector_printer(state_new);
|
||||||
return state_new;
|
return state_old;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_correctness(const ogdf::Graph &G) {
|
void test_correctness(const ogdf::Graph &G) {
|
||||||
|
|
|
@ -59,18 +59,20 @@ maximal_planar_subgraph_finder::guidedPostOrderTraversal(vector<int> post_order)
|
||||||
// int start = rev_post_order[0];
|
// int start = rev_post_order[0];
|
||||||
|
|
||||||
|
|
||||||
|
// implementation 2: use unordered_map to map node_id to position in reversed post_order
|
||||||
unordered_map<int, int> node_id_to_pos;
|
unordered_map<int, int> node_id_to_pos;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
// we flip the post_order vector around
|
// we flip the post_order vector around
|
||||||
for (size_t i = post_order.size() - 1; i >= 0; --i) {
|
for (size_t i = post_order.size() - 1; i != std::numeric_limits<size_t>::max(); --i) {
|
||||||
node_id_to_pos[post_order[i]] = j++;
|
node_id_to_pos[post_order[i]] = j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int postOrderID = 0;
|
int postOrderID = 0;
|
||||||
int end_condition = _node_list.size();
|
int end_condition = _node_list.size();
|
||||||
// we start from the end of the post_order, which is the root node
|
// we start from the end of the post_order, which is the root node
|
||||||
int start = post_order[post_order.size() - 1];
|
int start = post_order[post_order.size() - 1];
|
||||||
int i = start;
|
int i = start;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (((start > 0) && (i == (start - 1))) || ((start == 0 ) && (i == end_condition - 1)))
|
if (((start > 0) && (i == (start - 1))) || ((start == 0 ) && (i == end_condition - 1)))
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
#include <ogdf/fileformats/GraphIO.h>
|
#include <ogdf/fileformats/GraphIO.h>
|
||||||
|
|
||||||
// #define DEBUG
|
// #define DEBUG
|
||||||
|
// #define TIME
|
||||||
#define TIME
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------
|
||||||
// Finding MPS
|
// Finding MPS
|
||||||
|
@ -138,14 +137,29 @@ int maximal_planar_subgraph_finder::compute_removed_edge_size(const ogdf::Graph
|
||||||
start = std::chrono::high_resolution_clock::now();
|
start = std::chrono::high_resolution_clock::now();
|
||||||
#endif
|
#endif
|
||||||
sort_adj_list();
|
sort_adj_list();
|
||||||
|
#ifdef TIME
|
||||||
|
end = std::chrono::high_resolution_clock::now();
|
||||||
|
std::cout << "sort_adj_list: " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TIME
|
||||||
|
start = std::chrono::high_resolution_clock::now();
|
||||||
|
#endif
|
||||||
determine_edges();
|
determine_edges();
|
||||||
|
#ifdef TIME
|
||||||
|
end = std::chrono::high_resolution_clock::now();
|
||||||
|
std::cout << "determine edges: " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TIME
|
||||||
|
start = std::chrono::high_resolution_clock::now();
|
||||||
|
#endif
|
||||||
back_edge_traversal();
|
back_edge_traversal();
|
||||||
#ifdef TIME
|
#ifdef TIME
|
||||||
end = std::chrono::high_resolution_clock::now();
|
end = std::chrono::high_resolution_clock::now();
|
||||||
std::cout << "remaining procedures: " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << std::endl;
|
std::cout << "back edge traversal: " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return output_removed_edge_size();
|
return output_removed_edge_size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "mps.h"
|
#include "mps.h"
|
||||||
|
|
||||||
// #define DEBUG
|
// #define DEBUG
|
||||||
#define DEBUG_MUTATION
|
// #define DEBUG_MUTATION
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------
|
||||||
// CONSTRUCTOR
|
// CONSTRUCTOR
|
||||||
|
|
Loading…
Reference in New Issue