Ignore:
Timestamp:
Jul 12, 2017, 7:10:32 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Action_Thermostats, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Exclude_Hydrogens_annealWithBondGraph, Fix_Verbose_Codepatterns, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, Recreated_GuiChecks, StoppableMakroAction, TremoloParser_IncreasedPrecision
Children:
966ce7
Parents:
0dc8bf2
git-author:
Frederik Heber <frederik.heber@…> (05/19/17 09:27:11)
git-committer:
Frederik Heber <frederik.heber@…> (07/12/17 19:10:32)
Message:

Extended BreadthFirstSearchGatherer to allow BFS with limited discovery horizon.

  • TESTS: extended unit test as well.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Graph/BreadthFirstSearchGatherer.cpp

    r0dc8bf2 re3ec8a8  
    4444#include <boost/graph/breadth_first_search.hpp>
    4545
     46struct found_max_distance {}; // exception when doing limited BFS
     47
    4648/**
    4749 * I have no idea why this is so complicated with BGL ...
     
    5456{
    5557public:
    56   distance_recorder(DistanceMap dist) : d(dist) {}
     58  distance_recorder(
     59      DistanceMap dist,
     60      const int _max_distance) : d(dist), max_distance(_max_distance) {}
    5761
    5862  template <typename Edge, typename Graph>
     
    6266  }
    6367
     68  template <typename Vertex, typename Graph>
     69  void discover_vertex(Vertex u, const Graph &g) const {
     70    if ((max_distance >= 0) && (d[u] >= max_distance))
     71      throw found_max_distance();
     72  }
     73
    6474private:
    6575  DistanceMap d;
     76  const int max_distance;
    6677};
    6778
    6879template <typename DistanceMap>
    69 distance_recorder<DistanceMap> record_distance(DistanceMap d)
     80distance_recorder<DistanceMap> record_distance(DistanceMap d, const size_t _max_distance)
    7081{
    71   return distance_recorder<DistanceMap>(d);
     82  return distance_recorder<DistanceMap>(d, _max_distance);
    7283}
    7384
     
    7687{}
    7788
    78 std::vector<atomId_t> BreadthFirstSearchGatherer::operator()(const atomId_t &_discoverfrom)
     89std::vector<atomId_t> BreadthFirstSearchGatherer::operator()(
     90    const atomId_t &_discoverfrom,
     91    const int &_max_distance)
    7992{
    8093  std::vector<atomId_t> returnids;
     
    8699  const BoostGraphCreator::nodeId_t discoverfrom_nodeid = BGcreator.getNodeId(_discoverfrom);
    87100  distances[ boost::vertex(discoverfrom_nodeid, BGgraph) ] = 0;
    88   boost::breadth_first_search(
    89       BGgraph,
    90       boost::vertex(discoverfrom_nodeid, BGgraph),
    91       boost::visitor(record_distance(&distances[0])));
     101  try {
     102    boost::breadth_first_search(
     103        BGgraph,
     104        boost::vertex(discoverfrom_nodeid, BGgraph),
     105        boost::visitor(record_distance(&distances[0], _max_distance)));
     106  } catch (found_max_distance &e) {
     107    // where are at discovery horizon
     108  }
    92109  LOG(3, "DEBUG: From atom #" << _discoverfrom
    93110      << " BFS discovered the following distances " << distances);
Note: See TracChangeset for help on using the changeset viewer.