39#ifndef __ADS_interop_boost_FromBGL
40 #define __ADS_interop_boost_FromBGL
43#if defined( ADS_WITH_BOOST )
53#include <boost/graph/graph_traits.hpp>
54#include <boost/graph/properties.hpp>
55#include <boost/property_map/property_map.hpp>
77template<
class BG ,
class WeightMap =
void >
81 using Traits = boost::graph_traits< BG >;
82 using Vertex =
typename Traits::vertex_descriptor;
85 typename boost::property_map< BG , boost::vertex_index_t >::const_type;
87 using Map = std::conditional_t< std::is_void_v< WeightMap > , std::monostate ,
92 static constexpr bool indexed = std::is_integral_v< Vertex >;
97 using Weight =
typename decltype( []() {
98 if constexpr( std::is_void_v< WeightMap > )
99 return( std::type_identity< std::monostate >() );
101 return( std::type_identity<
102 typename boost::property_traits< WeightMap >::value_type >() );
106 explicit FromBGL( BG & g )
107 requires std::is_void_v< WeightMap >
108 : f_g( &g ) , f_i( get( boost::vertex_index , g ) ) {
114 FromBGL( BG & g , WeightMap w )
115 requires( ! std::is_void_v< WeightMap > )
116 : f_g( &g ) , f_i( get( boost::vertex_index , g ) ) , f_w( w ) {
121 [[nodiscard]]
const BG & graph(
void )
const {
return( *f_g ); }
124 [[nodiscard]]
bool directed(
void )
const {
125 return( boost::is_directed( *f_g ) );
129 [[nodiscard]]
int n(
void )
const {
return( f_n ); }
132 [[nodiscard]]
int bound(
void )
const {
return(
int( f_v.size() ) ); }
135 [[nodiscard]]
bool hasNode(
int u )
const {
136 return( ( u >= 0 ) && ( u < bound() ) && ! f_dead[ std::size_t( u ) ] );
140 [[nodiscard]] std::vector< int > V(
void )
const {
141 std::vector< int > r;
142 r.reserve( std::size_t( f_n ) );
143 for(
int u = 0 ; u < bound() ; ++u )
144 if( ! f_dead[ std::size_t( u ) ] )
152 void forEachAdj(
int u , F && f )
const {
154 for(
auto [ b , e ] = out_edges( f_v[ std::size_t( u ) ] , *f_g ) ; b != e ;
156 f(
int( get( f_i , target( *b , *f_g ) ) ) );
162 void forEachEdge(
int u , F && f )
const
163 requires( ! std::is_void_v< WeightMap > )
166 for(
auto [ b , e ] = out_edges( f_v[ std::size_t( u ) ] , *f_g ) ; b != e ;
168 f(
int( get( f_i , target( *b , *f_g ) ) ) , Weight( get( f_w , *b ) ) );
173 [[nodiscard]] std::vector< int > adj(
int u )
const {
174 std::vector< int > r;
175 forEachAdj( u , [ & ](
int v ) { r.push_back( v ); } );
181 [[nodiscard]] std::optional< Weight > weight(
int u ,
int v )
const {
182 if( ! hasNode( u ) || ! hasNode( v ) )
183 return( std::nullopt );
184 const auto [ e , there ] =
185 edge( f_v[ std::size_t( u ) ] , f_v[ std::size_t( v ) ] , *f_g );
187 return( std::nullopt );
188 if constexpr( std::is_void_v< WeightMap > )
191 return( Weight( get( f_w , e ) ) );
195 int insertNode(
void )
198 const Vertex x = add_vertex( *f_g );
200 f_dead.push_back(
false );
202 return(
int( get( f_i , x ) ) );
208 void insertEdge(
int u ,
int v ,
const Weight & w = Weight() )
211 ADS_PRE( hasNode( u ) && hasNode( v ) && ( u != v ) );
212 const Vertex x = f_v[ std::size_t( u ) ] , y = f_v[ std::size_t( v ) ];
213 auto [ e , there ] = edge( x , y , *f_g );
215 e = add_edge( x , y , *f_g ).first;
216 if constexpr( ! std::is_void_v< WeightMap > )
225 void deleteEdge(
int u ,
int v )
228 ADS_PRE( hasNode( u ) && hasNode( v ) );
229 remove_edge( f_v[ std::size_t( u ) ] , f_v[ std::size_t( v ) ] , *f_g );
235 void deleteNode(
int u )
239 clear_vertex( f_v[ std::size_t( u ) ] , *f_g );
240 f_dead[ std::size_t( u ) ] =
true;
248 const auto n = std::size_t( num_vertices( *f_g ) );
250 f_dead.assign( n ,
false );
252 for(
auto [ b , e ] = vertices( *f_g ) ; b != e ; ++b )
253 f_v[ std::size_t( get( f_i , *b ) ) ] = *b;
259 std::vector< Vertex > f_v;
260 std::vector< bool > f_dead;
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
The GRAPH of chapter 9 and its realizations.
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81