Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange result with FindShortestPath and Tuple

9 views
Skip to first unread message

Julian Francis

unread,
May 10, 2011, 8:32:50 AM5/10/11
to
Dear all,

I am getting a very confusing result when using Tuple to build a list
of vertices to be used as input to Graph (and eventually
FindShortestPath). However, when I use Table to build the list of
vertices, it all works fine. But the output of Tuple and Table produce
identical expressions, so why would one work and not the other? A
simple example may illustrate what I mean more clearly:

In[1]:= vertices1 = Tuples[{Range[2], Range[2]}]

Out[1]= {{1, 1}, {1, 2}, {2, 1}, {2, 2}}

In[2]:= vertices2 = Flatten[Table[{x, y}, {x, 1, 2}, {y, 1, 2}], 1]

Out[2]= {{1, 1}, {1, 2}, {2, 1}, {2, 2}}

In[3]:= vertices1 === vertices2

Out[3]= True

In[8]:= FindShortestPath[
Graph[vertices1, {{1, 1} \[DirectedEdge] {2, 1}},
VertexLabels -> "Name"], {1, 1}, {2, 1}]

Out[8]= {1, 1}

In[9]:= FindShortestPath[
Graph[vertices2, {{1, 1} \[DirectedEdge] {2, 1}},
VertexLabels -> "Name"], {1, 1}, {2, 1}]

Out[9]= {{1, 1}, {2, 1}}

I was expecting the last two expressions to be the same (with the last
one being the correct one). Why the difference?

Any help would be greatly appreciated.

Thanks,
Julian Francis.

Szabolcs Horvát

unread,
May 11, 2011, 4:25:58 AM5/11/11
to

I believe this is a bug.

I'm replying just to mention that the difference between vertices1 and
vertices2 is that vertices1 is a packed array:

Developer`PackedArrayQ[vertices1]

gives True.

Oliver Ruebenkoenig

unread,
May 12, 2011, 4:33:00 AM5/12/11
to

I reported it as bug. Thanks.

Oliver

Julian Francis

unread,
May 31, 2011, 7:54:01 AM5/31/11
to
Dear Oliver & Szabolcs,

Thanks for both of your replies. Let's hope it gets fixed in the next
Mathematica release.

Thanks & kind regards,
Julian.


On May 12, 9:33 am, Oliver Ruebenkoenig <ruebe...@wolfram.com> wrote:
> On Wed, 11 May 2011, Szabolcs Horv=E1t wrote:
> > On 2011.05.10. 14:32, JulianFranciswrote:
> >> Dear all,
>
> >> I am getting a very confusing result when using Tuple to build a list
> >> of vertices to be used as input to Graph (and eventually
> >> FindShortestPath). However, when I use Table to build the list of
> >> vertices, it all works fine. But the output of Tuple and Table produce
> >> identical expressions, so why would one work and not the other? A
> >> simple example may illustrate what I mean more clearly:
>
> >> In[1]:= vertices1 = Tuples[{Range[2], Range[2]}]
>
> >> Out[1]= {{1, 1}, {1, 2}, {2, 1}, {2, 2}}
>

> >> In[2]:= vertices2 = Flatten[Table[{x, y}, {x, 1, 2}, {y, 1, 2}], 1=

0 new messages