Boost logo

Boost :

Subject: Re: [boost] [SoC] BGL project idea
From: Eric Wolf (eric_at_[hidden])
Date: 2010-07-15 15:38:28


Dear Jeremiah,

thanks for the fast response.

1) I'll give some general clarifications on the algorithm, then
2) I want to talk (read/write) about how to implement it and your
   very valueable suggestions.

1) First of all some clarification (i'm not sure you need
them though :) )

Jeremiah Willcock <jewillco_at_[hidden]> writes:
> On Wed, 14 Jul 2010, Eric Wolf wrote:
>> Jeremiah Willcock <jewillco_at_[hidden]> writes:
>>>>> Why are you computing the transitive closure explicitly when it is not
>>>>> part of the algorithm's documented output? It there a reason that you
>>>>> can't use the SCC structure (and the connections between them)
>>>>> directly to compute the reduction without storing the full closure?
>>> Is there a reason you're not using the current transitive_closure
>>> algorithm in BGL?

An already computed transitive closure can't be used, as there is a need
to compute it in all cases, as some times it must be checked, whether an
edge is already in the to be computed closure.

>> I will modify transitive_closure from Vladimir Prus and use
>> successor sets. This will give better time complexity and better
>> memory usage.

So the transitive closure is stored in the successor sets in what
I imagine to be the next version of transitive_reduction.hpp. No
explicit transitive closure needed any more.

I cite some text, which would came later in your email:

> If I understand correctly, though, you always need
> to make some kind of transitive closure graph internally, even if the
> user doesn't want it;

Correct. Thats what I will use successor sets for in my next imagined
version.

> I don't remember if that was just for the condensation graph or if it
> was a transitive closure of the whole input graph.

Just for the condensation graph.

> You also need an explicit condensation graph as temporary storage for
> doing the reduction, too, or am I mistaken?

I'm not sure about this. The transitive_reduction of the condensation
graph is only touched to insert edges. It is not read in the “core“
algorithm. It is needed, to construct the transitive_reduction of the
original graph I think. (If the reduction of the original graph is
stored as an explicit graph, or if I write vertex pairs to an output
iterator isn't important though.)

2) Now I answer the other points in your response:

> OK. Please try to contribute that as a separate algorithm so other
> people can use it as well.

Ehh ... I don't understand, what you mean. A separate algorithm to the
previous version? Who would want the previous version (of
transitive_reduction)?

>>>>> Why are there functions that do the transitive closure as well as the
>>>>> reduction? Is having both of them a common use case? It appears that
>>>>> there is a lot of redundant code between the reduction-with-closure
>>>>> and reduction-only functions.
>>>>
>>>> It's the same algorithm. The algorithm for computing the closure and the
>>>> reduction is essentially the same. So you could have the other one for
>>>> free if you generate one of them. I doubt that it is a common use case,
>>>> I admit, but I thought one should have the possibility to get both in
>>>> one run, if its for free. So the reduction-with-closure and
>>>> reduction-only functions are essentially duplicates of each other.
>>>
>>> OK. Is there a way to factor out the common code?
>>
>> ** long lines below **
>>
>> Several ways to accomplish that come to my mind, but I'm unsure which
>> route to go and ask you for some advice.
>
> The closure and reduction will always have the same number of vertices
> as the original graph, right?

yes

> They just add or remove some edges, if I understand correctly.

yes

> What if you didn't output a graph at all, just a list of edges (pairs
> of vertices, since the edge may not exist in the original graph)?
> Then a user could easily ignore the list, or feed it back into a graph
> class's constructor to create a result graph. You could then use
> named parameters and make the default be to ignore the outputs.

That's a great idea. But I couldn't get the grasp of bgl named
parameters until now. I thought bgl would use the boost::parameter
library, but in my perception the documentation and what's done in
named_parameters.hpp don't fit.

> If I understand correctly, though, you always need to make some kind
> of transitive closure graph internally, even if the user doesn't want
> it; I don't remember if that was just for the condensation graph or if
> it was a transitive closure of the whole input graph. You also need
> an explicit condensation graph as temporary storage for doing the
> reduction, too, or am I mistaken?

The reduction could be easily written to an output iterator I imagine,
but the computation of the transitive closure of the condensation graph
must be done in all cases and stored somehow. Now in the successor sets.

> So here are some other options I've thought of; if some of the stuff I
> wrote in this paragraph is wrong, that might change which ones are
> possible.
>
> 1 (easy). Accept an Output Iterator that will get the reduction as a
> list of edges, built using the vertices from the original graph. Do
> the same for the closure. Use named parameters to make both of these
> outputs ignored by default, but they can also be used to create new
> graphs.

Even it the reduction is not used or wanted by the user, it still would
be computed from the reduction of the condensation graph. But maybe it
is an accepable annoyance?

> 2 (harder, but not because of template tricks). Create two
> semi-implicit graphs, one for the closure and one for the reduction;
> return both from your algorithm. In this case, your graphs would only
> store a map from each vertex to its component (i.e., vertex in the
> condensation graph), which vertex is the representative of its
> component (for reductions), and the condensation graph (either its
> closure or reduction). You would then need to do the reduction even
> if the user doesn't need it, but you would not need to store the
> reduction or closure of anything but the condensation graph. You
> could also just have two variants of the algorithm, one that creates
> the condensation graph and its transitive closure, and another that
> creates both the condensation graph, its closure, and its reduction.
> That will likely save you code still, and named parameters can be used
> to determine in one function whether the reduction is necessary to
> compute (and this can probably be done with a run-time if statement on
> a property of a template argument, without needing any fancy
> metaprogramming beyond type_traits).

And a two functions to construct the reduction and the closure from
the cond.gr.rd. and the cond.gr.cl. and the mappings. Yeah, thats a
possible way.

> Your options:
>
>> 1) Define a Graph type which absorbs all add_vertex and add_edge
>> operations like /dev/null in unix, then write one implementation
>> function like ...
>
> I don't like this option because I don't think the reduction can be
> removed completely, since I believe you need an explicit graph for the
> reduction when you are computing (you use already filled-in parts of
> it to create other parts, right?).

Nope. The reduction of the condensation graph is only written, not read
in the core algorithm. It gets read if one tries to build the transitive
reduction of the whole graph.

But I don't like that option, too. It is ugly.

>> 2) Use boost::enable_if like that: (In the following ... denotes an
>> ellipsis of zero or more parameters, not varargs.) ...
>
> This option is feasible and probably easier than you think it is;
> named parameters will take care of the dispatching, so you probably
> won't need enable_if.

If you think it is feasible, then I would like to take that route. One
remedy still remains in my perception. If the user doesn't want the
transitive reduction, an unused local variable remains in the main
implementation function ...

Can that be removed somehow by fancy template stuff?

What's your favorite choice?

Yours,

Eric


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk