/// <summary>
        /// Saves given <paramref name="coloring"/> into <paramref name="writer"/> in TGF-like text representation.
        /// The color of each vertex is saved as a second number, after vertex id. So a vertex with id=1, label=sth
        /// colored with number 132 will be saved in TGF vertex list as "1 132 sth".
        /// </summary>
        /// <param name="writer">Writer to save coloring to.</param>
        /// <param name="graph">Coloring to be saved.</param>
        public static void WriteColoringAsTgf(this TextWriter writer, GraphColoring coloring)
        {
            var graph = coloring.Graph;

            foreach (var vertex in graph.Vertices)
            {
                writer.WriteLine($"{vertex.Id} {coloring[vertex]} {vertex.Label}");
            }
            writer.WriteLine("#");
            foreach (var edge in graph.Edges)
            {
                writer.WriteLine(edge.ToString());
            }
        }
예제 #2
0
 /// <summary>
 /// Calculates count of unique colors used in <paramref name="coloring"/>.
 /// </summary>
 /// <param name="coloring">Coloring to count colors in.</param>
 /// <returns>Count of unique colors.</returns>
 public static int ColorsUsed(this GraphColoring coloring)
 {
     return(coloring.VertexColors.Values.Distinct().Count());
 }