diff --git a/deferred_planarity_test/src/main.cpp b/deferred_planarity_test/src/main.cpp index 82972c0..5a6c3d1 100644 --- a/deferred_planarity_test/src/main.cpp +++ b/deferred_planarity_test/src/main.cpp @@ -27,7 +27,7 @@ vector generate_mutated_post_order(const ogdf::Graph &G, vector post_o vector generate_guided_post_order(const ogdf::Graph &G, vector post_order); void vector_printer(const vector& state) { - for (int i = 0; i < state.size(); ++i) { + for (int i = 0; i < static_cast(state.size()); ++i) { std::cout << state[i] << ","; } std::cout << std::endl; @@ -67,8 +67,7 @@ vector repeated_mutation(const ogdf::Graph &G, int k_max, int mutate_point) void test_correctness(const ogdf::Graph &G) { vector state_old = generate_post_order(G); - int num_removed_edges; - num_removed_edges = compute_removed_edge_size(G, state_old); + compute_removed_edge_size(G, state_old); } diff --git a/deferred_planarity_test/src/mps.cpp b/deferred_planarity_test/src/mps.cpp index bdeba63..9df00be 100644 --- a/deferred_planarity_test/src/mps.cpp +++ b/deferred_planarity_test/src/mps.cpp @@ -11,8 +11,8 @@ maximal_planar_subgraph_finder::maximal_planar_subgraph_finder() {} //Destructor maximal_planar_subgraph_finder::~maximal_planar_subgraph_finder() { - for (int i = 0; i < _node_list.size(); ++i) delete _node_list[i]; - for (int i = 0; i < _new_node_list.size(); ++i) delete _new_node_list[i]; + for (size_t i = 0; i < _node_list.size(); ++i) delete _node_list[i]; + for (size_t i = 0; i < _new_node_list.size(); ++i) delete _new_node_list[i]; } node* @@ -24,7 +24,7 @@ maximal_planar_subgraph_finder::get_new_node(node_type t) { vector maximal_planar_subgraph_finder::return_post_order() { vector post_order; - for (int i = 0; i < _post_order_list.size(); ++i) { + for (size_t i = 0; i < _post_order_list.size(); ++i) { post_order.push_back(_post_order_list[i]->node_id()); } return post_order; @@ -36,7 +36,7 @@ maximal_planar_subgraph_finder::postOrderTraversal() { node::init_mark(); // always start with node 0 int postOrderID = 0; - for (int i = 0; i < _node_list.size(); ++i) { + for (size_t i = 0; i < _node_list.size(); ++i) { if (!_node_list[i]->is_marked()) { _node_list[i]->DFS_visit(_post_order_list, postOrderID); } @@ -62,7 +62,7 @@ maximal_planar_subgraph_finder::guidedPostOrderTraversal(vector post_order) unordered_map node_id_to_pos; int j = 0; // we flip the post_order vector around - for (int i = post_order.size() - 1; i >= 0; --i) { + for (size_t i = post_order.size() - 1; i >= 0; --i) { node_id_to_pos[post_order[i]] = j++; } int postOrderID = 0; @@ -97,14 +97,14 @@ maximal_planar_subgraph_finder::mutatedPostOrderTraversal(vector post_order node::init_mark(); vector rev_post_order; - for (int i = post_order.size() - 1; i >= 0; --i) { + for (size_t i = post_order.size() - 1; i >= 0; --i) { rev_post_order.push_back(post_order[i]); } int postOrderID = 0; int traversal_index = 0; - // Define the range [0, n] - int n = _node_list.size() - 1; // Change 'n' to your desired upper bound + // Define the range [0, n] + // int n = _node_list.size() - 1; // Change 'n' to your desired upper bound // set loop variables int start = rev_post_order[0]; @@ -135,7 +135,7 @@ maximal_planar_subgraph_finder::mutatedPostOrderTraversal(vector post_order void maximal_planar_subgraph_finder::print_post_order() { int current_index; - for (int i = 0; i < _post_order_list.size(); ++i) { + for (size_t i = 0; i < _post_order_list.size(); ++i) { current_index = _post_order_list[i]->node_id(); std::cout << current_index << ","; } @@ -157,12 +157,12 @@ void maximal_planar_subgraph_finder::sort_adj_list() { vector > vecList; vecList.resize(_post_order_list.size()); - for (int i = 0; i < _post_order_list.size(); ++i) { + for (size_t i = 0; i < _post_order_list.size(); ++i) { for (int j = 0; j < _post_order_list[i]->degree(); ++j) { vecList[_post_order_list[i]->adj(j)->post_order_index()].push_back(_post_order_list[i]); } } - for (int i = 0; i < _post_order_list.size(); ++i) { + for (size_t i = 0; i < _post_order_list.size(); ++i) { _post_order_list[i]->set_adj_list(vecList[i]); } } @@ -171,20 +171,20 @@ maximal_planar_subgraph_finder::sort_adj_list() { //Order the edges properly. void maximal_planar_subgraph_finder::determine_edges() { - for (int i = 0; i < _post_order_list.size(); ++i) { + for (size_t i = 0; i < _post_order_list.size(); ++i) { if (_post_order_list[i]->parent() == 0) continue; _post_order_list[i]->set_1st_label(_post_order_list[i]->parent()->post_order_index()); _edge_list.push_back(pair (_post_order_list[i]->parent(), _post_order_list[i])); } - for (int i = 0; i < _post_order_list.size(); ++i) { + for (size_t i = 0; i < _post_order_list.size(); ++i) { for (int j = 0; j < _post_order_list[i]->degree(); ++j) { - if (_post_order_list[i]->adj(j)->post_order_index() > i) break; - if (_post_order_list[i]->adj(j)->get_1st_label() == i) continue; + if (_post_order_list[i]->adj(j)->post_order_index() > static_cast(i)) break; + if (_post_order_list[i]->adj(j)->get_1st_label() == static_cast(i)) continue; _back_edge_list.push_back(pair (_post_order_list[i], _post_order_list[i]->adj(j))); _is_back_edge_eliminate.push_back(false); } } - for (int i = 0; i < _post_order_list.size(); ++i) { + for (size_t i = 0; i < _post_order_list.size(); ++i) { _post_order_list[i]->set_1st_label(INT_MAX); } } @@ -194,7 +194,7 @@ void maximal_planar_subgraph_finder::back_edge_traversal() { node* i_node = 0; node* current_node = 0; - for (int i = 0; i < _back_edge_list.size(); ++i) { + for (size_t i = 0; i < _back_edge_list.size(); ++i) { current_node = _back_edge_list[i].second; i_node = _back_edge_list[i].first; if (!back_edge_traversal(current_node, i_node->post_order_index())) _is_back_edge_eliminate[i] = true; @@ -471,7 +471,7 @@ maximal_planar_subgraph_finder::trim(node* u) { new_AE_root = get_new_node(AE_VIRTUAL_ROOT); new_AE_root->init_AE(node_list[0]); //Eliminate the children other than the path. - for (int i = 1; i < node_list.size(); ++i) { + for (size_t i = 1; i < node_list.size(); ++i) { for (int j = 0; j < node_list[i]->child_num(); ++j) { if (node_list[i]->child(j) != node_list[i-1]) eliminate(node_list[i]->child(j)); } @@ -481,7 +481,7 @@ maximal_planar_subgraph_finder::trim(node* u) { else { node_list[0]->set_to_boundary_path(down, node_list[1]); node_list[node_list.size()-1]->set_to_boundary_path(up, node_list[node_list.size()-2]); - for (int i = 1; i < node_list.size()-1; ++i) { + for (size_t i = 1; i < node_list.size()-1; ++i) { node_list[i]->set_to_boundary_path(node_list[i-1], node_list[i+1]); } } @@ -489,7 +489,7 @@ maximal_planar_subgraph_finder::trim(node* u) { up_next = up->get_next(node_list[node_list.size()-1]); down_next = down->get_next(node_list[0]); //Unfold the c-nodes in the node_list. - for (int i = 0; i < node_list.size(); ++i) { + for (size_t i = 0; i < node_list.size(); ++i) { if (node_list[i]->type() == C_NODE) c_node_extension(node_list[i]); } //Return the new boundary. @@ -663,7 +663,7 @@ maximal_planar_subgraph_finder::parallel_search_sentinel(node* n0, node* n0_prev } //If the c-node found is top-tier, then assign all the traversed node a pointer to c-node. - for (int i = 0; i < traversed.size(); ++i) traversed[i]->set_c_node(c); + for (size_t i = 0; i < traversed.size(); ++i) traversed[i]->set_c_node(c); return pair((node*)0, (node*)0); } @@ -711,7 +711,7 @@ pair maximal_planar_subgraph_finder::count_sentinel_elimination(pa node* maximal_planar_subgraph_finder::construct(node* u) { //Basic works. - int i_label = u->get_1st_label(); + // int i_label = u->get_1st_label(); // unused node* node_i = _post_order_list[u->get_1st_label()]; parenting_labeling_shaving(u, node_i); @@ -759,7 +759,7 @@ maximal_planar_subgraph_finder::construct(node* u) { node* maximal_planar_subgraph_finder::construct(node* c, node* p) { //Basic works. - int i_label = c->get_1st_label(); + // int i_label = c->get_1st_label(); // unused var node* node_i = _post_order_list[c->get_1st_label()]; parenting_labeling_shaving(p, node_i); //note: Now, c must have exactly two children left, and c has a parent-link to p, p has achild link to c, too. @@ -830,11 +830,11 @@ maximal_planar_subgraph_finder::parenting_labeling_shaving(node* u, node* node_i u_i_path.push_back(u_i_path[u_i_path.size()-1]->parent()); if (u_i_path[u_i_path.size()-1] == node_i) break; } - for (int i = 0; i < u_i_path.size()-2; ++i) { + for (size_t i = 0; i < u_i_path.size()-2; ++i) { u_i_path[i]->add_child(u_i_path[i+1]); u_i_path[i+1]->set_parent(u_i_path[i]); } - for (int i = 0; i < u_i_path.size()-2; ++i) { + for (size_t i = 0; i < u_i_path.size()-2; ++i) { for (int j = 0; j < u_i_path[i+1]->child_num(); ++j) { if (u_i_path[i+1]->child(j) == u_i_path[i]) { u_i_path[i+1]->remove_child(j); diff --git a/deferred_planarity_test/src/mps_test.cpp b/deferred_planarity_test/src/mps_test.cpp index 29d1819..e3081c9 100644 --- a/deferred_planarity_test/src/mps_test.cpp +++ b/deferred_planarity_test/src/mps_test.cpp @@ -175,7 +175,7 @@ void maximal_planar_subgraph_finder::init_from_graph(const ogdf::Graph &G) { // count the number of removed edges int maximal_planar_subgraph_finder::output_removed_edge_size() { int sum = 0; - for (int i = 0; i < _back_edge_list.size(); ++i) { + for (size_t i = 0; i < _back_edge_list.size(); ++i) { if (_is_back_edge_eliminate[i]) ++sum; } return sum; diff --git a/deferred_planarity_test/src/node.cpp b/deferred_planarity_test/src/node.cpp index 965285b..1db37a1 100644 --- a/deferred_planarity_test/src/node.cpp +++ b/deferred_planarity_test/src/node.cpp @@ -37,7 +37,7 @@ void node::set_post_order_index(int i) {_post_order_index = i;} //Only used when consturcting c-node //The first node calling this function would not be labeled. void node::recursively_labeling() { - for (int i = 0; i < _children.size(); ++i) { + for (size_t i = 0; i < _children.size(); ++i) { _children[i]->_label.second = ARTIFICIAL_EDGE; _children[i]->recursively_labeling(); } @@ -58,7 +58,7 @@ void node::set_adj_list(vector vec) {_adj_list = vec;} void node::DFS_visit(vector &dfsList, int &index) { mark(); - for (int i = 0; i < _adj_list.size(); ++i) { + for (size_t i = 0; i < _adj_list.size(); ++i) { if (!_adj_list[i]->is_marked()) { _adj_list[i]->_parent = this; _adj_list[i]->DFS_visit(dfsList, index); @@ -128,7 +128,7 @@ void node::guided_DFS_visit(vector &dfsList, - for (int i = 0; i < neighbor_list.size(); ++i) { + for (size_t i = 0; i < neighbor_list.size(); ++i) { if (!neighbor_list[i]->is_marked()) { neighbor_list[i]->_parent = this; neighbor_list[i]->guided_DFS_visit(dfsList, node_list, return_index, node_id_to_pos); @@ -157,7 +157,7 @@ void node::mutated_DFS_visit(vector &dfsList, // create an unordered set to efficiently check for presence of an element std::unordered_set neighbor_set; - for (int i = 0; i < _adj_list.size(); ++i) { + for (size_t i = 0; i < _adj_list.size(); ++i) { neighbor_set.insert(_adj_list[i]->node_id()); } // when an element in rev_post_order is found in neighbor_set, we add that to neighbor_list @@ -165,7 +165,7 @@ void node::mutated_DFS_visit(vector &dfsList, // it is ok if the neighbor was already visited before, // it would've been marked and will be subsequently ignored vector neighbor_list; - for (int i = 0; i < rev_post_order.size(); ++i) { + for (size_t i = 0; i < rev_post_order.size(); ++i) { if (neighbor_set.find(rev_post_order[i]) != neighbor_set.end()) { neighbor_list.push_back(node_list[rev_post_order[i]]); } @@ -185,7 +185,7 @@ void node::mutated_DFS_visit(vector &dfsList, #ifdef DEBUG_MUTATION std::cout << "current node:" << this->node_id() << std::endl; - for (int i = 0; i < neighbor_list.size(); ++i) { + for (size_t i = 0; i < neighbor_list.size(); ++i) { std::cout << neighbor_list[i]->node_id() << "(" << neighbor_list[i]->is_marked() << ")" << ","; } std::cout << std::endl; @@ -196,7 +196,7 @@ void node::mutated_DFS_visit(vector &dfsList, // next node will receive incremented index traversal_index++; - for (int i = 0; i < neighbor_list.size(); ++i) + for (size_t i = 0; i < neighbor_list.size(); ++i) { if (!neighbor_list[i]->is_marked()) { @@ -229,7 +229,7 @@ void node::remove_child(int i) { } void node::remove_child(node* n) { - for (int i = 0; i < _children.size(); ++i) { + for (size_t i = 0; i < _children.size(); ++i) { if (_children[i] == n) { _children[i] = _children[_children.size()-1]; _children.resize(_children.size()-1); @@ -305,7 +305,7 @@ void node::init_AE(node* u) { if (u->child_num() == 0) return; _children = u->_children; u->clear_children(); - for (int i = 0; i < _children.size(); ++i) { + for (size_t i = 0; i < _children.size(); ++i) { _children[i]->set_parent(this); } set_parent(u);