How to test whether a vertex or edge exists?
I want to add a vertex, which a string as its ID to a graph if a vertex
representing such a string does not exist in the graph. Is there a function
call to test if a vertex exists in a graph?
-----------------------------------------------------------------------
//Here is the simpilfied situation that I want to handle, "IF THERE IS NOT
a vertex representing the //string of the current line" is the predicate I
want to know
typedef adjacency_list
On Saturday 06 May 2006 22:49, sean yang wrote:
I want to add a vertex, which a string as its ID to a graph if a vertex representing such a string does not exist in the graph. Is there a function call to test if a vertex exists in a graph?
I don't think there's any particularly efficient way of doing that. Could you
first read the strings into a set and then create vertices based on what's in
the set?
There isn't a function to test if a vertex is in a graph because it isn't
needed. The only way to get a vertex is to dereference a vertex_iterator, and
obviously such a vertex *is* in the graph. Except for default construction,
there isn't even a general way to construct a vertex. How could there be?
Vertex descriptors are required to be default constructible, assignable, and
equality comparable, but beyond that their representation is arbitrary, so
there's no way for a generic algorithm to create one.
Having said that, it is possible for any particular graph class to provide a
method for creating valid vertices, and adjacency_list provides the function
vertex( n, g ), which returns the nth vertex in g. I haven't read the source
for this function, but I assume that if n is out of range it does something
reasonable like return graph_traits
A related question I want to ask is whether there exist a function call that test whether an edge representing [vertext string("Node1") --> vertext string("Node2") ] exists in a graph.
There's a function edge( u, v, g ) returns the edge between u and v, if it exists. This function is required by the AdjacencyMatrix concept. D.
From: Daniel Mitchell
Reply-To: boost-users@lists.boost.org
Yeah, I agree with you. For the first question, I think I'd better to save the strings to an vector and build a relationship between strings in this vector and vertices in the graph.
A related question I want to ask is whether there exist a function call that test whether an edge representing [vertext string("Node1") --> vertext string("Node2") ] exists in a graph.
There's a function edge( u, v, g ) returns the edge between u and v, if it exists. This function is required by the AdjacencyMatrix concept. Thanks for the reply. I have a question for concept requirements. For example, if I declare a Graph representation by typedef adjacency_list
, property > Graph;
How can I know if this Graph satisfies the reqirement of a certain concept, say AdjacencyMatrix ? Thanks again.
D. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_________________________________________________________________ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/
On Sunday 07 May 2006 17:09, sean yang wrote:
Yeah, I agree with you. For the first question, I think I'd better to save the strings to an vector and build a relationship between strings in this vector and vertices in the graph.
I think that's a reasonable approach. I suggested a set since it would automatically take care of the problem of duplicates, but you obviously know your application better than I do.
Thanks for the reply. I have a question for concept requirements. For example, if I declare a Graph representation by typedef adjacency_list
, property > Graph; How can I know if this Graph satisfies the reqirement of a certain concept, say AdjacencyMatrix ?
The answer is slightly complex because of the nature of concepts. A concept is
a set of syntactic and semantic requirements a type must satisfy to qualify
as an argument to a generic function. For example, if objects of type Graph
are to qualify as arguments to a function that requires the AdjacencyMatrix
concept, the expression edge( u, v, g ) must compile. This can obviously be
checked by the compiler, and the BGL makes it easy to do so:
#include
participants (2)
-
Daniel Mitchell
-
sean yang