Re: [Boost-users] Graph Library - bundled properties, internal & external properties
Hello again,
Second, with bundled properties I have troubles with constructors. I created a class myClass, that I will use as a struct for the bundled properties. This class contains reference members so it needs a constructor better than the default constructor without any arguments. Creating a graph with these bundled properties doesn't allow me to use another constructor than the default myClass() one, it seems. I think it would be very good if I could create an array of myClass and then point my Graph object to this array to use it as bundled properties. Then I could do all the initialization I want cleanly.
I think that when you add an edge or vertex, you can just pass a myClass instance before the graph argument, e.g,,
v = add_vertex(myClass(some_reference), g);
Ok, so that would solve one of my problems. Thank you.
My last problem is with the depth_first_search() algorithm... and of course bundled properties. This algorithm takes a const Graph &; but I want to be able to modify (while running the algorithm) the bundled properties!! That is the whole point of running this algorithm. I don't want to change the structure of the graph (the abstract graph - links from vertices to edges, etc), while running the algorithm, of course, but I do want to change when I want my bundled properties... that is not possible (at least, not without compiler warnings, which I don't like :-) due to the fact that depth_first_search expects a const graph.
Yeah, this is an annoying problem. We'd like to be able to take either a const or a non-const graph, but doing so would require two overloads of the algorithm, which we really can't do (too much code!).
Like someone else pointed out, what do you mean by too much code? It would require too much time? Or would it be considered a problem for more "fundamental" reasons (ie, that could lead to trouble in existing code, etc...)?
I suggest that you put a non-const reference to the graph from within your visitor and use that instead of the graph that is passed to the event functions.
I am not sure I understand how you would do that... Am I correct in understanding that you would declare a non const reference as a member in your visitor? And then you would have to pass the Graph object when you create the visitor. That means a visitor would be suitable for only one graph (that is not a problem in my case, just a remark) on which you intend to use the visitor on. Another way would be to use pointers to objects as bundled properties, instead of directly the object themselves. I think that should work and that's what I am using right now. Basically it only changes that in your visitor, it's not g[v].some_member = 4; but g[v]->some_member = 4; (if g is the graph). Seems to work fine. Jean-Noël
On Mar 11, 2005, at 6:28 PM, Elvanör wrote:
My last problem is with the depth_first_search() algorithm... and of course bundled properties. This algorithm takes a const Graph &; but I want to be able to modify (while running the algorithm) the bundled properties!! That is the whole point of running this algorithm. I don't want to change the structure of the graph (the abstract graph - links from vertices to edges, etc), while running the algorithm, of course, but I do want to change when I want my bundled properties... that is not possible (at least, not without compiler warnings, which I don't like :-) due to the fact that depth_first_search expects a const graph.
Yeah, this is an annoying problem. We'd like to be able to take either a const or a non-const graph, but doing so would require two overloads of the algorithm, which we really can't do (too much code!).
Like someone else pointed out, what do you mean by too much code? It would require too much time? Or would it be considered a problem for more "fundamental" reasons (ie, that could lead to trouble in existing code, etc...)?
Oops, the reply I'd sent never made it out of the outbox. It should show up before this message...
I suggest that you put a non-const reference to the graph from within your visitor and use that instead of the graph that is passed to the event functions.
I am not sure I understand how you would do that... Am I correct in understanding that you would declare a non const reference as a member in your visitor?
Yes.
And then you would have to pass the Graph object when you create the visitor. That means a visitor would be suitable for only one graph (that is not a problem in my case, just a remark) on which you intend to use the visitor on.
Yes, unfortunately.
Another way would be to use pointers to objects as bundled properties, instead of directly the object themselves. I think that should work and that's what I am using right now.
Basically it only changes that in your visitor, it's not g[v].some_member = 4; but g[v]->some_member = 4; (if g is the graph).
Seems to work fine.
Sure, that'll work. I would typically try to avoid doing that, if only because I wouldn't want to have to deal with allocating/deallocating the pointers. One other alternative would be to const_cast the graph that the visitor gets. It's ugly, but it will work. Doug
participants (2)
-
Douglas Gregor
-
Elvanör