src/VertexColoring.Algorithms/ColoringExtensions.cs
/// <summary>
/// Optimizes color weights by grouping vertices by color, ordering the groups by count,
/// and assigning colors in rising order to groups of vertices as ordered,
/// so that the largest group has the smallest color.
/// </summary>
/// <param name="coloring">Coloring to be optimized.</param>
/// <returns>A new, optimized coloring (new instance).</returns>
Optimizes color weights by grouping vertices by color, ordering the groups by count,
and assigning colors in rising order to groups of vertices as ordered,
so that the largest group has the smallest color.
Optimizes color weights by grouping vertices by color ordering the groups by count and assigning colors in rising order to groups of vertices as ordered so that the largest group has the smallest color .
public static GraphColoring OptimizeByWeighting(this GraphColoring coloring)
        {
            var colors = coloring.VertexColors
                .GroupBy(p => p.Value, p => p.Key)
                .Select(g => (group: g, count: g.Count()))
                .OrderByDescending(t => t.count)
                .SelectMany((t, i) => t.group.Select(v => (vertex: v, color: i + 1)))
                .ToImmutableSortedDictionary(t => t.vertex, t => t.color);
            return new GraphColoring(coloring.Graph, colors);
        }
public static GraphColoring OptimizeByWeighting ( this GraphColoring coloring ) { var colors = coloring . VertexColors . GroupBy ( p => p . Value , p => p . Key ) . Select ( g => ( group : g , count : g . Count ( ) ) ) . OrderByDescending ( t => t . count ) . SelectMany ( ( t , i ) => t . group . Select ( v => ( vertex : v , color : i + 1 ) ) ) . ToImmutableSortedDictionary ( t => t . vertex , t => t . color ) ; return new GraphColoring ( coloring . Graph , colors ) ; }
Optimizes color weights by grouping vertices by color, ordering the groups by count,
and assigning colors in rising order to groups of vertices as ordered,
so that the largest group has the smallest color.
Optimizes color weights by grouping vertices by color ordering the groups by count and assigning colors in rising order to groups of vertices as ordered so that the largest group has the smallest color .
A new, optimized coloring (new instance).
A new optimized coloring ( new instance ) .
GraphColoring
this
coloring
Coloring to be optimized.
Coloring to be optimized .