1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*PGR-GNU*****************************************************************
File: hawickcircuits.hpp
Copyright (c) 2022 pgRouting developers
Mail: project@pgrouting.org
Copyright (c) 2022 Nitish Chauhan
Mail: nitishchauhan0022 at gmail.com
------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/
#ifndef INCLUDE_CIRCUITS_HAWICKCIRCUITS_HPP_
#define INCLUDE_CIRCUITS_HAWICKCIRCUITS_HPP_
#pragma once
#include <iostream>
#include <iterator>
#include <deque>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/hawick_circuits.hpp>
#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/base_graph.hpp"
#include "cpp_common/interruption.hpp"
#include "cpp_common/assert.hpp"
#include "c_types/circuits_rt.h"
/**
* @brief The main file which calls the respective boost function.
*
* Contains actual implementation of the function and the calling
* of the respective boost function.
*/
namespace pgrouting {
namespace functions {
template <typename G, typename E>
class circuit_detector{
public:
/** @brief circuit detector to get the results
*
* @param graph the graph containing the edges
* @param data container for storing the result
*
*/
circuit_detector(
G &graph,
std::deque<circuits_rt> &data) :
m_graph(graph),
m_data(data) {}
template <typename P, typename Gr>
void cycle(P const &p, Gr const& Grap) {
if (p.empty()) {
return;
}
int seq = 0;
typename P::const_iterator i, before_end = boost::prior(p.end());
auto start_vid = m_graph[*p.begin()].id;
auto end_vid = start_vid;
double agg_cost = 0;
E edge;
for (i = p.begin(); i != before_end; ++i, ++seq) {
auto node = m_graph[*i].id;
edge = boost::edge(*i, *(i+1), Grap).first;
auto cost = m_graph[edge].cost;
auto id = m_graph[edge].id;
m_data.push_back({circuit_No, seq, start_vid, end_vid, node, id, cost, agg_cost});
agg_cost = agg_cost + cost;
}
auto node = m_graph[*i].id;
edge = boost::edge(*(boost::prior(p.end())), *(p.begin()), Grap).first;
auto cost = m_graph[edge].cost;
auto id = m_graph[edge].id;
m_data.push_back({circuit_No, seq, start_vid, end_vid, node, id, cost, agg_cost});
agg_cost = agg_cost + cost;
++seq;
m_data.push_back({circuit_No, seq, start_vid, end_vid, start_vid, -1, 0, agg_cost});
circuit_No++;
}
private:
G &m_graph;
std::deque<circuits_rt> &m_data;
int circuit_No = 1;
};
template <class G>
class pgr_hawickCircuits{
public:
typedef typename G::E E;
/** @name hawickcircuit
* @{
*
*/
/** @brief hawickcircuit function
*
* It does all the processing and returns the results.
*
* @param graph the graph containing the edges
*
* @returns results, when results are found
*
* @see [boost::hawickcircuit]
* (https://www.boost.org/libs/graph/doc/hawick_circuits.html)
*/
std::deque<circuits_rt> hawickCircuits(G & graph) {
// results storing the output
std::deque<circuits_rt> results;
// a circuit detector to provide the mechanism to store the circuit
circuit_detector <G, E> detector(graph, results);
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::hawick_unique_circuits(graph.graph, detector);
} catch (boost::exception const& ex) {
(void)ex;
throw;
} catch (std::exception &e) {
(void)e;
throw;
} catch (...) {
throw;
}
return results;
//@}
}
};
} // namespace functions
} // namespace pgrouting
#endif // INCLUDE_CIRCUITS_HAWICKCIRCUITS_HPP_
|