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])

and then redefining the graph with the new, sorted-values dictionary but I 
get the same BFS results. How can I convince Sage to perform the BFS by 
going through neighbors in numerical order? 

This is sort of important because I have 60 papers to grade with four graph 
searches each and if Sage can't automate the process then this will be a 
major PITA. Thanks, rt

-- 
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 sage-edu+unsubscr...@googlegroups.com.
To post to this group, send email to sage-edu@googlegroups.com.
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