39 for (
auto &r :
path) {
48 path.push_front(data);
59 if (
path.size() <= 1)
return;
60 std::deque< Path_t > newpath;
61 for (
size_t i = 0; i <
path.size(); ++i) {
64 (i == 0? -1 :
path[i - 1].edge),
65 (i == 0? 0 :
path[i - 1].cost),
69 for (
size_t i = 0; i < newpath.size(); ++i) {
70 newpath[i].agg_cost = (i == 0)?
72 newpath[i - 1].agg_cost + newpath[i - 1].cost;
79 for (
auto &p :
path) {
97 [](
Path_t p, int64_t e) {return p.edge == e;});
107 auto position = std::search(
109 [](
Path_t p, int64_t e) { return p.edge == e;});
110 if (position !=
path.end()) {
111 position->agg_cost = std::numeric_limits<double>::infinity();
119 log <<
"Path: " << path.
start_id() <<
" -> " << path.
end_id() <<
"\n"
120 <<
"seq\tnode\tedge\tcost\tagg_cost\n";
122 for (
const auto &e : path) {
127 << e.agg_cost <<
"\n";
134 return static_cast<size_t>(std::count_if(
path.begin(),
path.end(),
135 [](
Path_t const&p) ->
size_t {
136 return std::isinf(p.agg_cost);
143 if (j == 0)
return result;
144 for (
auto i =
path.begin(); i !=
path.begin() + j; ++i) {
154 if (subpath.
empty())
return true;
155 if (subpath.
size() >=
path.size())
return false;
156 std::deque< Path_t >::const_iterator i, j;
157 for (i =
path.begin(), j = subpath.
begin();
160 if ((*i).node != (*j).node)
return false;
209 auto last =
path.back();
210 auto agg_cost = last.agg_cost;
214 for (
auto item : other.
path) {
215 item.agg_cost += agg_cost;
223 size_t &sequence)
const {
225 for (
const auto e :
path) {
226 auto agg_cost = std::fabs(
227 e.agg_cost - (std::numeric_limits<double>::max)()) < 1?
228 std::numeric_limits<double>::infinity() : e.agg_cost;
229 auto cost = std::fabs(e.cost - (std::numeric_limits<double>::max)()) < 1?
230 std::numeric_limits<double>::infinity() : e.cost;
232 (*postgres_data)[sequence] = {i,
start_id(),
end_id(), e.node, e.edge, cost, agg_cost};
241 size_t &sequence)
const {
242 for (
unsigned int i = 0; i <
path.size(); i++) {
243 (*ret_path)[sequence].seq =
static_cast<int>(i);
244 (*ret_path)[sequence].start_id =
start_id();
245 (*ret_path)[sequence].end_id =
start_id();
246 (*ret_path)[sequence].node =
path[i].node;
247 (*ret_path)[sequence].edge =
path[i].edge;
248 (*ret_path)[sequence].cost =
path[i].cost;
249 (*ret_path)[sequence].agg_cost =
path[i].agg_cost;
257 size_t &sequence,
int routeId)
const {
258 for (
unsigned int i = 0; i <
path.size(); i++) {
259 (*ret_path)[sequence].seq =
static_cast<int>(i + 1);
260 (*ret_path)[sequence].start_id = routeId;
261 (*ret_path)[sequence].end_id =
end_id();
262 (*ret_path)[sequence].node =
path[i].node;
263 (*ret_path)[sequence].edge =
path[i].edge;
264 (*ret_path)[sequence].cost =
path[i].cost;
265 (*ret_path)[sequence].agg_cost = (i == 0)?
267 (*ret_path)[sequence-1].agg_cost +
path[i-1].cost;
275 size_t &sequence,
int routeId)
const {
276 for (
unsigned int i = 0; i <
path.size(); i++) {
277 (*ret_path)[sequence].seq =
static_cast<int>(i + 1);
278 (*ret_path)[sequence].start_id = routeId;
279 (*ret_path)[sequence].end_id =
end_id();
280 (*ret_path)[sequence].node =
path[i].node;
281 (*ret_path)[sequence].edge =
path[i].edge;
282 (*ret_path)[sequence].cost =
path[i].cost;
283 (*ret_path)[sequence].agg_cost =
path[i].agg_cost;
298 {return l.node < r.node;});
299 std::stable_sort(
path.begin(),
path.end(),
301 {return l.agg_cost < r.agg_cost;});
312 const std::deque< Path > &paths) {
314 for (
const Path &path : paths) {
315 if (path.path.size() > 0)
316 path.generate_postgres_data(ret_path, sequence);
338 std::sort(paths.begin(), paths.end(),
339 [](
const Path &e1,
const Path &e2)->bool {
340 return e2.size() < e1.size();
344 for (
auto &p : paths) {
345 if (p.size() < 2)
continue;
346 std::sort(p.begin(), p.end(),
348 return e1.node < e2.node;
352 for (
auto &p1 : paths) {
353 for (
const auto &p2 : paths) {
354 if (p1.start_id() == p2.start_id())
continue;
355 for (
const auto &stop : p2.path) {
357 auto pos = lower_bound(p1.begin(), p1.end(), stop,
359 return l.node < r.node;
363 && (stop.node == pos->node)
364 && (stop.agg_cost < pos->agg_cost)) {
374 std::sort(paths.begin(), paths.end(),
375 [](
const Path &e1,
const Path &e2)->bool {
376 return e1.start_id() < e2.start_id();
380 for (
auto &path : paths) {
381 path.sort_by_node_agg_cost();
389 for (
const Path &e : paths) {
390 count += e.path.size();