How to get a graph that does not accept parallel edges?
How do I declare a graph that does not allow parallel edges?
I have come up with this but IMO it is sort of, well, kludgey:
typedef adjacency_list
Hi Eric,
2006/9/8, Eric Fowler
How do I declare a graph that does not allow parallel edges? I have come up with this but IMO it is sort of, well, kludgey:
typedef adjacency_list
Graph; This works because std::set does not like multiple entries.
Quoting adjacency_list documentation: "One of the first things to consider when choosing the OutEdgeList is whether you want adjacency_list to enforce the absence of parallel edges in the graph (that is, enforce that the graph not become a multi-graph). If you want this enforced then use the setS or hash_setS selectors. If you want to represent a multi-graph, or know that you will not be inserting parallel edges into the graph, then choose one of the Sequence types: vecS, listS, or slistS."
But what if for performance reasons (say) I want a listS or vecS instead of setS?
To me it looks like there is no special check inside adjacency_list for parallel edges. The check is only done through the underlying container. So if you want to use listS or vecS as an outedge-container, you have to check for parallel edges yourself.
In adjacency_list.hpp I find: template <> struct parallel_edge_traits<setS> { typedef disallow_parallel_edge_tag type; };
Which suggest the existence of a more elegant mechanism. Anybody know what that is?
For me, this validates the above assumption. This tag is set through specializing on the OutEdgeList container. HTH, Stephan
On Thu, 7 Sep 2006, Eric Fowler wrote:
How do I declare a graph that does not allow parallel edges?
I have come up with this but IMO it is sort of, well, kludgey:
typedef adjacency_list
Graph; This works because std::set does not like multiple entries.
But what if for performance reasons (say) I want a listS or vecS instead of setS?
In adjacency_list.hpp I find: template <> struct parallel_edge_traits<setS> { typedef disallow_parallel_edge_tag type; };
Which suggest the existence of a more elegant mechanism.
Anybody know what that is?
You could write a wrapper around std::vector or std::list that enforces unicity of it's elements, create a tag (e.g. my_tagS) for it and then a few thins like this: struct my_tagS {} ; template < typename ValueType > class my_container { // ... } ; namespace boost { template < typename ValueType > struct container_gen< my_tagS , ValueType > { typedef my_container< ValueType > type ; } ; template <> struct parallel_edge_traits< my_tagS > { typedef disallow_parallel_edge_tag type ; } ; } I have never tried it, though, so no guaranty it will work out. -- François Duranleau LIGUM, Université de Montréal "Any sufficiently advanced technology is indistinguishable from magic" - Arthur C. Clarke _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Eric Fowler
-
François Duranleau
-
Stephan Diederich