Guest User

Untitled

a guest
Mar 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. ︠from sage.graphs.graph_coloring import vertex_coloring
  2.  
  3. # This is the list of English actors in the order they appear
  4. english_actor_sequence = [
  5. 1, 2, 3, 1, 5, 4, 2, 6, 1, 3,
  6. 2, 9, 6, 3, 10, 11, 3, 2, 12, 1,
  7. 13, 14, 12, 2, 7, 6, 1, 13, 11, 5,
  8. 13, 15, 7, 12, 10, 16, 17, 2, 3, 6,
  9. 12, 17, 15, 5, 4, 13, 2, 7, 1, 14,
  10. 10, 15, 9, 4, 2]
  11.  
  12. # Two French actors cannot take roles of English actors in consecutive scenes
  13. actor_pairs = [(english_actor_sequence[i],english_actor_sequence[i+1]) for i in range(len(english_actor_sequence) - 1)]
  14.  
  15. # Create a graph where the English actors are nodes, the edges are whether two English actors are in consecutive scenes
  16. # Multiedges are not needed
  17. scene_graph = Graph(actor_pairs, multiedges=False)
  18.  
  19. # Show the graph before colouring
  20. scene_graph.graphplot(layout='circular').show(figsize=[6,6])
  21.  
  22. # Display the info
  23. print 'You need %d French actors.' % vertex_coloring(scene_graph, value_only=True)
  24. print 'These are the English roles the French actors will take: '
  25. for i in range(vertex_coloring(scene_graph, value_only=True)):
  26. print 'French actor %d will play the parts: ' % (i+1)
  27. print vertex_coloring(scene_graph)[i]
  28.  
  29. #Show the coloured graph
  30. scene_graph.graphplot(layout='circular', partition=vertex_coloring(scene_graph)).show(figsize=[6,6])
Add Comment
Please, Sign In to add comment