Пример #1
0
        /// <summary>
        /// Finds a coloring for each node in a list of graphs.
        /// </summary>
        /// <param name="graphs">The graphs to color in.</param>
        /// <returns>A mapping from node to category (color).</returns>
        public static IDictionary <Node, int> FindColoring(IList <Graph> graphs)
        {
            var union = new Graph(graphs[0].IsDirected);

            for (int i = 0; i < graphs.Count; i++)
            {
                union.DisjointUnionWith(graphs[i], i + "_", false);
            }

            var refinement = new ColorRefinement(union);

            refinement.RefinePartitioning();

            var newAssignment = new Dictionary <Node, int>();

            foreach (var entry in refinement.ColorAssignment)
            {
                string nodeName = entry.Key.Name;

                int    index      = nodeName.IndexOf('_');
                int    graphIndex = int.Parse(nodeName.Remove(index));
                string actualName = nodeName.Substring(index + 1);

                newAssignment[graphs[graphIndex].Nodes[actualName]] = entry.Value;
            }

            return(newAssignment);
        }
Пример #2
0
        /// <summary>
        /// Finds a coloring for each node in a graph.
        /// </summary>
        /// <param name="graph">The graph to color in.</param>
        /// <returns>A mapping from node to category (color).</returns>
        public static IDictionary <Node, int> FindColoring(Graph graph)
        {
            var refinement = new ColorRefinement(graph);

            refinement.RefinePartitioning();
            return(refinement.ColorAssignment);
        }