/** * \file JunctionTree.cpp * \brief Stores a junction tree * * Copyright 2007-2010 IMP Inventors. All rights reserved. * */ #include "IMP/domino/JunctionTree.h" #include #include IMPDOMINO_BEGIN_NAMESPACE void read_junction_tree(const std::string &filename, JunctionTree *jt) { std::ifstream jt_f (filename.c_str()); if (! jt_f.is_open()) { IMP_THROW("problem opening junction tree file: "<< filename, IOException); } std::string line; int status=0; //0 - nodes header, 1 - nodes, 2 - edges header, 3 - edges int node_ind = 0; while (!jt_f.eof()) { getline (jt_f,line); std::vector ls; boost::split(ls, line, boost::is_any_of(" ")); if (status==0) { if (ls[0] == "nodes:") { status=1; jt->set_nodes(boost::lexical_cast(ls[1])); } else { IMP_INTERNAL_CHECK(true, "wrong junction tree format"); } } else if (status == 1) { if (ls[0] == "edges:") { status=2; } else { for(std::vector::iterator it = ls.begin(); it != ls.end(); it++) { boost::trim(*it); if (it->size() >0) { jt->set_node_name(node_ind,*it); IMP_LOG(VERBOSE,"adding component "<< *it << " to node " << node_ind << std::endl); } } node_ind = node_ind +1; } } else if (status == 2) { if (ls.size() == 2) { IMP_LOG(VERBOSE,"adding edge bewteen " << ls[0] << " and " << ls[1]<< std::endl); jt->add_edge(boost::lexical_cast(ls[0]), boost::lexical_cast(ls[1])); } else { IMP_WARN("edge line was not parsed: "<()); } void JunctionTree::set_component_name(int vi,int ci,const std::string &name) { IMP_USAGE_CHECK(static_cast(vi) < boost::num_vertices(g_), "input node index (" << vi << ") is out of range (" << boost::num_vertices(g_) <<")" <(vi) < boost::num_vertices(g_), "input node index (" << vi << ") is out of range (" << boost::num_vertices(g_) <<")" <::edge_iterator ei_begin, ei_end, ei; tie(ei_begin, ei_end) = edges(g_); for (ei = ei_begin; ei != ei_end; ei++) { out << *ei << std::endl; } out << "==================================" << std::endl; out << "==================================" << std::endl; } IMPDOMINO_END_NAMESPACE