# Boost Users :

Subject: Re: [Boost-users] [BGL] Shared nodes on path
From: Aaron Windsor (aaron.windsor_at_[hidden])
Date: 2014-02-27 12:11:33

Hi,

As described, your problem is NP-hard, which means that if you were to find
a way to solve it in polynomial time in the number of vertices in the
graph, you'd also be able to solve a lot of other hard problems that
nobody's ever been able to solve in polynomial time. For example, given an
algorithm that solves your problem, you could use that algorithm to find
Hamiltonian paths in graphs: for any graph G with n vertices, just run the
algorithm on that graph and the path (u, x_0, ..., x_{n-2}, v), where the
x_i's are vertices not appearing in G (or, say, isolated vertices in G) and
u and v are two vertices from G. If the algorithm outputs a path, it's a
path of length n-1 and thus Hamiltonian.

In addition, there can easily be an exponential number of paths output by
such an algorithm, so even if you could find an efficient algorithm, once
you reach graphs with on the order of hundreds of nodes, there's no
guarantee that you have enough space to store the results or time to read
them.

Maybe there are some additional constraints on your actual problem or the
graphs you're dealing with that make it simpler than what you've described
above? If so, those would be good to know. If not, and you still want to
write an algorithm to do this, I'd suggest that you don't try to do
anything fancy with the BGL. Your best bet will just enumerating through
all candidate paths of the appropriate length and checking if the candidate
is an actual path in G.

-Aaron

On Thu, Feb 27, 2014 at 3:40 AM, Sensei <senseiwa_at_[hidden]> wrote:

> Dear all,
>
> I have a simple question about the most efficient way of finding shared
> nodes between a path and a graph. Let me be more explicit.
>
> I have an oriented graph G, and a very simple graph P, which is actually a
> simple oriented path (n0 -> n1 -> ... -> nK). I need to find *all* the
> possible shared paths between P and G with the same length as P.
>
> For instance, being
>
> P = n1 -> n2 -> n3 -> n4 -> n5 -> n6
>
> we may find that the G and P share only two sub-paths
>
> n1 -> n2 -> n3
> n5 -> n6
>
> I'd like to find all sub-graphs that connect the two paths, for instance
> having
>
> n1 -> n2 -> n3 -> n10 -> n5 -> n6
> n1 -> n2 -> n3 -> n42 -> n5 -> n6
>
> with the constraint that the solution must be a path with the same length
> as P, therefore a solution as these
>
> n1 -> n2 -> n3 -> n9 -> n8 -> n5 -> n6
> n1 -> n2 -> n3 -> n5 -> n6
>
> would not be acceptable.
>
> I know I can do it manually, but I think a BGL-aware solution is quite
> better that a manual search :)
>
> Thanks & Cheers!
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

>