This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interface with TdLib, a library concerning treedecompositions
- Loading branch information
Lukas Larisch
committed
Sep 19, 2015
1 parent
aeeddeb
commit 6a6b47b
Showing
11 changed files
with
1,325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
tarball=tdlib-VERSION.tar.bz2 | ||
sha1=5b0bcb44be41d367eb8162faf5d20f50e9bf68ee | ||
md5=6467fbf8a3e3f20f3cadf9a67680bf8d | ||
cksum=76656347 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,375 @@ | ||
diff -rupN tdlib-1.0/Makefile tdlib-1.0_/Makefile | ||
--- tdlib-1.0/Makefile 1970-01-01 01:00:00.000000000 +0100 | ||
+++ tdlib-1.0_/Makefile 2015-09-19 19:28:00.726714936 +0200 | ||
@@ -0,0 +1,13 @@ | ||
+CC=g++ | ||
+#CFLAGS=-Wall -fPIC -O3 -fomit-frame-pointer -funroll-loops | ||
+#CPPFLAGS="$CPPFLAGS -I$SAGE_LOCAL/include" | ||
+#LDFLAGS="$LDFLAGS -L$SAGE_LOCAL/lib" | ||
+SAGESOFLAGS=-shared -Wl,-soname,libtd.so | ||
+ | ||
+all: library | ||
+ | ||
+library: sage_tdlib.cpp | ||
+ $(CC) $(LDFLAGS) $(SAGEOFLAGS) -fPIC -o libtd.so sage_tdlib.cpp -c | ||
+ | ||
+clean: | ||
+ -@rm -rf *.o *.so 2>/dev/null || true | ||
diff -rupN tdlib-1.0/sage_tdlib.cpp tdlib-1.0_/sage_tdlib.cpp | ||
--- tdlib-1.0/sage_tdlib.cpp 1970-01-01 01:00:00.000000000 +0100 | ||
+++ tdlib-1.0_/sage_tdlib.cpp 2015-09-19 19:26:18.158712871 +0200 | ||
@@ -0,0 +1,305 @@ | ||
+#include <boost/tuple/tuple.hpp> | ||
+#include <map> | ||
+ | ||
+#include <boost/graph/adjacency_list.hpp> | ||
+#include "TD_combinations.hpp" | ||
+#include "TD_lower_bounds.hpp" | ||
+#include "TD_greedyCR.hpp" | ||
+#include "TD_dynamicCR.hpp" | ||
+#include "TD_seperator_algorithm.hpp" | ||
+#include "TD_elimination_orderings.hpp" | ||
+#include "TD_postprocessing.hpp" | ||
+#include "TD_misc.hpp" | ||
+ | ||
+ | ||
+#ifndef TD_STRUCT_VERTEX | ||
+#define TD_STRUCT_VERTEX | ||
+ | ||
+struct Vertex{ | ||
+ unsigned int id; | ||
+}; | ||
+ | ||
+#endif | ||
+ | ||
+typedef boost::adjacency_list<boost::setS, boost::listS, boost::undirectedS, Vertex> TD_graph_t; | ||
+ | ||
+struct bag{ | ||
+ std::set<unsigned int> bag; | ||
+}; | ||
+ | ||
+typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, bag> TD_tree_dec_t; | ||
+ | ||
+#include "sage_tdlib.hpp" | ||
+ | ||
+ | ||
+void make_tdlib_graph(TD_graph_t &G, std::vector<unsigned int> &V, std::vector<unsigned int> &E){ | ||
+ unsigned int max = 0; | ||
+ for(unsigned int i = 0; i < V.size(); i++) | ||
+ max = (V[i]>max)? V[i] : max; | ||
+ | ||
+ std::vector<TD_graph_t::vertex_descriptor> idxMap(max+1); | ||
+ | ||
+ for(unsigned int i = 0; i < V.size(); i++){ | ||
+ idxMap[V[i]] = boost::add_vertex(G); | ||
+ G[idxMap[V[i]]].id = V[i]; | ||
+ } | ||
+ | ||
+ if(E.size() != 0){ | ||
+ for(unsigned int j = 0; j < E.size()-1; j++){ | ||
+ boost::add_edge(idxMap[E[j]], idxMap[E[j+1]], G); | ||
+ j++; | ||
+ } | ||
+ } | ||
+} | ||
+ | ||
+void make_tdlib_decomp(TD_tree_dec_t &T, std::vector<std::vector<int> > &V, std::vector<unsigned int> &E){ | ||
+ std::vector<TD_tree_dec_t::vertex_descriptor> idxMap(V.size()+1); | ||
+ | ||
+ for(unsigned int i = 0; i < V.size(); i++){ | ||
+ idxMap[i] = boost::add_vertex(T); | ||
+ std::set<unsigned int> bag; | ||
+ for(unsigned int j = 0; j < V[i].size(); j++) | ||
+ bag.insert((unsigned int) V[i][j]); | ||
+ T[idxMap[i]].bag = bag; | ||
+ } | ||
+ | ||
+ if(E.size() != 0){ | ||
+ for(unsigned int j = 0; j < E.size()-1; j++){ | ||
+ boost::add_edge(idxMap[E[j]], idxMap[E[j+1]], T); | ||
+ j++; | ||
+ } | ||
+ } | ||
+ | ||
+} | ||
+ | ||
+void make_sage_graph(TD_graph_t &G, std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G){ | ||
+ boost::graph_traits<TD_graph_t>::vertex_iterator vIt, vEnd; | ||
+ for(boost::tie(vIt, vEnd) = boost::vertices(G); vIt != vEnd; vIt++) | ||
+ V_G.push_back(G[*vIt].id); | ||
+ | ||
+ boost::graph_traits<TD_graph_t>::edge_iterator eIt, eEnd; | ||
+ for(boost::tie(eIt, eEnd) = boost::edges(G); eIt != eEnd; eIt++){ | ||
+ E_G.push_back(G[boost::source(*eIt, G)].id); | ||
+ E_G.push_back(G[boost::target(*eIt, G)].id); | ||
+ } | ||
+} | ||
+ | ||
+void make_sage_decomp(TD_tree_dec_t &T, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T){ | ||
+ std::map<boost::graph_traits<TD_tree_dec_t>::vertex_descriptor, unsigned int> vertex_map; | ||
+ boost::graph_traits<TD_tree_dec_t>::vertex_iterator tIt, tEnd; | ||
+ unsigned int id = 0; | ||
+ | ||
+ for(boost::tie(tIt, tEnd) = boost::vertices(T); tIt != tEnd; tIt++){ | ||
+ vertex_map.insert(std::pair<boost::graph_traits<TD_tree_dec_t>::vertex_descriptor, unsigned int>(*tIt, id++)); | ||
+ std::vector<int> bag; | ||
+ for(std::set<unsigned int>::iterator sIt = T[*tIt].bag.begin(); sIt != T[*tIt].bag.end(); sIt++) | ||
+ bag.push_back((int)*sIt); | ||
+ V_T.push_back(bag); | ||
+ } | ||
+ | ||
+ boost::graph_traits<TD_tree_dec_t>::edge_iterator eIt, eEnd; | ||
+ for(boost::tie(eIt, eEnd) = boost::edges(T); eIt != eEnd; eIt++){ | ||
+ std::map<boost::graph_traits<TD_tree_dec_t>::vertex_descriptor, unsigned int>::iterator v, w; | ||
+ v = vertex_map.find(boost::source(*eIt, T)); | ||
+ w = vertex_map.find(boost::target(*eIt, T)); | ||
+ E_T.push_back(v->second); | ||
+ E_T.push_back(w->second); | ||
+ } | ||
+} | ||
+ | ||
+ | ||
+/* PREPROCESSING */ | ||
+ | ||
+int sage_preprocessing_MD(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, int lb){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ TD_tree_dec_t T; | ||
+ | ||
+ treedec::preprocessing_MD(G, T, lb); | ||
+ | ||
+ make_sage_decomp(T, V_T, E_T); | ||
+ | ||
+ return lb; | ||
+} | ||
+ | ||
+ | ||
+int sage_preprocessing_FI_TM(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, int lb){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ TD_tree_dec_t T; | ||
+ | ||
+ treedec::preprocessing_FI_TM(G, T, lb); | ||
+ | ||
+ make_sage_decomp(T, V_T, E_T); | ||
+ | ||
+ return lb; | ||
+} | ||
+ | ||
+ | ||
+/* LOWER BOUNDS */ | ||
+ | ||
+ | ||
+int sage_deltaC_min_d(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ return treedec::lb::deltaC_min_d(G); | ||
+} | ||
+ | ||
+int sage_deltaC_max_d(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ return treedec::lb::deltaC_max_d(G); | ||
+} | ||
+ | ||
+int sage_deltaC_least_c(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ return treedec::lb::deltaC_least_c(G); | ||
+} | ||
+ | ||
+int sage_LBN_deltaC(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ return treedec::lb::LBN_deltaC(G); | ||
+} | ||
+ | ||
+int sage_LBNC_deltaC(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ return treedec::lb::LBNC_deltaC(G); | ||
+} | ||
+ | ||
+int sage_LBP_deltaC(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ return treedec::lb::LBP_deltaC(G); | ||
+} | ||
+ | ||
+int sage_LBPC_deltaC(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ return treedec::lb::LBPC_deltaC(G); | ||
+} | ||
+ | ||
+ | ||
+/* EXACT TREE DECOMPOSITIONS */ | ||
+ | ||
+int sage_CR_greedy_decomp(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, int lb){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ TD_tree_dec_t T; | ||
+ | ||
+ treedec::CR_greedy_decomp(G, T, lb); | ||
+ | ||
+ make_sage_decomp(T, V_T, E_T); | ||
+ | ||
+ return treedec::get_width(T); | ||
+} | ||
+ | ||
+ | ||
+int sage_CR_dynamic_decomp(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, int lb){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ TD_tree_dec_t T; | ||
+ | ||
+ treedec::CR_dynamic_decomp(G, T, lb); | ||
+ | ||
+ make_sage_decomp(T, V_T, E_T); | ||
+ | ||
+ return treedec::get_width(T); | ||
+} | ||
+ | ||
+/* APPOXIMATIVE TREE DECOMPOSITIONS */ | ||
+ | ||
+ | ||
+int sage_seperator_algorithm(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ TD_tree_dec_t T; | ||
+ | ||
+ treedec::seperator_algorithm(G, T); | ||
+ | ||
+ make_sage_decomp(T, V_T, E_T); | ||
+ | ||
+ return treedec::get_width(T); | ||
+} | ||
+ | ||
+int sage_ordering_to_treedec(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, std::vector<unsigned int> &elim_ordering){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ TD_tree_dec_t T; | ||
+ treedec::ordering_to_treedec(G, elim_ordering, T); | ||
+ | ||
+ make_sage_decomp(T, V_T, E_T); | ||
+ | ||
+ return treedec::get_width(T); | ||
+} | ||
+ | ||
+void sage_treedec_to_ordering(std::vector<std::vector<int> > &V, std::vector<unsigned int> &E, std::vector<unsigned int> &elim_ordering){ | ||
+ TD_tree_dec_t T; | ||
+ make_tdlib_decomp(T, V, E); | ||
+ | ||
+ treedec::treedec_to_ordering(T, elim_ordering); | ||
+} | ||
+ | ||
+ | ||
+/* POSTPROCESSING */ | ||
+ | ||
+int sage_MSVS(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ TD_tree_dec_t T; | ||
+ make_tdlib_decomp(T, V_T, E_T); | ||
+ | ||
+ treedec::MSVS(G, T); | ||
+ | ||
+ V_T.clear(); | ||
+ E_T.clear(); | ||
+ | ||
+ make_sage_decomp(T, V_T, E_T); | ||
+ | ||
+ return treedec::get_width(T); | ||
+} | ||
+ | ||
+void sage_minimalChordal(std::vector<unsigned int> &V, std::vector<unsigned int> &E, std::vector<unsigned int> &old_elimination_ordering, std::vector<unsigned int> &new_elimination_ordering){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V, E); | ||
+ | ||
+ treedec::minimalChordal(G, old_elimination_ordering, new_elimination_ordering); | ||
+} | ||
+ | ||
+ | ||
+/* MISC */ | ||
+ | ||
+ | ||
+int sage_is_valid_decomposition(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T){ | ||
+ TD_graph_t G; | ||
+ make_tdlib_graph(G, V_G, E_G); | ||
+ | ||
+ TD_tree_dec_t T; | ||
+ make_tdlib_decomp(T, V_T, E_T); | ||
+ | ||
+ return treedec::is_valid_treedecomposition(G, T); | ||
+} | ||
+ | ||
+int sage_get_width(std::vector<std::vector<int> > &V_T){ | ||
+ int width = 0; | ||
+ for(unsigned int i = 0; i< V_T.size(); i++) | ||
+ width = ((int)V_T[i].size() > width)? (int)V_T[i].size() : width; | ||
+ | ||
+ return width-1; | ||
+} | ||
diff -rupN tdlib-1.0/sage_tdlib.hpp tdlib-1.0_/sage_tdlib.hpp | ||
--- tdlib-1.0/sage_tdlib.hpp 1970-01-01 01:00:00.000000000 +0100 | ||
+++ tdlib-1.0_/sage_tdlib.hpp 2015-09-19 19:27:05.166713818 +0200 | ||
@@ -0,0 +1,45 @@ | ||
+/* TdLib interface for sage */ | ||
+ | ||
+ | ||
+/* PREPROCESSING */ | ||
+ | ||
+int sage_preprocessing(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &bags, int lb); | ||
+int sage_preprocessing_MD(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, int lb); | ||
+int sage_preprocessing_FI_TM(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, int lb); | ||
+ | ||
+/* LOWER BOUNDS */ | ||
+ | ||
+int sage_deltaC_min_d(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G); | ||
+int sage_deltaC_max_d(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G); | ||
+int sage_deltaC_least_c(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G); | ||
+ | ||
+int sage_LBN_deltaC(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G); | ||
+int sage_LBNC_deltaC(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G); | ||
+int sage_LBP_deltaC(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G); | ||
+int sage_LBPC_deltaC(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G); | ||
+ | ||
+ | ||
+/* EXACT TREE DECOMPOSITIONS */ | ||
+ | ||
+int sage_CR_greedy_decomp(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, int lb); | ||
+int sage_CR_dynamic_decomp(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, int lb); | ||
+ | ||
+ | ||
+/* APPROXIMATIVE TREE DECOMPOSITIONS */ | ||
+ | ||
+int sage_seperator_algorithm(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T); | ||
+ | ||
+ | ||
+/* POSTPROCESSING */ | ||
+ | ||
+int sage_MSVS(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T); | ||
+void sage_minimalChordal(std::vector<unsigned int> &V, std::vector<unsigned int> &E, std::vector<unsigned int> &old_elimination_ordering, std::vector<unsigned int> &new_elimination_ordering); | ||
+ | ||
+ | ||
+/* MISC */ | ||
+ | ||
+int sage_is_valid_decomposition(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T); | ||
+int sage_ordering_to_treedec(std::vector<unsigned int> &V_G, std::vector<unsigned int> &E_G, std::vector<std::vector<int> > &V_T, std::vector<unsigned int> &E_T, std::vector<unsigned int> &elim_ordering); | ||
+void sage_treedec_to_ordering(std::vector<std::vector<int> > &V, std::vector<unsigned int> &E, std::vector<unsigned int> &elim_ordering); | ||
+int sage_get_width(std::vector<std::vector<int> > &V_T); | ||
+ |
Oops, something went wrong.