Ejemplo n.º 1
0
        public void Color()
        {
            // Variable
            Graph.IVertexInterface        vertex;
            List <Graph.IVertexInterface> neighboursVertexList;

            if (coloredGraph.GetIsInitializedColoredGraph())
            {
                throw new MyException.GraphException.ColoredGraphAlreadyInitializedException();
            }

            coloredGraph.ResetColors();

            while (!graph.GetColoredGraph().AreAllVerticesColored())
            {
                copyGraph = Graph.GraphOperation.GraphOperation.SubGraph(graph, graph.GetColoredGraph().GetUnColoredVertexList());

                while (copyGraph.GetRealCountVertices() != 0)
                {
                    vertex = copyGraph.GetGraphProperty().GetVertexWithDegree(copyGraph.GetGraphProperty().GetMinimumVertexDegree());
                    neighboursVertexList = copyGraph.Neighbours(vertex);

                    copyGraph.VertexDelete(vertex);
                    foreach (Graph.IVertexInterface neighbour in neighboursVertexList)
                    {
                        copyGraph.VertexDelete(neighbour);
                    }

                    graph.GetColoredGraph().ColorVertex(graph.GetVertexByUserName(vertex.GetUserName()), color);
                }

                color++;
            }

            bool isColored = coloredGraph.InitializeColoredGraph();

            if (!isColored)
            {
                throw new MyException.GraphColoringAlgorithmException.AlgorithmGraphIsNotColored();
            }
        }