Hi Robert, just an FYI that sage-support is probably a place where more 
people will see questions of this kind.  Good luck!

On Wednesday, March 19, 2014 3:16:18 PM UTC-4, Robert wrote:
>
> I have a graph defined as a dictionary: 
>
> {0: [19, 8, 11], 1: [18, 19, 8, 14, 15], 2: [16, 18, 4, 10, 11, 13], 3: 
> [6, 13, 15], 4: [2, 19, 13], 5: [11], 6: [16, 3, 9], 7: [18, 9, 12, 14], 8: 
> [0, 16, 1, 19, 12], 9: [16, 17, 19, 6, 7, 11], 10: [17, 2, 18], 11: [0, 2, 
> 5, 9], 12: [7, 8, 14], 13: [2, 18, 3, 4], 14: [1, 7, 12], 15: [1, 3, 19], 
> 16: [2, 18, 19, 6, 8, 9], 17: [9, 10], 18: [16, 1, 2, 7, 10, 13], 19: [0, 
> 16, 1, 4, 8, 9, 15]}
>
> Pardon the large input here. The thing to note is that the lists following 
> each key are not sorted. When I ask Sage to do a breadth first search of 
> this graph starting from vertex 0 
> (syntax: list(g.breadth_first_search(0))), I get: 
>
> [0, 19, 8, 11, 16, 1, 4, 9, 15, 12, 2, 5, 18, 6, 14, 13, 17, 7, 3, 10]
>
>
> I.e. Sage is performing the BFS in the order in which the vertices appear 
> in the lists, rather than in numerical order. I want the BFS to be done in 
> numerical order on neighbors. I tried this: 
>
> for key in dict:
>     dict[key] = sorted(dict[key])
>

Can you try using the "neighbors" keyword with something?

sage: list(G.breadth_first_search(0,neighbors=lambda x: 
sorted(G.neighbors(x))))
[0, 8, 11, 19, 1, 12, 16, 2, 5, 9, 4, 15, 14, 18, 7, 6, 10, 13, 17, 3]

Sorry for having to use the lambda function.  I'm not sure there is a 
better way to do it.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-edu.
For more options, visit https://groups.google.com/d/optout.

Reply via email to