src/VertexColoring.Algorithms/ColoringExtensions.cs
/// <summary>
/// Colors graph vertices greedily processing them in order of <paramref name="verticesOrdered"/>.
/// </summary>
/// <param name="graph">Graph to be colored.</param>
/// <param name="verticesOrdered">Ordering of graph vertices to use in algorithm.</param>
/// <param name="adjacency"><paramref name="graph"/> adjacency to save calculations
/// when doing multiple colorings.</param>
/// <returns>Vertex coloring of provided graph.</returns>
Colors graph vertices greedily processing them in order of .
Colors graph vertices greedily processing them in order of .
public static GraphColoring ColorGreedilyWithVertexOrder(this Graph graph, IEnumerable<Vertex> verticesOrdered,
            VertexAdjacency adjacency)
        {
            var maxDegree = adjacency.AdjacentVertices.Max(p => p.Value.Count);
            var colors = Enumerable.Range(1, maxDegree + 2);
            var coloring = new MutableGraphColoring(graph);
            foreach (var vertex in verticesOrdered)
            {
                var adjacentVertices = adjacency.AdjacentVertices[vertex];
                var usedColors = adjacentVertices.Select(v => coloring[v]).Where(c => c != null).Select(c => c.Value);
                var color = colors.Except(usedColors).First();
                coloring[vertex] = color;
            }
            return coloring.ToImmutable();
        }
public static GraphColoring ColorGreedilyWithVertexOrder ( this Graph graph , IEnumerable < Vertex > verticesOrdered , VertexAdjacency adjacency ) { var maxDegree = adjacency . AdjacentVertices . Max ( p => p . Value . Count ) ; var colors = Enumerable . Range ( 1 , maxDegree + 2 ) ; var coloring = new MutableGraphColoring ( graph ) ; foreach ( var vertex in verticesOrdered ) { var adjacentVertices = adjacency . AdjacentVertices [ vertex ] ; var usedColors = adjacentVertices . Select ( v => coloring [ v ] ) . Where ( c => c != null ) . Select ( c => c . Value ) ; var color = colors . Except ( usedColors ) . First ( ) ; coloring [ vertex ] = color ; } return coloring . ToImmutable ( ) ; }
Colors graph vertices greedily processing them in order of .
Colors graph vertices greedily processing them in order of .
Vertex coloring of provided graph.
Vertex coloring of provided graph .
Graph
this
verticesOrdered
IEnumerable<Vertex>
Ordering of graph vertices to use in algorithm.
Ordering of graph vertices to use in algorithm .
adjacency
VertexAdjacency
adjacency to save calculations
when doing multiple colorings.
adjacency to save calculations when doing multiple colorings .
graph
Graph to be colored.
Graph to be colored .