diff --git a/include/Graph/Graph_TS.hpp b/include/Graph/Graph_TS.hpp index e1ab6ce7d..c2bc0536e 100644 --- a/include/Graph/Graph_TS.hpp +++ b/include/Graph/Graph_TS.hpp @@ -110,6 +110,20 @@ namespace CXXGRAPH * case if target is not reachable from source or there is error in the computation. */ const DijkstraResult dijkstra(const Node &source, const Node &target) const override; + /** + * @brief Function runs the bellmanford algorithm for some source node and + * target node in the graph and returns the shortest distance of target + * from the source if there is no negative cycle in the graph. + * Note: Thread Safe + * + * @param source source vertex + * @param target target vertex + * + * @return shortest distance if target is reachable from source else ERROR in + * case if target is not reachable from source or there is negative cycle or + * there is error in the computation. + */ + const BellmanFordResult bellmanford(const Node &source, const Node &target) const override; /** * \brief * Function performs the breadth first search algorithm over the graph @@ -304,6 +318,15 @@ namespace CXXGRAPH releaseLock(); return dij; } + + template + const BellmanFordResult Graph_TS::bellmanford(const Node &source, const Node &target) const + { + getLock(); + auto bellford = Graph::bellmanFord(source, target); + releaseLock(); + return bellford; + } template const std::vector> Graph_TS::breadth_first_search(const Node &start) const @@ -386,4 +409,4 @@ namespace CXXGRAPH return partitions; } } -#endif // __GRAPH_TS_H__ \ No newline at end of file +#endif // __GRAPH_TS_H__