- Timestamp:
- May 19, 2017, 9:27:11 AM (8 years ago)
- Branches:
- ForceAnnealing_goodresults, ForceAnnealing_tocheck
- Children:
- adbeca
- Parents:
- 6370f9
- Location:
- src/Graph
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Graph/BoostGraphCreator.hpp
r6370f9 r060fc3 38 38 39 39 public: 40 40 41 //!> typedef for an undirected graph using boost::graph 41 42 typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, 42 boost::property<boost::vertex_name_t, atomId_t>, boost::no_property > UndirectedGraph; 43 boost::property<boost::vertex_name_t, atomId_t>, 44 boost::property<boost::vertex_color_t, boost::default_color_type> /* needed for limited-depth DFS, 45 otherwise the property_map gets full size of graph */ 46 > UndirectedGraph; 47 43 48 //!> typedef for a map of graph node indices 44 49 typedef boost::property_map < UndirectedGraph, boost::vertex_index_t >::type index_map_t; -
src/Graph/BreadthFirstSearchGatherer.cpp
r6370f9 r060fc3 44 44 #include <boost/graph/breadth_first_search.hpp> 45 45 46 struct found_max_distance {}; // exception when doing limited BFS 47 46 48 /** 47 49 * I have no idea why this is so complicated with BGL ... … … 54 56 { 55 57 public: 56 distance_recorder(DistanceMap dist) : d(dist) {} 58 distance_recorder( 59 DistanceMap dist, 60 const size_t _max_distance) : d(dist), max_distance(_max_distance) {} 57 61 58 62 template <typename Edge, typename Graph> … … 62 66 } 63 67 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 64 74 private: 65 75 DistanceMap d; 76 const size_t max_distance; 66 77 }; 67 78 68 79 template <typename DistanceMap> 69 distance_recorder<DistanceMap> record_distance(DistanceMap d )80 distance_recorder<DistanceMap> record_distance(DistanceMap d, const size_t _max_distance) 70 81 { 71 return distance_recorder<DistanceMap>(d );82 return distance_recorder<DistanceMap>(d, _max_distance); 72 83 } 73 84 … … 76 87 {} 77 88 78 std::vector<atomId_t> BreadthFirstSearchGatherer::operator()(const atomId_t &_discoverfrom) 89 std::vector<atomId_t> BreadthFirstSearchGatherer::operator()( 90 const atomId_t &_discoverfrom, 91 const size_t &_max_distance) 79 92 { 80 93 std::vector<atomId_t> returnids; … … 86 99 const BoostGraphCreator::nodeId_t discoverfrom_nodeid = BGcreator.getNodeId(_discoverfrom); 87 100 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 } 92 109 LOG(3, "DEBUG: From atom #" << _discoverfrom 93 110 << " BFS discovered the following distances " << distances); -
src/Graph/BreadthFirstSearchGatherer.hpp
r6370f9 r060fc3 35 35 /** Discovers all nodes from the given \a _discoverfrom and returns 36 36 * the vector of ids. 37 * 38 * \param _discoverfrom node to start BFS from 39 * \param _max_distance max distance to discover (0 means all) 37 40 */ 38 std::vector<atomId_t> operator()(const atomId_t &_discoverfrom); 41 std::vector<atomId_t> operator()( 42 const atomId_t &_discoverfrom, 43 const size_t &_max_distance = 0); 39 44 40 45 private: -
src/Graph/unittests/BreadthFirstSearchGathererUnitTest.cpp
r6370f9 r060fc3 105 105 CPPUNIT_ASSERT_EQUAL (compareids, atomids); 106 106 }; 107 108 /** Tests whether operator() with limited distance works. 109 */ 110 void BreadthFirstSearchGathererTest::limitedDistanceTest() 111 { 112 // create linear test graph 113 prepareLinearGraph(); 114 115 // call operator 116 BreadthFirstSearchGatherer gatherer(*BGCreator); 117 std::vector<atomId_t> atomids = gatherer(0, 3); 118 119 // create comparator set 120 std::vector<atomId_t> compareids; 121 compareids += 0,1,2,3; 122 CPPUNIT_ASSERT_EQUAL ((size_t)4, atomids.size()); 123 CPPUNIT_ASSERT_EQUAL (compareids, atomids); 124 }; -
src/Graph/unittests/BreadthFirstSearchGathererUnitTest.hpp
r6370f9 r060fc3 25 25 CPPUNIT_TEST_SUITE( BreadthFirstSearchGathererTest) ; 26 26 CPPUNIT_TEST ( operatorTest ); 27 CPPUNIT_TEST ( limitedDistanceTest ); 27 28 CPPUNIT_TEST_SUITE_END(); 28 29 … … 31 32 void tearDown(); 32 33 void operatorTest(); 34 void limitedDistanceTest(); 33 35 34 36 private:
Note:
See TracChangeset
for help on using the changeset viewer.