Example #1
0
        public void RandomLayoutAlgorithm([NotNull] IVertexAndEdgeListGraph <string, Edge <string> > graph)
        {
            IDictionary <string, Size> verticesSizes = GetVerticesSizes(graph.Vertices);
            var algorithm = new RandomLayoutAlgorithm <string, Edge <string>, IVertexAndEdgeListGraph <string, Edge <string> > >(
                graph,
                verticesSizes,
                null,
                new RandomLayoutParameters())
            {
                Rand = new Random(12345)
            };

            LayoutResults results = ExecuteLayoutAlgorithm(algorithm, verticesSizes, true);

            results.CheckPositions();
        }
Example #2
0
        public void RandomLayoutAlgorithm_WithFixedVertices()
        {
            IVertexAndEdgeListGraph <string, Edge <string> > graph = GraphFactory.CreateGeneralGraph(
                30,
                15,
                10,
                false,
                i => i.ToString(),
                (s, t) => new Edge <string>(s, t),
                new Random(123));

            string[] vertices = graph.Vertices.ToArray();

            string fixedVertexNoPos    = vertices[2];
            string fixedVertexWithPos  = vertices[16];
            var    fixedVertexPosition = new Point(50.0, 50.0);
            IDictionary <string, Point> verticesPositions = new Dictionary <string, Point>
            {
                [fixedVertexWithPos] = fixedVertexPosition
            };
            IDictionary <string, Size> verticesSizes = GetVerticesSizes(vertices);
            var verticesTypes = new Dictionary <string, RandomVertexType>
            {
                [fixedVertexNoPos]   = RandomVertexType.Fixed,
                [vertices[8]]        = RandomVertexType.Free,
                [fixedVertexWithPos] = RandomVertexType.Fixed
            };

            var algorithm = new RandomLayoutAlgorithm <string, Edge <string>, IVertexAndEdgeListGraph <string, Edge <string> > >(
                graph,
                verticesPositions,
                verticesSizes,
                verticesTypes,
                new RandomLayoutParameters())
            {
                Rand = new Random(12345)
            };

            // Run without overlap removal otherwise fixed vertex may change their positions after algorithm run
            LayoutResults results = ExecuteLayoutAlgorithm(algorithm, verticesSizes);

            results.CheckPositions();

            Assert.AreEqual(fixedVertexPosition, algorithm.VerticesPositions[fixedVertexWithPos]);
        }