예제 #1
0
        //Zadanie 1.3
        static void Main(string[] args)
        {
            //Creating sample graph with 5 vertexes and 5 edges
            var graphClass = new Graph();
            var graphSize = 10;
            var graph = graphClass.CreateGraph(graphSize);
            graphClass.FillGraphRandomly(graph, 5, 5);

            //Calculating edge count Concurrently
            if (graphClass.CountEdgesConcurrently(graph, graphSize) == graphClass.CountEdgesSequentially(graph))
            {
                Console.WriteLine("Both alghoritms calculate edge count properly");
            }
            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var graphClass = new Graph();
            var graphSize = 10;
            var vertexNumber = 5;
            var graph = graphClass.CreateGraph(graphSize);
            graphClass.FillGraphRandomly(graph, vertexNumber, 5);
            graphClass.WriteGraph(graph);

            VertexArray = new Point[vertexNumber];
            var counter = 0;
            var random = new Random();

            var sb = new StringBuilder();
            for (var j = 0; j <= graphSize; j++)
            {
                for (var k = 0; k < graphSize; k++)
                {
                    if (k >= j + 1)
                    {

                        if (graph[j, k] == 1)
                        {
                            VertexArray[counter] = new Point(j, k, random.Next(0, 11));
                            counter++;
                        }
                    }
                }
            }

            var sequence = "";
            PermutationList = new List<string>();
            for (var l = 0; l < counter; l++)
            {
                sequence += l.ToString();
            }

            GeneratePermutations(sequence);
            MaxWidth(PermutationList);

            var threadArray = new Thread[vertexNumber];
            for (var i = 0; i < vertexNumber; i++)
            {
                var set = PermutationList.GetRange(i*24,24);
                threadArray[i] = new Thread(() =>
                {

                    var width = MaxWidth(set);

                    lock(PermutationList)
                    {

                        if (width > Max) Max = width;
                    }

                });

                threadArray[i].Start();
            }

            foreach (var thread in threadArray) thread.Join();
            Console.WriteLine($"Szerokość grafu wynosi {Max}");
            Console.ReadKey();
        }