diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 6d191c3..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "libs/boost/graph"] - path = libs/boost/graph - url = git@github.com:boostorg/graph.git -[submodule "boost"] - path = boost - url = https://github.com/boostorg/boost diff --git a/Makefile b/Makefile deleted file mode 100755 index 5bbf35c..0000000 --- a/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -CC=g++ -CC64=CC -CFLAGS=-O2 -march=native -std=c++0x -D_hypot=hypot -OMPFLAGS=-fopenmp -C64FLAGS=$(CFLAGS) -BOOST_GRAPH=-Ilibs/boost/graph/include -BOOST_ANY=-L/lib/libboost* -DEBUGFLAGS=-g -O0 -std=c++0x -PROFILEFLAGS=-pg -OBJS=uspr uspr_neighbors - -.PHONY: debug -.PHONY: profile -.PHONY: test -.PHONY: test_trees/%.test -.PHONY: clean -.PHONY: all -.PHONY: default - -all: $(OBJS) - -all-tests := $(addsuffix .test_out, $(basename $(wildcard test_trees/*.test))) - -boost-any := $(addprefix -I, $(basename $(wildcard boost/libs/*/include/))) - -LFLAGS=$(boost-any) - -uspr: uspr.cpp *.h - $(CC) $(LFLAGS) $(CFLAGS) -o uspr uspr.cpp - -uspr_neighbors: uspr_neighbors.cpp *.h - $(CC) $(LFLAGS) $(CFLAGS) -o uspr_neighbors uspr_neighbors.cpp - -debug: - $(CC) $(LFLAGS) $(DEBUGFLAGS) -o uspr uspr.cpp -profile: - $(CC) $(LFLAGS) $(DEBUGFLAGS) $(PROFILEFLAGS) -o uspr uspr.cpp -test: $(all-tests) - @echo "Success, all tests passed." - -test_trees/%.test_out : test_trees/%.tre test_trees/%.test uspr - @./uspr <$< 2>&1 > $@ && diff -1 $(addsuffix .test, $(basename $<)) $@ || \ - (echo "Test $@ failed" && exit 1) - @echo "Test $@ passed" - -clean: - @rm $(OBJS) test_trees/*.test_out 2> /dev/null || echo > /dev/null diff --git a/boost b/boost deleted file mode 160000 index a89d865..0000000 --- a/boost +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a89d865a504c59a0fea96ffbb22bd983da470104 diff --git a/tbr.h b/tbr.h index b730e51..178398a 100644 --- a/tbr.h +++ b/tbr.h @@ -56,35 +56,35 @@ typedef boost::adjacency_list (); for (socket *s : socketlist) { dead_map[s->dead] = s; - map, vector >::iterator i = + map, vector >::iterator i = sockets.find(make_pair(s->i, s->j)); if (i == sockets.end()) { - + auto new_i = sockets.insert(make_pair(make_pair(s->i, s->j), vector())); i = new_i.first; } - if (i->second.size() < s->num) { + if ((int) i->second.size() < s->num) { i->second.resize(s->num); } (i->second)[s->num - 1] = s; @@ -215,7 +215,7 @@ class socketcontainer { } return socket_list; } - + }; @@ -249,7 +249,7 @@ void find_dead_components(uforest &T, socketcontainer &S, map & void find_dead_components_hlpr(unode *n, unode *prev, int component, uforest &T, socketcontainer &S, map &T_status, vector > &T_dead_components); void update_nodemapping(nodemapping &twins, uforest &F, int original_label, int new_label, bool forward); int check_socket_group_combination(int k, int kprime, socketcontainer &T1_sockets, socketcontainer &T2_sockets_normalized, vector > &T1_dead_components, vector > &T2_dead_components, vector , vector > > &socketcandidates, vector > &sockets, vector > &candidate_phi_node_sockets); -int check_socket_group_combinations(int n, int i, int j, int last, int k, int kprime, socketcontainer &T1_sockets, socketcontainer &T2_sockets_normalized, vector > &T1_dead_components, vector > &T2_dead_components, vector , vector > > &socketcandidates, vector > &sockets, vector > &phi_node_sockets); +int check_socket_group_combinations(unsigned int n, unsigned int i, unsigned int j, int last, int k, int kprime, socketcontainer &T1_sockets, socketcontainer &T2_sockets_normalized, vector > &T1_dead_components, vector > &T2_dead_components, vector , vector > > &socketcandidates, vector > &sockets, vector > &phi_node_sockets); int check_socket_group_combinations(int k, int kprime, socketcontainer &T1_sockets, socketcontainer &T2_sockets_normalized, vector > &T1_dead_components, vector > &T2_dead_components, vector , vector > > &socketcandidates, vector > &phi_node_sockets); bool get_constraint(list &dead_component, socketcontainer &T_sockets, map &socket_pointer_map, vector &constraint); int solve_monotonic_2sat_2vars(vector > &constraints, vector &preferred_sockets, list &changed_sockets); @@ -414,7 +414,10 @@ int replug_distance(uforest &T1, uforest &T2, bool quiet /* = true */, uforest * } template -int tbr_distance_hlpr(uforest &T1, uforest &T2, int k, T t, int (*func_pointer)(uforest &F1, uforest &F2, nodemapping &twins, int k, T s), uforest **MAF1 /* = NULL */, uforest **MAF2 /* = NULL */) { +int tbr_distance_hlpr(uforest &T1, uforest &T2, int k, T t, + int (*func_pointer)(uforest &F1, uforest &F2, + nodemapping &twins, int k, T s), + uforest **MAF1 /* = NULL */, uforest **MAF2 /* = NULL */) { uforest F1 = uforest(T1); uforest F2 = uforest(T2); @@ -459,18 +462,23 @@ int tbr_distance_hlpr(uforest &T1, uforest &T2, int k, T t, int (*func_pointer)( } ) - - return tbr_distance_hlpr(F1, F2, k, twins, sibling_pairs, singletons, t, func_pointer, MAF1, MAF2); + return tbr_distance_hlpr(F1, F2, k, twins, sibling_pairs, singletons, t, + func_pointer, MAF1, MAF2); } template -int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map &sibling_pairs, list &singletons, T t, int (*func_pointer)(uforest &F1, uforest &F2, nodemapping &twins, int k, T s), uforest **MAF1 /* = NULL*/, uforest **MAF2 /* = NULL*/) { +int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, + map &sibling_pairs, list &singletons, T t, + int (*func_pointer)(uforest &F1, uforest &F2, nodemapping &twins, + int k, T s), uforest **MAF1 /* = NULL*/, + uforest **MAF2 /* = NULL*/) { if (k < 0) { return -1; } debug(cout << "tbr_distance_hlpr(" << k << ")" << endl); + Rcpp::checkUserInterrupt(); // if (sib pair list is not empty, k>=0) { while (!sibling_pairs.empty() || !singletons.empty()) { @@ -486,7 +494,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map p: sibling_pairs) { cout << p.first << ", " << p.second << endl; } @@ -597,7 +605,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, mapget_parent() == F2_c->get_parent() || @@ -643,7 +651,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, mapget_label(), F2_new_terminal->get_label()); // check for singleton - if (F2_new_terminal->is_singleton()) { //get_parent()->get_distance() > F2_new_terminal->get_distance()) + if (F2_new_terminal->is_singleton()) { //get_parent()->get_distance() > F2_new_terminal->get_distance()) singletons.push_back(F2_new_terminal->get_label()); } @@ -703,7 +711,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map > pendants = find_pendants(F2_a, F2_c); int num_pendants = pendants.size(); debug( cout << "path:" << endl; list path = list(); get_path(F2_a, F2_c, path); - + for (unode *x : path) { cout << "\t" << F2.str_subtree(x) << endl; } @@ -761,9 +769,9 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map e_a = make_pair(F2_a->get_label(), F2_a->get_parent()->get_label()); - + debug(cout << "cut e_a" << endl); - + // copy the trees uforest F1_copy = uforest(F1); uforest F2_copy = uforest(F2); @@ -772,7 +780,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map sibling_pairs_copy = map(sibling_pairs); list singletons_copy = list(singletons); - + debug(cout << F2_copy << endl); int first_label = e_a.first; int second_label = e_a.second; @@ -798,7 +806,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map result) { if (MAF1 != NULL && MAF2 != NULL) { @@ -827,9 +835,9 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map e_c = make_pair(F2_c->get_label(), F2_c->get_parent()->get_label()); - + debug(cout << "cut e_c: " << F2.str_subtree(F2_c) << endl); - + // copy the trees uforest F1_copy = uforest(F1); uforest F2_copy = uforest(F2); @@ -838,7 +846,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map sibling_pairs_copy = map(sibling_pairs); list singletons_copy = list(singletons); - + debug(cout << F2_copy << endl); int first_label = e_c.first; int second_label = e_c.second; @@ -856,7 +864,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map result) { if (MAF1 != NULL && MAF2 != NULL) { @@ -977,9 +985,9 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map e_b = pendants.front(); - + debug(cout << "cut e_b" << endl); - + // copy the trees uforest F1_copy = uforest(F1); uforest F2_copy = uforest(F2); @@ -990,7 +998,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, mapget_label(), F1_c->get_label())); sibling_pairs_copy.insert(make_pair(F1_c->get_label(), F1_a->get_label())); list singletons_copy = list(singletons); - + debug(cout << F2_copy << endl); int first_label = e_b.first; int second_label = e_b.second; @@ -1005,7 +1013,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map result) { if (MAF1 != NULL && MAF2 != NULL) { @@ -1033,9 +1041,9 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map e_d = pendants.back(); - + debug(cout << "cut e_d" << endl); - + // copy the trees uforest F1_copy = uforest(F1); uforest F2_copy = uforest(F2); @@ -1046,7 +1054,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, mapget_label(), F1_c->get_label())); sibling_pairs_copy.insert(make_pair(F1_c->get_label(), F1_a->get_label())); list singletons_copy = list(singletons); - + debug(cout << F2_copy << endl); int first_label = e_d.first; int second_label = e_d.second; @@ -1062,7 +1070,7 @@ int tbr_distance_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map result) { if (MAF1 != NULL && MAF2 != NULL) { @@ -1234,6 +1242,7 @@ int tbr_approx(uforest &T1, uforest &T2, bool low) { int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map &sibling_pairs, list &singletons) { debug_approx(cout << "tbr_approx_hlpr(" << k << ")" << endl); + Rcpp::checkUserInterrupt(); while (!sibling_pairs.empty() || !singletons.empty()) { @@ -1248,7 +1257,7 @@ int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map p: sibling_pairs) { cout << p.first << ", " << p.second << endl; } @@ -1361,7 +1370,7 @@ int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, mapget_parent() == F2_c->get_parent() || @@ -1403,7 +1412,7 @@ int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, mapget_label(), F2_new_terminal->get_label()); // check for singleton - if (F2_new_terminal->is_singleton()) { //get_parent()->get_distance() > F2_new_terminal->get_distance()) + if (F2_new_terminal->is_singleton()) { //get_parent()->get_distance() > F2_new_terminal->get_distance()) singletons.push_back(F2_new_terminal->get_label()); } @@ -1462,7 +1471,7 @@ int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, mapget_parent()->get_neighbor_not(F2_a, F2_b1); unode *F2_d1 = F2_c->get_parent()->get_neighbor_not(F2_c); unode *F2_d2 = F2_c->get_parent()->get_neighbor_not(F2_c, F2_d1); - + bool cut_a = true; bool cut_b = true; bool cut_c = true; @@ -1493,9 +1502,9 @@ int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map e_a = make_pair(F2_a->get_label(), F2_a->get_parent()->get_label()); - + debug_approx(cout << "cut e_a" << endl); - + debug_approx(cout << F2 << endl;) int first_label = e_a.first; int second_label = e_a.second; @@ -1520,15 +1529,15 @@ int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map e_c = make_pair(F2_c->get_label(), F2_c->get_parent()->get_label()); - + debug_approx(cout << "cut e_c" << endl); - + debug_approx(cout << F2 << endl;) int first_label = e_c.first; int second_label = e_c.second; @@ -1553,7 +1562,7 @@ int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, mapget_parent(); } pair e_b = make_pair(F2_b1->get_label(), F2_b2->get_label()); - + debug_approx(cout << "cut e_b" << endl); - + debug_approx(cout << F2 << endl;) int first_label = e_b.first; int second_label = e_b.second; @@ -1602,9 +1611,9 @@ int tbr_approx_hlpr(uforest &F1, uforest &F2, int k, nodemapping &twins, map e_d = make_pair(F2_d1->get_label(), F2_d2->get_label()); - + debug_approx(cout << "cut e_d" << endl); - + debug_approx(cout << F2 << endl;) int first_label = e_d.first; int second_label = e_d.second; @@ -1674,9 +1683,9 @@ list > find_pendants(unode *a, unode *c) { } int print_mAFs(uforest &F1, uforest &F2, nodemapping &twins, int k, int dummy) { - cout << "ANSWER FOUND" << endl; - cout << "\t" << F1.str() << endl; - cout << "\t" << F2.str() << endl; + /*Rcout << "ANSWER FOUND" << endl;*/ + Rcout << F1.str() << endl; + Rcout << F2.str() << endl; return k; } @@ -1686,9 +1695,9 @@ int count_mAFs(uforest &F1, uforest &F2, nodemapping &twins, int k, int *count) } int print_and_count_mAFs(uforest &F1, uforest &F2, nodemapping &twins, int k, int *count) { - cout << "ANSWER FOUND" << endl; - cout << "\t" << F1.str() << endl; - cout << "\t" << F2.str() << endl; + /*Rcout << "ANSWER FOUND" << endl;*/ + Rcout << F1.str() << endl; + Rcout << F2.str() << endl; (*count)++; return k; } @@ -1873,7 +1882,7 @@ int replug_hlpr(uforest &F1, uforest &F2, nodemapping &twins, int k, pair &l : T2_dead_components) { @@ -2014,14 +2023,13 @@ int check_socket_group_combinations(int k, int kprime, socketcontainer &T1_socke } // enumerate each combination of socket pairings recursively -int check_socket_group_combinations(int n, int i, int j, int last, int k, int kprime, socketcontainer &T1_sockets, socketcontainer &T2_sockets_normalized, vector > &T1_dead_components, vector > &T2_dead_components, vector , vector > > &socketcandidates, vector > &sockets, vector > &phi_node_sockets) { -/* cout << "combinations("; - cout << n << ", "; - cout << i << ", "; - cout << j << ", "; - cout << last << ")"; - cout << endl; - */ +int check_socket_group_combinations(unsigned int n, unsigned int i, unsigned int j, + int last, int k, int kprime, + socketcontainer &T1_sockets, + socketcontainer &T2_sockets_normalized, + vector > &T1_dead_components, + vector > &T2_dead_components, + vector , vector > > &socketcandidates, vector > &sockets, vector > &phi_node_sockets) { // test this combination if (n >= socketcandidates.size()) { return check_socket_group_combination(k, kprime, T1_sockets, T2_sockets_normalized, T1_dead_components, T2_dead_components, socketcandidates, sockets, phi_node_sockets); @@ -2035,7 +2043,7 @@ int check_socket_group_combinations(int n, int i, int j, int last, int k, int kp } else { n++; - return check_socket_group_combinations(n, 0, 0, 0, k, kprime, T1_sockets, T2_sockets_normalized, T1_dead_components, T2_dead_components, socketcandidates, sockets, phi_node_sockets); + return check_socket_group_combinations(n, 0U, 0U, 0, k, kprime, T1_sockets, T2_sockets_normalized, T1_dead_components, T2_dead_components, socketcandidates, sockets, phi_node_sockets); } } @@ -2088,7 +2096,7 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket // map of socket pointers to paired socket numbers map socket_pointer_map = map(); int i = 0; - for(int i = 0; i < sockets.size(); i++) { + for(unsigned int i = 0; i < sockets.size(); i++) { socket_pointer_map[sockets[i].first] = i; socket_pointer_map[sockets[i].second] = i; } @@ -2125,7 +2133,7 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket // list of preferred sockets for building out an edge cover // these are sockets not adjacent to a large dead component in either tree vector preferred_sockets = vector(sockets.size(), true); - for(int i = 0; i < sockets.size(); i++) { + for(unsigned int i = 0; i < sockets.size(); i++) { if (T1_socket_dead_component_map.find(sockets[i].first->dead) != T1_socket_dead_component_map.end()) { preferred_sockets[i] = false; } @@ -2165,7 +2173,7 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket i++; } debug_phi_nodes( - cout << "found " << constraints.size() << " constraints" << endl; + cout << "found " << constraints.size() << " constraints" << endl; ) @@ -2185,7 +2193,7 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket debug_phi_nodes( cout << "phi-node sockets:" << endl; ) - for (int i = 0; i < sockets.size(); i++) { + for (unsigned int i = 0; i < sockets.size(); i++) { if (!changed_sockets_vector[i]) { candidate_phi_node_sockets.push_back(sockets[i]); debug_phi_nodes(cout << sockets[i].first->str() << "\t" << sockets[i].second->str() << endl;) @@ -2230,7 +2238,7 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket cout << endl; ) // number of phi nodes in dead component - int T2_dead_comp_phi_nodes = 0; + int T2_dead_comp_phi_nodes = 0; for (int x : T2_dead_components[dead_component]) { if (socket_pointer_map.find(T2_sockets_normalized.find_dead(x)) != socket_pointer_map.end()) { int x_socket = socket_pointer_map[T2_sockets_normalized.find_dead(x)]; @@ -2240,13 +2248,13 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket } } int max_extra_phi_nodes = T2_dead_components[dead_component].size() - 1 - T2_dead_comp_phi_nodes; - int allocated_extra_phi_nodes = 0; + int remaining_extra_phi_nodes = max_extra_phi_nodes; debug_phi_nodes( if (p.second.size() > 1) { cout << "conflict: " << endl; for (int s : p.second) { - cout << "," << s; + cout << "," << s; } cout << endl; } @@ -2259,7 +2267,7 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket int socket = socket_pointer_map[T2_sockets_normalized.find_dead(s)]; int T1_dead_component = T1_socket_dead_component_map[sockets[socket].first->dead]; // determine its phi node count - int T1_dead_comp_phi_nodes = 0; + int T1_dead_comp_phi_nodes = 0; for (int x : T1_dead_components[T1_dead_component]) { if (socket_pointer_map.find(T1_sockets.find_dead(x)) != socket_pointer_map.end()) { int x_socket = socket_pointer_map[T1_sockets.find_dead(x)]; @@ -2315,7 +2323,7 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket cout << "replug_distance: " << (2 * kprime) - phi_nodes << endl; ) - + // return the remaining number of moves (phi-nodes returned in candidate_phi_node_sockets) @@ -2325,13 +2333,15 @@ int check_socket_group_combination(int k, int kprime, socketcontainer &T1_socket // determine the minimum number of variables that must be false to satisfy a monotonic 2 SAT set of CNF constraints where each variable occurs at most twice // works by converting to a maximum edge cover problem where each vertex is a clause and each edge is a variable spanning two clauses -int solve_monotonic_2sat_2vars(vector > &constraints, vector &preferred_sockets, list &changed_sockets) { +int solve_monotonic_2sat_2vars(vector > &constraints, + vector &preferred_sockets, + list &changed_sockets) { debug_phi_nodes(cout << "solve_monotonic_2sat_2vars()" << endl;) // inverse map sockets to constraints map > constraint_map = map >(); - for(int i = 0; i < constraints.size(); i++) { + for(unsigned int i = 0; i < constraints.size(); i++) { for(int socket : constraints[i]) { constraint_map[socket].push_back(i); } @@ -2339,9 +2349,9 @@ int solve_monotonic_2sat_2vars(vector > &constraints, vector & // build the constraint graph undirected_graph G(constraints.size()); - for(int i = 0; i < constraints.size(); i++) { + for(unsigned int i = 0; i < constraints.size(); i++) { for(int socket : constraints[i]) { - for (int constraint : constraint_map[socket]) { + for (unsigned int constraint : constraint_map[socket]) { if (constraint != i) { // for constraints containing this socket if (i < constraint) { @@ -2367,11 +2377,13 @@ int solve_monotonic_2sat_2vars(vector > &constraints, vector & // find a maximum matching - + // matching data structure vector::vertex_descriptor> mate(constraints.size()); bool success = boost::checked_edmonds_maximum_cardinality_matching(G, &mate[0]); - assert(success); + if (!success) { + throw(runtime_error("Maximum cardinality matching failed")); + } int matching_size = boost::matching_size(G, &mate[0]); debug_phi_nodes(cout << "found a matching of size " << matching_size << endl;) @@ -2400,7 +2412,7 @@ int solve_monotonic_2sat_2vars(vector > &constraints, vector & if (done) { break; } - for(int constraint : constraint_map[socket]) { + for(unsigned int constraint : constraint_map[socket]) { if (constraint == mate[*vi]) { debug_phi_nodes(cout << "both contain " << socket << endl;) changed_sockets.push_back(socket); @@ -2414,8 +2426,8 @@ int solve_monotonic_2sat_2vars(vector > &constraints, vector & else if (!handled_constraints[*vi]) { // vertex is not matched, pick an arbitrary socket // avoid sockets that are not adjacent to dead components - int c = 0; - for(c = 0; c < constraints[*vi].size(); c++) { + unsigned int c = 0U; + for(c = 0U; c < constraints[*vi].size(); c++) { if (!preferred_sockets[constraints[*vi][c]]) { break; } @@ -2476,7 +2488,7 @@ bool get_constraint(list &dead_component, socketcontainer &T_sockets, mapj != prev_socket->j) { // cout << "found" << endl; - + component = T_dead_components.size(); T_dead_components.push_back(list()); T_dead_components[component].push_back(prev_label); @@ -2933,7 +2945,7 @@ void leaf_reduction_hlpr(utree &T1, utree &T2, nodemapping &twins, map sibling_pairs.insert(make_pair(new_sibling_pair[i-2], new_sibling_pair[i-1])); } } - + // make terminal in T2 // contract T2_a and T2_c debug( diff --git a/uforest.h b/uforest.h index a29589d..af64f38 100644 --- a/uforest.h +++ b/uforest.h @@ -73,7 +73,7 @@ class uforest: public utree { string str(bool print_internal = false, map *reverse_label_map = NULL) const { stringstream ss; - for(int i = 0; i < components.size(); i++) { + for(int i = 0; i < (int) components.size(); i++) { if (i > 0) { ss << " "; } @@ -96,7 +96,7 @@ class uforest: public utree { } string str_with_depths(bool print_internal = false) const { stringstream ss; - for(int i = 0; i < components.size(); i++) { + for(unsigned int i = 0; i < components.size(); i++) { if (i > 0) { ss << " "; } @@ -195,7 +195,7 @@ class uforest: public utree { } } void contract_degree_two() { - for(int i = 0; i < components.size(); i++) { + for(unsigned int i = 0; i < components.size(); i++) { unode *c = components[i]; unode *result = c->contract_degree_two_subtree(); if (result != c) { diff --git a/uspr.h b/uspr.h index e5cd7be..ae18c3d 100644 --- a/uspr.h +++ b/uspr.h @@ -50,7 +50,7 @@ along with uspr. If not, see . #ifdef DEBUG_USPR #define debug_uspr(x) x #else - #define debug_uspr(x) + #define debug_uspr(x) #endif // options @@ -100,7 +100,7 @@ bool operator < (tree_distance a, tree_distance b) { return a.estimate < b.estimate; } } - return a.distance < b.distance; } + return a.distance < b.distance; } bool operator <= (tree_distance a, tree_distance b) { if (a.distance == b.distance) { if (a.estimate == b.estimate) { @@ -237,7 +237,9 @@ int uspr_distance(uforest &T1_original, uforest &T2_original) { // cout << "target: " << target << endl; if (tree_string == target) { // cout << "returning " << cost+1 << endl; - cout << "examined " << visited_trees.size() << " trees" << endl; + debug_uspr( + cout << "examined " << visited_trees.size() << " trees" << endl; + ) return cost+1; } // else { diff --git a/utree.h b/utree.h index 0f12d01..88eba77 100644 --- a/utree.h +++ b/utree.h @@ -41,7 +41,7 @@ bool KEEP_LABELS = false; // prototypes bool build_utree(utree &t, string &s, map *label_map = NULL, map *reverse_label_map = NULL); -int build_utree_helper(utree &t, string &s, int start, unode *parent, bool &valid, map *label_map = NULL, map *reverse_label_map = NULL); +unsigned int build_utree_helper(utree &t, string &s, int start, unode *parent, bool &valid, map *label_map = NULL, map *reverse_label_map = NULL); void find_sibling_pairs_hlpr(utree &t, map &sibling_pairs); map distances_from_leaf(utree &T1, int leaf); void distances_from_leaf_hlpr(utree &T1, map &distances, unode *prev, unode *current, int distance); @@ -135,12 +135,12 @@ class utree { return label; } - int add_leaf(int label) { - int start = leaves.size(); + unsigned int add_leaf(unsigned int label) { + unsigned int start = leaves.size(); if (leaves.size() <= label) { - leaves.resize(label+1); + leaves.resize(label + 1); } - for(int i = start; i < label; i++) { + for(unsigned int i = start; i < label; i++) { leaves[i] = NULL; } leaves[label] = new unode(label); @@ -283,7 +283,6 @@ class utree { s << n->str(reverse_label_map); } list::const_iterator i; - const list &cn = n->const_neighbors(); int count = 0; bool has_contracted = false; for(unode *i : n->const_neighbors()) { @@ -325,7 +324,7 @@ class utree { s << n->str(reverse_label_map); } list::const_iterator i; - const list &cn = n->const_neighbors(); + int count = 0; bool has_contracted = false; for(unode *i : n->const_neighbors()) { @@ -367,7 +366,7 @@ class utree { s << n->str(); } list::const_iterator i; - const list &cn = n->const_neighbors(); + int count = 0; bool has_contracted = false; for(unode *i : n->const_neighbors()) { @@ -463,7 +462,7 @@ class utree { return true; } - + }; ostream& operator<<(ostream &os, const utree& t) { @@ -491,9 +490,9 @@ bool build_utree(utree &t, string &s, map *label_map, map *label_map, map *reverse_label_map) { +unsigned int build_utree_helper(utree &t, string &s, int start, unode *parent, bool &valid, map *label_map, map *reverse_label_map) { // next special char - int loc = s.find_first_of("(,)", start); + unsigned int loc = s.find_first_of("(,)", start); if (loc == string::npos) { return loc; } @@ -551,7 +550,6 @@ int build_utree_helper(utree &t, string &s, int start, unode *parent, bool &vali void find_sibling_pairs_hlpr(utree &t, map &sibling_pairs) { - int i = 3; for(int l : t.find_leaves()) { unode *n = t.get_leaf(l); unode *p = n->get_neighbors().front();