Open C++ Libraries.org develop
Loading...
Searching...
No Matches
dijkstra.hpp
1// SPDX-License-Identifier: BSL-1.0
2// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org)
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5// Official repository: https://github.com/open-cpp-libraries/tproc
6
7#ifndef OCL_TPROC_DIJKSTRA_HPP
8#define OCL_TPROC_DIJKSTRA_HPP
9
10#include <ocl/tproc/detail/config.hpp>
11
13
14namespace ocl::tproc
15{
16
19 template <class SourcePair>
20 inline void dijkstra(SourcePair& pair)
21 {
22 for (const auto& v : pair.source.vertices())
23 {
24 pair.dist[v] = SourcePair::infinity;
25 pair.prev[v] = SourcePair::undefined;
26 pair.result += v;
27 pair.source[v] = {};
28 }
29
30 while (pair.result)
31 {
32 auto vert = pair.result.vertex;
33 pair.result.remove(vert);
34
35 for (auto& v : pair.graph)
36 {
37 const auto& alt = pair.dist[v.u] + pair.graph.distance(v.u, v.v);
38
39 if (alt < pair.dist[v.u])
40 {
41 pair.dist[v.v] = alt;
42 pair.prev[v.v] = vert;
43 }
44 }
45 }
46 }
47
48} // namespace ocl::tproc
49
50#include "dijkstra.inl"
51
52#endif // OCL_TPROC_DIJKSTRA_HPP
AMLALE: SourcePair desrves documentation by themselves.
Definition bfs.hpp:13
void dijkstra(SourcePair &pair)
Implementation of dijkstra's algorithm.
Definition dijkstra.hpp:20