Пример #1
0
        private void GenerateAny()
        {
            var numberOfVertices           = GraphCreator.NumberOfVertices;
            var probabilityOfEdgeExistence = GraphCreator.ProbabilityOfEdgeExistence;

            var generator = new ConnectedGraphGenerator(numberOfVertices, probabilityOfEdgeExistence);

            _graph = generator.Generate();
            if (_graph == null)
            {
                return;
            }

            Graph.Show(_graph, GetSpreadMode());
            IsConnected    = new DfsConnectivityChecker().IsConnected(_graph);
            SearchSequence = new DfsAlgorithm().Execute(_graph, 0).Select(x => x + 1);

            if (!IsConnected)
            {
                return;
            }

            var colors = DistinctColors.DistinctColors.OrderBy(x => Guid.NewGuid()).Take(numberOfVertices).ToArray();

            foreach (var(vertex, color) in new GreedyVertexColoringAlgorithm().Execute(_graph))
            {
                Graph.Vertices[vertex].Color = colors[color];
            }
        }
Пример #2
0
        private Document CreateDocument()
        {
            var document = new Document();

            DefineStyles(document);

            var section = document.AddSection();
            var header  = section.AddParagraph("Autorzy: ");

            header.Format.Font.Size = 24;
            header.Format.Alignment = ParagraphAlignment.Right;

            foreach (var name in AppInfo.Authors)
            {
                var p = section.AddParagraph(name);
                p.Format.Alignment = ParagraphAlignment.Right;
            }

            section.AddImage(CreateImage());

            header = section.AddParagraph("Macierz incydencji:");
            header.Format.Font.Size = 18;
            section.Add(BuildIncidencyMatrix());

            var isConnected = new DfsConnectivityChecker().IsConnected(_graph);

            header = section.AddParagraph("Spójność:");
            header.Format.Font.Size = 18;
            section.AddParagraph("Graf jest " + (isConnected ? "spójny" : "niespójny"));

            if (isConnected)
            {
                header = section.AddParagraph("Ciąg przeszukań (w głąb):");
                header.Format.Font.Size = 18;
                section.AddParagraph(string.Join(", ", _searchAlgorithm.Execute(_graph, 0).Select(x => x + 1)));

                header = section.AddParagraph("Wynik kolorowania wierzchołków (algorytm zachłanny):");
                header.Format.Font.Size = 18;
                foreach (var(vertex, color) in _vertexColoringAlgorithm.Execute(_graph))
                {
                    section.AddParagraph($@"Wierzchołek {vertex + 1} - Kolor {color + 1}");
                }
            }

            return(document);
        }
Пример #3
0
        public void Create(Stream outputStream)
        {
            using (var streamWriter = new StreamWriter(outputStream))
            {
                streamWriter.WriteLine("Autorzy:");
                streamWriter.WriteLine(string.Join(", ", AppInfo.Authors));
                streamWriter.WriteLine();
                streamWriter.WriteLine("Macierz incydencji:");
                for (int i = 0; i < _graph.NumberOfVertices; ++i)
                {
                    var row = Enumerable.Range(0, _graph.NumberOfVertices)
                              .Select(j =>
                    {
                        if (i == j)
                        {
                            return("-");
                        }
                        return(_graph[i, j] ? "1" : "0");
                    });
                    streamWriter.WriteLine(string.Join("  ", row));
                }
                streamWriter.WriteLine();

                var isConnected = new DfsConnectivityChecker().IsConnected(_graph);
                streamWriter.WriteLine("Graf jest " + (isConnected ? "spójny" : "niespójny"));
                streamWriter.WriteLine();
                if (isConnected)
                {
                    streamWriter.WriteLine("Ciąg przeszukań (w głąb):");
                    streamWriter.WriteLine(string.Join(", ", _searchAlgorithm.Execute(_graph, 0).Select(x => x + 1)));
                    streamWriter.WriteLine();

                    streamWriter.WriteLine("Wynik kolorowania wierzchołków (algorytm zachłanny):");
                    foreach (var(vertex, color) in _vertexColoringAlgorithm.Execute(_graph))
                    {
                        streamWriter.WriteLine($@"Wierzchołek {vertex + 1} - Kolor {color + 1}");
                    }
                    streamWriter.WriteLine();
                }
            }
        }