43#ifndef __ADS_interop_boost_Dijkstra
44 #define __ADS_interop_boost_Dijkstra
47#if defined( ADS_WITH_BOOST )
56#include <boost/graph/breadth_first_search.hpp>
57#include <boost/graph/graph_traits.hpp>
58#include <boost/graph/properties.hpp>
59#include <boost/property_map/property_map.hpp>
78template< FrontierQueue Q ,
class DistanceMap >
83 using value_type = int;
88 UpdatableQueue( Q & q ,
int n , DistanceMap d ) : f_S( q , n ) , f_d( d ) { }
91 void push(
int v ) { f_S.add( v , get( f_d , v ) ,
true ); }
94 void update(
int v ) { f_S.update( v , get( f_d , v ) ); }
100 f_top = f_S.extract();
112 [[nodiscard]]
bool empty(
void )
const {
113 return( ( f_top < 0 ) && f_S.empty() );
117 PriorityFrontier< Q > f_S;
134template<
class B ,
class WeightMap ,
class PredecessorMap ,
136struct RelaxVisitor : boost::default_bfs_visitor
145 template<
class E ,
class G >
146 bool relax(
const E & e ,
const G & g )
const {
147 const auto u = source( e , g ) , v = target( e , g );
148 const auto du = get( d , u ) + get( w , e );
149 if( du < get( d , v ) ) {
158 template<
class E ,
class G >
159 void tree_edge(
const E & e ,
const G & g )
const {
160 ( void )relax( e , g );
164 template<
class E ,
class G >
165 void gray_target(
const E & e ,
const G & g )
const {
167 queue->update(
int( target( e , g ) ) );
201template<
class G , FrontierQueue Q ,
class WeightMap ,
class PredecessorMap ,
203void dijkstraShortestPaths(
const G & g ,
int s , Q & q , WeightMap w ,
204 PredecessorMap p , DistanceMap d )
206 using D =
typename boost::property_traits< DistanceMap >::value_type;
207 const int n = int( num_vertices( g ) );
208 ADS_PRE( ( s >= 0 ) && ( s < n ) && q.empty() );
209 for(
int v = 0 ; v < n ; ++v ) {
210 put( d , v , std::numeric_limits< D >::max() );
213 put( d , s , D( 0 ) );
214 using B = UpdatableQueue< Q , DistanceMap >;
215 B buffer( q , n , d );
216 std::vector< boost::default_color_type > color( std::size_t( n ) ,
217 boost::white_color );
218 detail::RelaxVisitor< B , WeightMap , PredecessorMap , DistanceMap > vis;
223 boost::breadth_first_visit(
224 g , s , buffer , vis ,
225 boost::make_iterator_property_map(
226 color.data() , boost::typed_identity_property_map< int >() ) );
231template<
class G , FrontierQueue Q ,
class PredecessorMap ,
233void dijkstraShortestPaths(
const G & g ,
int s , Q & q , PredecessorMap p ,
236 dijkstraShortestPaths( g , s , q , get( boost::edge_weight , g ) , p , d );
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The shortest paths of chapter 11 from a node of an oriented GRAPH whose edges have a cost [see Grap...
#define ADS_PRE(cond)
[check]
Definition Contract.h:121