Guest User

Untitled

a guest
Dec 12th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. int ChromaticNumber(Graph G)
  2. {
  3. for (int i = 0; i < G.Vertices.size(); ++i)
  4. {
  5. //initialize vertex color to 1
  6. ++G.Vertices[i].Color;
  7. bool Match = true;
  8.  
  9. //loop while there is an adjacent vertex with the same color
  10. while (Match)
  11. {
  12. Match = false;
  13. for (int j = 0; j < G.Vertices[i].Edges.size(); ++j)
  14. {
  15. //get adjacent vertex
  16. int AdjacentVertex = G.Vertices[i].Edges[j];
  17.  
  18. //if an adjacent vertex has the same color, increment the
  19. //current vertex's color
  20. if (G.Vertices[i].Color == G.Vertices[AdjacentVertex].Color)
  21. {
  22. ++G.Vertices[i].Color;
  23. Match = true;
  24. }
  25. }
  26. }
  27. }
  28.  
  29. int MaxColor = 0;
  30.  
  31. //loop to determine the largest color value
  32. for (int i = 0; i < G.Vertices.size(); ++i)
  33. if (G.Vertices[i].Color > MaxColor)
  34. MaxColor = G.Vertices[i].Color;
  35.  
  36. return MaxColor;
  37. }
Add Comment
Please, Sign In to add comment