00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef IMPDOMINO_JUNCTION_TREE_H
00010 #define IMPDOMINO_JUNCTION_TREE_H
00011
00012 #include "domino_config.h"
00013 #include "IMP/base_types.h"
00014 #include <boost/graph/graph_traits.hpp>
00015 #include <boost/graph/adjacency_list.hpp>
00016 #include <boost/algorithm/string.hpp>
00017 #include <boost/lexical_cast.hpp>
00018
00019 IMPDOMINO_BEGIN_NAMESPACE
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class IMPDOMINOEXPORT JunctionTree {
00033 public:
00034 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>
00035 Graph;
00036 JunctionTree() {}
00037 JunctionTree(int number_of_nodes) {
00038 set_nodes(number_of_nodes);
00039 }
00040
00041
00042 void set_nodes(int number_of_nodes);
00043
00044 void add_edge(int v1,int v2) {
00045 IMP_INTERNAL_CHECK(static_cast<unsigned int>(v1) < boost::num_vertices(g_),
00046 "input node index (" << v1 << ") is out of range ("
00047 << boost::num_vertices(g_) << std::endl);
00048 IMP_INTERNAL_CHECK(static_cast<unsigned int>(v2) < boost::num_vertices(g_),
00049 "input node index (" << v2 << ") is out of range ("
00050 << boost::num_vertices(g_) << std::endl);
00051 boost::add_edge(v1,v2,g_);
00052 }
00053 void set_node_name(int vi, const std::string &name) {
00054 IMP_USAGE_CHECK(static_cast<unsigned int>(vi) < boost::num_vertices(g_),
00055 "input node index (" << vi << ") is out of range ("
00056 << boost::num_vertices(g_) << ")"<<std::endl);
00057 data_[vi].push_back(name);
00058 }
00059 const Graph *get_graph() const {return &g_;}
00060 int get_number_of_components(int vi) const {return data_[vi].size();}
00061
00062
00063
00064
00065
00066
00067
00068 const std::string get_component_name(int vi,int ci) const;
00069
00070
00071
00072
00073
00074
00075 void set_component_name(int vi,int ci,const std::string &name);
00076
00077 int get_number_of_nodes() const {return boost::num_vertices(g_);}
00078 void add_component_to_node(int vi, const std::string &name) {
00079 data_[vi].push_back(name);}
00080 bool has_edge(int n1,int n2) const{
00081 bool found;
00082 boost::graph_traits <Graph>::edge_descriptor e;
00083 boost::tie(e, found) =
00084 boost::edge(boost::vertex(n1,g_), boost::vertex(n2,g_), g_);
00085 return found;
00086 }
00087 void show(std::ostream& out = std::cout) const;
00088 protected:
00089 typedef std::vector<std::vector<std::string> > NodeData;
00090 Graph g_;
00091 NodeData data_;
00092 };
00093
00094
00095 IMPDOMINOEXPORT void read_junction_tree(
00096 const std::string &filename, JunctionTree *jt);
00097
00098 IMPDOMINO_END_NAMESPACE
00099
00100 #endif