2 #ifndef OPENGM_MODELTREES_HXX
3 #define OPENGM_MODELTRESS_HXX
18 #include <boost/lexical_cast.hpp>
39 void roots(std::vector<IndexType>&);
40 void nodes(std::vector<std::vector<IndexType> >&);
46 std::map<IndexType, IndexType> representives_;
47 std::vector<IndexType> parents_;
48 std::vector<bool> b_roots_;
49 IndexType numberOfRoots_;
61 std::vector<std::set<IndexType> > neighbors;
62 gm_.variableAdjacencyList(neighbors);
64 std::vector<IndexType> degree(gm_.numberOfVariables());
65 std::vector<IndexType> leafs;
66 b_roots_.resize(gm_.numberOfVariables());
67 parents_.resize(gm_.numberOfVariables());
68 typename std::set<typename GM::IndexType>::iterator it;
69 typename std::set<typename GM::IndexType>::iterator fi;
72 degree[i]=neighbors[i].size();
73 parents_[i]=gm_.numberOfVariables();
78 while(!leafs.empty()){
82 it=neighbors[l].begin();
87 degree[*it]=degree[*it]-1;
88 fi=neighbors[*it].find(l);
89 neighbors[*it].erase(fi);
97 for(
IndexType i=0;i<gm_.numberOfVariables();++i){
99 representives_[i]=numberOfRoots_;
109 return numberOfRoots_;
115 if(parents_[i]==gm_.numberOfVariables()){
116 return gm_.numberOfVariables();
120 while(parents_[r]!=r){
130 roots.resize(numberOfRoots_);
132 for(
IndexType i=0;i<gm_.numberOfVariables();++i){
144 if(parents_[i]==gm_.numberOfVariables()){
145 return gm_.numberOfVariables();
156 nodes.resize(numberOfRoots_);
157 for(
IndexType i=0;i<gm_.numberOfVariables();++i){
158 if(parents_[i]!=gm_.numberOfVariables()){
159 IndexType treeID = representives_[treeOfVariable(i)];
160 nodes[treeID].push_back(i);
167 if(parents_[i]==gm_.numberOfVariables()){
168 return gm_.numberOfVariables();
171 return representives_[treeOfVariable(i)];
IndexType treeOfVariable(IndexType i)
IndexType numberOfTrees() const
GM::OperatorType OperatorType
modelTrees(const GmType &)
IndexType parentOfVariable(IndexType i)
void roots(std::vector< IndexType > &)
void nodes(std::vector< std::vector< IndexType > > &)
IndexType treeOfRoot(IndexType i)