public void Assignment1_Case1()
        {
            var vertices = new ExtendedVertex[]
                {
                   new ExtendedVertex(1, new AdjacentEdge[]
                        {
                            new AdjacentEdge(2,1),
                            new AdjacentEdge(3,1),
                            new AdjacentEdge(4,2),
                            new AdjacentEdge(5,2),
                            new AdjacentEdge(6,2),
                        }),
                    new ExtendedVertex(2, new AdjacentEdge[]
                    {
                        new AdjacentEdge(1,1),
                        new AdjacentEdge(3,1),
                        new AdjacentEdge(4,2),
                        new AdjacentEdge(5,2),
                        new AdjacentEdge(6,2),
                    }),
                    new ExtendedVertex(3, new AdjacentEdge[]
                        {
                            new AdjacentEdge(1,1),
                            new AdjacentEdge(2,1),
                            new AdjacentEdge(4,2),
                            new AdjacentEdge(5,2),
                            new AdjacentEdge(6,2),
                        }),
                    new ExtendedVertex(4, new AdjacentEdge[]
                    {
                        new AdjacentEdge(1,2),
                        new AdjacentEdge(2,2),
                        new AdjacentEdge(3,2),
                        new AdjacentEdge(5,2),
                        new AdjacentEdge(6,2),
                    }),
                     new ExtendedVertex(5, new AdjacentEdge[]
                    {
                        new AdjacentEdge(1,2),
                        new AdjacentEdge(2,2),
                        new AdjacentEdge(3,2),
                        new AdjacentEdge(4,2),
                        new AdjacentEdge(6,2),
                    }),
                     new ExtendedVertex(6, new AdjacentEdge[]
                    {
                        new AdjacentEdge(1,2),
                        new AdjacentEdge(2,2),
                        new AdjacentEdge(3,2),
                        new AdjacentEdge(4,2),
                        new AdjacentEdge(5,2),
                    }),
                };

            var maxSpaceClustering = new MaxSpaceClustering();
            Assert.AreEqual(2, maxSpaceClustering.CalcMaxSpacing(vertices, 4));
        }
Example #2
0
        private static void CalcClusterings(string filePath)
        {
            var stopWatch = new Stopwatch();
            stopWatch.Start();

            var lines = File.ReadAllLines(filePath);
            int verticesCount = int.Parse(lines[0].Split(' ').First());
            var vertices = new Dictionary<string, Vertex>(verticesCount);

            foreach (var line in lines.Skip(1))
            {
                AddDictionaryEdge(vertices, line);
            }

            var maxSpaceClustering = new MaxSpaceClustering();

            var result = maxSpaceClustering.CalcClusterings(vertices);

            stopWatch.Stop();

            Console.WriteLine("the largest value of k such that there is a k-clustering with spacing at least 3: {0}, elapsed: {1} ms", result, stopWatch.ElapsedMilliseconds);
        }
        public void Assignment1_Case2()
        {
            var vertices = Enumerable.Range(1, 10).Select(x => new ExtendedVertex(x)).ToArray();

            AddEdge(vertices, 1, 2, 91);
            AddEdge(vertices, 1, 3, 6);
            AddEdge(vertices, 1, 4, 31);
            AddEdge(vertices, 1, 5, 53);
            AddEdge(vertices, 1, 6, 15);
            AddEdge(vertices, 1, 7, 35);
            AddEdge(vertices, 1, 8, 83);
            AddEdge(vertices, 1, 9, 69);
            AddEdge(vertices, 1, 10, 78);
            AddEdge(vertices, 2, 3, 98);
            AddEdge(vertices, 2, 4, 58);
            AddEdge(vertices, 2, 5, 46);
            AddEdge(vertices, 2, 6, 53);
            AddEdge(vertices, 2, 7, 55);
            AddEdge(vertices, 2, 8, 74);
            AddEdge(vertices, 2, 9, 3);
            AddEdge(vertices, 2, 10, 34);

            AddEdge(vertices, 3, 4, 42);
            AddEdge(vertices, 3, 5, 4);
            AddEdge(vertices, 3, 6, 22);
            AddEdge(vertices, 3, 7, 84);
            AddEdge(vertices, 3, 8, 32);
            AddEdge(vertices, 3, 9, 74);
            AddEdge(vertices, 3, 10, 4);

            AddEdge(vertices, 4, 5, 94);
            AddEdge(vertices, 4, 6, 46);
            AddEdge(vertices, 4, 7, 92);
            AddEdge(vertices, 4, 8, 16);
            AddEdge(vertices, 4, 9, 65);
            AddEdge(vertices, 4, 10, 76);

            AddEdge(vertices, 5, 6, 5);
            AddEdge(vertices, 5, 7, 71);
            AddEdge(vertices, 5, 8, 17);
            AddEdge(vertices, 5, 9, 21);
            AddEdge(vertices, 5, 10, 73);

            AddEdge(vertices, 6, 7, 91);
            AddEdge(vertices, 6, 8, 36);
            AddEdge(vertices, 6, 9, 66);
            AddEdge(vertices, 6, 10, 59);

            AddEdge(vertices, 7, 8, 47);
            AddEdge(vertices, 7, 9, 9);
            AddEdge(vertices, 7, 10, 13);

            AddEdge(vertices, 8, 9, 51);
            AddEdge(vertices, 8, 10, 85);
            AddEdge(vertices, 9, 10, 2);

            var maxSpaceClustering = new MaxSpaceClustering();
            Assert.AreEqual(9, maxSpaceClustering.CalcMaxSpacing(vertices, 4));
        }
        public void Assignment2_Case1()
        {
            var vertices = new Dictionary<string, Vertex>(10);

            AddDictionaryEdge(vertices, "0 1 1 0 0 1 1 1");
            AddDictionaryEdge(vertices, "1 1 0 0 1 0 1 1");
            AddDictionaryEdge(vertices, "1 0 1 1 1 0 0 1");
            AddDictionaryEdge(vertices, "1 1 1 1 0 0 1 0");
            AddDictionaryEdge(vertices, "0 0 1 1 0 0 1 1");
            AddDictionaryEdge(vertices, "0 0 0 1 1 0 1 1");
            AddDictionaryEdge(vertices, "1 1 0 0 1 1 1 1");
            AddDictionaryEdge(vertices, "1 0 1 1 1 1 1 0");
            AddDictionaryEdge(vertices, "1 0 0 0 0 1 1 0");
            AddDictionaryEdge(vertices, "0 1 0 0 0 0 1 1");

            var maxSpaceClustering = new MaxSpaceClustering();
            Assert.AreEqual(6, maxSpaceClustering.CalcClusterings(vertices));
        }
Example #5
0
        private static void MaxSpaceClustering(string filePath)
        {
            var lines = File.ReadAllLines(filePath);
            int verticesCount = int.Parse(lines[0].Split(' ').First());
            var vertices = Enumerable.Range(1, verticesCount).Select(x => new ExtendedVertex(x)).ToArray();

            foreach (var line in lines.Skip(1))
            {
                var node = line.Split(new[] { ' ', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries);
                var left = int.Parse(node[0]);
                var right = int.Parse(node[1]);
                var weight = int.Parse(node[2]);
                vertices[left - 1].AddAdjacenEdge(new AdjacentEdge(right, weight));
                vertices[right - 1].AddAdjacenEdge(new AdjacentEdge(left, weight));
            }

            var maxSpaceClustering = new MaxSpaceClustering();

            Console.WriteLine("maximum spacing of a 4-clustering: {0}", maxSpaceClustering.CalcMaxSpacing(vertices, 4));
        }