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]); }
private void CreateSampleGraph() { #region Simple tree graph var graph = new PocGraph(); PocVertex[] vertices = Enumerable.Range(0, 8).Select(VertexFactory).ToArray(); graph.AddVertexRange(vertices); graph.AddEdgeRange(new [] { EdgeFactory(vertices[0], vertices[1]), EdgeFactory(vertices[1], vertices[2]), EdgeFactory(vertices[2], vertices[3]), EdgeFactory(vertices[2], vertices[4]), EdgeFactory(vertices[0], vertices[5]), EdgeFactory(vertices[1], vertices[7]), EdgeFactory(vertices[4], vertices[6]), EdgeFactory(vertices[0], vertices[4]) }); GraphModels.Add(new GraphViewModel("Fa", graph)); #endregion #region Complete graph IBidirectionalGraph <PocVertex, PocEdge> completeGraph = GraphFactory.CreateCompleteGraph( 7, VertexFactory, EdgeFactory); GraphModels.Add(new GraphViewModel("Complete", ConvertToPocGraph(completeGraph))); #endregion #region Isolated vertices graph IBidirectionalGraph <PocVertex, PocEdge> isolatedVerticesGraph = GraphFactory.CreateIsolatedVerticesGraph <PocVertex, PocEdge>( 25, VertexFactory); GraphModels.Add(new GraphViewModel("Isolated vertices", ConvertToPocGraph(isolatedVerticesGraph))); #endregion #region General graph IBidirectionalGraph <PocVertex, PocEdge> generalGraph = GraphFactory.CreateGeneralGraph( 30, 25, 10, true, VertexFactory, EdgeFactory, new Random(123456)); GraphModels.Add(new GraphViewModel("General graph", ConvertToPocGraph(generalGraph))); #endregion #region DAG graph IBidirectionalGraph <PocVertex, PocEdge> dagGraph = GraphFactory.CreateDAG( 30, 25, 5, 10, true, VertexFactory, EdgeFactory, new Random(123456)); GraphModels.Add(new GraphViewModel("DAG graph", ConvertToPocGraph(dagGraph))); #endregion #region Tree graph IBidirectionalGraph <PocVertex, PocEdge> treeGraph = GraphFactory.CreateTree( 25, 3, VertexFactory, EdgeFactory, new Random(123456)); GraphModels.Add(new GraphViewModel("Tree graph", ConvertToPocGraph(treeGraph)));