Ignore:
Timestamp:
Jul 5, 2017, 7:40:48 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
ForceAnnealing_oldresults, IndependentFragmentGrids_IntegrationTest
Children:
89235ea
Parents:
6afd46
git-author:
Frederik Heber <frederik.heber@…> (05/18/17 17:45:47)
git-committer:
Frederik Heber <frederik.heber@…> (07/05/17 19:40:48)
Message:

Extracted extraction (subset of) nodes from BoostGraph into BreadthFirstSearchGatherer.

  • also added helper namespace BoostGraphHelpers.
  • we now treat the vertex indices and vertex names properly. Before that they had to coincide. Now, the name is the atomic id associated with the node and the index is the boost::graph internal index.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Graph/BoostGraphCreator.cpp

    r6afd46 r6e5907  
    8585      std::back_inserter(atomids), getAtomId);
    8686  ASSERT( _atoms.size() == atomids.size(),
    87       "BoostGraphCreator::createFromAtom() - atomids and atoms differ in size?");
     87      "BoostGraphCreator::createFromAtom() - atomids "
     88      +toString(atomids.size())+" and atoms "+toString(_atoms.size())
     89      +" differ in size?");
    8890  std::sort(atomids.begin(), atomids.end());
    8991  const predicate_t predicate = boost::bind(inSetPredicate, boost::ref(atomids), _1);
     
    9597}
    9698
     99BoostGraphCreator::nodeId_t BoostGraphCreator::getNodeId(
     100    const atomId_t &_atomid) const
     101{
     102  atomids_nodeids_t::const_iterator iter =
     103      atomids_nodeids.find(_atomid);
     104  return (iter == atomids_nodeids.end()) ? (nodeId_t)-1 : iter->second;
     105}
     106
    97107template <typename iterator>
    98108void BoostGraphCreator::createFromRange(
     
    101111    const size_t &_no_nodes,
    102112    const predicate_t &_pred
    103     ) {
    104   // convert BondGraph into boost::graph
    105   UndirectedGraph molgraph(_no_nodes);
     113    )
     114{
     115  graph = UndirectedGraph();
     116
     117  // add vertices
    106118  for(iterator iter = _begin; iter != _end; ++iter) {
    107     LOG(2, "DEBUG: Looking at node " << (*iter)->getId());
     119    const atomId_t atomid = (*iter)->getId();
     120    Vertex v = boost::add_vertex(atomid, graph);
     121    const atomId_t vertexname = boost::get(boost::get(boost::vertex_name, graph), v);
     122    const nodeId_t vertexindex = boost::get(boost::get(boost::vertex_index, graph), v);
     123    LOG(2, "DEBUG: Adding node " << vertexindex << " associated to atom #" << vertexname);
     124    ASSERT( vertexname == atomid,
     125        "BoostGraphCreator::createFromRange() - atomid "+toString(atomid)
     126        +" is not name of vertex "+toString(vertexname)+".");
     127    atomids_nodeids.insert( std::make_pair(vertexname, vertexindex) );
     128  }
     129
     130  // add edges
     131  for(iterator iter = _begin; iter != _end; ++iter) {
     132    LOG(2, "DEBUG: Looking at atom " << (*iter)->getId());
    108133    const BondList& ListOfBonds = (*iter)->getListOfBonds();
    109134    for(BondList::const_iterator bonditer = ListOfBonds.begin();
    110135        bonditer != ListOfBonds.end(); ++bonditer) {
     136      LOG(2, "DEBUG: Looking at bond " << *(*bonditer));
    111137      const atomId_t leftid = (*bonditer)->leftatom->getId();
     138      const nodeId_t leftnodeid = getNodeId(leftid);
    112139      const atomId_t rightid = (*bonditer)->rightatom->getId();
     140      const nodeId_t rightnodeid = getNodeId(rightid);
    113141      // only pick each bond once and evaluate predicate
    114142      if ((leftid == (*iter)->getId())
    115143          && (_pred(**bonditer))) {
    116         LOG(3, "DEBUG: ADDING edge " << leftid << " <-> " << rightid);
    117         boost::add_edge(leftid, rightid, graph);
     144        LOG(3, "DEBUG: ADDING edge " << leftnodeid << " <-> " << rightnodeid);
     145        boost::add_edge(leftnodeid, rightnodeid, graph);
    118146      } else {
    119         LOG(3, "DEBUG: Discarding edge " << leftid << " <-> " << rightid);
     147        LOG(3, "DEBUG: Discarding edge " << leftnodeid << " <-> " << rightnodeid);
    120148      }
    121149    }
Note: See TracChangeset for help on using the changeset viewer.