andres::graph
paths.hxx
1 #pragma once
2 #ifndef ANDRES_GRAPH_PATHS_HXX
3 #define ANDRES_GRAPH_PATHS_HXX
4 
5 #include <cstddef>
6 #include <utility> // std::pair
7 
8 #include "andres/graph/graph.hxx" // DefaultSubgraphMask
9 
10 namespace andres {
11 namespace graph {
12 
20 template<class GRAPH, class ITERATOR>
21 inline std::pair<bool, std::size_t>
23  const GRAPH& graph,
24  ITERATOR begin,
25  ITERATOR end,
26  const bool ignoreEdgeBetweenFirstAndLast = false
27 ) {
28  return findChord(graph, DefaultSubgraphMask<>(), begin, end,
29  ignoreEdgeBetweenFirstAndLast);
30 }
31 
40 template<class GRAPH, class SUBGRAPH_MASK, class ITERATOR>
41 inline std::pair<bool, std::size_t>
43  const GRAPH& graph,
44  const SUBGRAPH_MASK& mask,
45  ITERATOR begin,
46  ITERATOR end,
47  const bool ignoreEdgeBetweenFirstAndLast = false
48 ) {
49  for(ITERATOR it = begin; it != end - 1; ++it)
50  for(ITERATOR it2 = it + 2; it2 != end; ++it2) {
51  if(ignoreEdgeBetweenFirstAndLast && it == begin && it2 == end - 1) {
52  continue;
53  }
54  std::pair<bool, std::size_t> p = graph.findEdge(*it, *it2);
55  if(p.first && mask.edge(p.second)) {
56  return p;
57  }
58  }
59  return std::pair<bool, std::size_t>(false, 0);
60 }
61 
62 } // namespace graph
63 } // namespace andres
64 
65 #endif // #ifndef ANDRES_GRAPH_PATHS_HXX