示例#1
0
        private static string PrintChromosomes([NotNull] GeneticCompoundFDPOptimizer optimizer)
        {
            StringBuilder strBuilder = new StringBuilder();

            for (int i = 0; i < optimizer.Population.Length; i++)
            {
                CompoundFDPLayoutParameters chromosome = optimizer.Population[i];

                strBuilder.AppendLine($"---------- Chromosome[{i}] ---------------");
                strBuilder.AppendLine($"ElasticConstant: {chromosome.ElasticConstant}");
                strBuilder.AppendLine($"RepulsionConstant: {chromosome.RepulsionConstant}");
                strBuilder.AppendLine($"GravitationFactor: {chromosome.GravitationFactor}");
                strBuilder.AppendLine($"NestingFactor: {chromosome.NestingFactor}");
                strBuilder.AppendLine($"Phase1Iterations: {chromosome.Phase1Iterations}");
                strBuilder.AppendLine($"Phase2Iterations: {chromosome.Phase2Iterations}");
                strBuilder.AppendLine($"Phase3Iterations: {chromosome.Phase3Iterations}");
                strBuilder.AppendLine($"DisplacementLimitMultiplier: {chromosome.DisplacementLimitMultiplier}");
                strBuilder.AppendLine($"SeparationMultiplier: {chromosome.SeparationMultiplier}");
                strBuilder.AppendLine($"TemperatureDecreasing: {chromosome.TemperatureDecreasing}");
                strBuilder.AppendLine($"Fitness: {optimizer.Fitnesses[i]}");
                strBuilder.AppendLine("---------------------------------------------");
            }

            return(strBuilder.ToString());
        }
示例#2
0
        public void Clone()
        {
            var parameters       = new CompoundFDPLayoutParameters();
            var clonedParameters = (CompoundFDPLayoutParameters)parameters.Clone();

            Assert.AreEqual(parameters, clonedParameters);

            parameters = new CompoundFDPLayoutParameters();
            parameters.IdealEdgeLength   = 15;
            parameters.ElasticConstant   = 0.5;
            parameters.RepulsionConstant = 120;
            parameters.NestingFactor     = 0.3;
            parameters.GravitationFactor = 9;
            parameters.Phase1Iterations  = 40;
            parameters.Phase2Iterations  = 30;
            parameters.Phase3Iterations  = 40;
            parameters.Phase2TemperatureInitialMultiplier = 0.6;
            parameters.Phase3TemperatureInitialMultiplier = 0.4;
            parameters.TemperatureDecreasing       = 0.4;
            parameters.DisplacementLimitMultiplier = 0.4;
            parameters.SeparationMultiplier        = 10;
            clonedParameters = (CompoundFDPLayoutParameters)parameters.Clone();

            Assert.AreEqual(parameters, clonedParameters);
        }
示例#3
0
        /// <summary>
        /// Performs the actual layout algorithm.
        /// </summary>
        /// <param name="graph">The object containing the graph data</param>
        /// <param name="rootNode">Root node</param>
        protected override void PerformLayout(GraphMapData graph, INode rootNode)
        {
            BidirectionalGraph <string, WeightedEdge <string> > bGraph = GraphSharpUtility.GetBidirectionalGraph(graph);
            IDictionary <string, Size>   nodeSizes     = GraphSharpUtility.GetNodeSizes(graph);
            IDictionary <string, Vector> nodePositions = GraphSharpUtility.GetNodePositions(graph);
            CompoundFDPLayoutParameters  compoundFDPLayoutParameters = new CompoundFDPLayoutParameters();

            CompoundFDPLayoutAlgorithm <string, WeightedEdge <string>, BidirectionalGraph <string, WeightedEdge <string> > > compoundFDPLayoutAlgorithm = new CompoundFDPLayoutAlgorithm <string, WeightedEdge <string>, BidirectionalGraph <string, WeightedEdge <string> > >(bGraph, nodeSizes, null, null, nodePositions, compoundFDPLayoutParameters);

            compoundFDPLayoutAlgorithm.Compute();

            GraphSharpUtility.SetNodePositions(graph, compoundFDPLayoutAlgorithm.VertexPositions);
        }
示例#4
0
        public void InvalidParameters()
        {
            var parameters = new CompoundFDPLayoutParameters();

            Assert.Throws <ArgumentOutOfRangeException>(() => parameters.IdealEdgeLength  = -1);
            Assert.Throws <ArgumentOutOfRangeException>(() => parameters.ElasticConstant  = -1);
            Assert.Throws <ArgumentOutOfRangeException>(() => parameters.Phase1Iterations = -1);
            Assert.Throws <ArgumentOutOfRangeException>(() => parameters.Phase2Iterations = -1);
            Assert.Throws <ArgumentOutOfRangeException>(() => parameters.Phase3Iterations = -1);
            Assert.Throws <ArgumentOutOfRangeException>(() => parameters.Phase2TemperatureInitialMultiplier = -1);
            Assert.Throws <ArgumentOutOfRangeException>(() => parameters.Phase3TemperatureInitialMultiplier = -1);
            Assert.Throws <ArgumentOutOfRangeException>(() => parameters.TemperatureDecreasing = -1);
        }
        public void Constructor()
        {
            var graph               = new BidirectionalGraph <string, Edge <string> >();
            var verticesPositions   = new Dictionary <string, Point>();
            var verticesSizes       = new Dictionary <string, Size>();
            var verticesThicknesses = new Dictionary <string, Thickness>();
            var verticesTypes       = new Dictionary <string, CompoundVertexInnerLayoutType>();

            var algorithm = new CompoundFDPLayoutAlgorithm <string, Edge <string>, IBidirectionalGraph <string, Edge <string> > >(graph, verticesSizes, verticesThicknesses, verticesTypes);

            AssertFDPAlgorithmProperties(algorithm, graph);

            algorithm = new CompoundFDPLayoutAlgorithm <string, Edge <string>, IBidirectionalGraph <string, Edge <string> > >(graph, verticesSizes, verticesThicknesses, verticesTypes);
            algorithm.IterationEnded += (sender, args) => { };
            AssertFDPAlgorithmProperties(algorithm, graph, expectedReportIterationEnd: true);

            algorithm = new CompoundFDPLayoutAlgorithm <string, Edge <string>, IBidirectionalGraph <string, Edge <string> > >(graph, verticesSizes, verticesThicknesses, verticesTypes);
            algorithm.ProgressChanged += (sender, args) => { };
            AssertFDPAlgorithmProperties(algorithm, graph, expectedReportProgress: true);

            algorithm = new CompoundFDPLayoutAlgorithm <string, Edge <string>, IBidirectionalGraph <string, Edge <string> > >(graph, verticesSizes, verticesThicknesses, verticesTypes);
            algorithm.IterationEnded  += (sender, args) => { };
            algorithm.ProgressChanged += (sender, args) => { };
            AssertFDPAlgorithmProperties(algorithm, graph, expectedReportIterationEnd: true, expectedReportProgress: true);

            algorithm = new CompoundFDPLayoutAlgorithm <string, Edge <string>, IBidirectionalGraph <string, Edge <string> > >(graph, verticesPositions, verticesSizes, verticesThicknesses, verticesTypes);
            AssertFDPAlgorithmProperties(algorithm, graph, verticesPositions);

            var parameters = new CompoundFDPLayoutParameters();

            algorithm = new CompoundFDPLayoutAlgorithm <string, Edge <string>, IBidirectionalGraph <string, Edge <string> > >(graph, verticesSizes, verticesThicknesses, verticesTypes, parameters);
            AssertFDPAlgorithmProperties(algorithm, graph, p: parameters);

            algorithm = new CompoundFDPLayoutAlgorithm <string, Edge <string>, IBidirectionalGraph <string, Edge <string> > >(graph, verticesPositions, verticesSizes, verticesThicknesses, verticesTypes, parameters);
            AssertFDPAlgorithmProperties(algorithm, graph, verticesPositions, p: parameters);

            #region Local function

            void AssertFDPAlgorithmProperties <TVertex, TEdge, TGraph>(
                CompoundFDPLayoutAlgorithm <TVertex, TEdge, TGraph> algo,
                TGraph g,
                IDictionary <TVertex, Point> pos = null,
                bool expectedReportIterationEnd  = false,
                bool expectedReportProgress      = false,
                CompoundFDPLayoutParameters p    = null)
                where TVertex : class
示例#6
0
            public void RefineLayout(int iterations)
            {
                // Prepare state for algorithm.
                BidirectionalGraph <string, IEdge <string> > graph
                    = new BidirectionalGraph <string, IEdge <string> >(false);
                Dictionary <string, Point> positions
                    = new Dictionary <string, Point>();

                // Anything to do?
                if (BayesianNetwork.VariablesOrdered.Any() == false)
                {
                    this.Positions  = new Dictionary <string, Point>();
                    IterationCount += iterations;
                    return;
                }

                Random random = new Random(0);

                foreach (var rv in BayesianNetwork.VariablesOrdered)
                {
                    graph.AddVertex(rv.Name);

                    foreach (var child
                             in rv.Children.Select(c => BayesianNetwork.GetVariable(c)))
                    {
                        graph.AddVertex(child.Name);
                        graph.AddEdge(new Edge <string>(rv.Name, child.Name));
                    }

                    // If we have no existing layout yet, lets try to prime the
                    // alg by putting pure parents at top and pure children at
                    // bottom.
                    if (Positions.Count != 0)
                    {
                        // We have existing layout. Start with it but add slight
                        // randomness.

                        Point positionNoised;
                        if (Positions.ContainsKey(rv.Name))
                        {
                            positionNoised = Positions[rv.Name];
                        }
                        else
                        {
                            positionNoised = new Point();
                        }
                        positionNoised.X  += (random.NextDouble() - 0.5) * 0.01;
                        positionNoised.Y  += (random.NextDouble() - 0.5) * 0.01;
                        positions[rv.Name] = positionNoised;
                    }
                }

                // Initialize algorithm.
                var layoutAlgorithms
                    = new StandardLayoutAlgorithmFactory <string, IEdge <string>, IBidirectionalGraph <string, IEdge <string> > >();

                var layoutContext = new LayoutContext <string, IEdge <string>, IBidirectionalGraph <string, IEdge <string> > >(
                    graph,
                    positions,
                    _sizes,
                    LayoutMode.Simple);

                ILayoutAlgorithm <string, IEdge <string>, IBidirectionalGraph <string, IEdge <string> > > layoutAlgorithm;

                var algorithm = this._options.Algorithm;

                // Hack: SugiyamaEfficient breaks if no edges.
                if (algorithm == NetworkLayoutOptions.AlgorithmEnum.KK || graph.Edges.Count() == 0)
                {
                    var layoutParameters = new KKLayoutParameters();
                    layoutParameters.Height           = 1000;
                    layoutParameters.Width            = 1000;
                    layoutParameters.MaxIterations    = iterations;
                    layoutParameters.LengthFactor     = 1.35;
                    layoutParameters.K               *= 10.1;
                    layoutParameters.AdjustForGravity = false;

                    layoutAlgorithm = layoutAlgorithms.CreateAlgorithm("KK", layoutContext, layoutParameters);
                }
                else if (algorithm == NetworkLayoutOptions.AlgorithmEnum.SugiyamaEfficient)
                {
                    var layoutParameters = new EfficientSugiyamaLayoutParameters();
                    layoutParameters.MinimizeEdgeLength = true;
                    layoutParameters.OptimizeWidth      = true;
                    layoutParameters.WidthPerHeight     = 1.65;
                    layoutParameters.VertexDistance     = this._options.NodeSeparationTarget;
                    layoutParameters.LayerDistance      = 5.0;

                    layoutAlgorithm = layoutAlgorithms.CreateAlgorithm("EfficientSugiyama", layoutContext, layoutParameters);
                }
                else if (algorithm == NetworkLayoutOptions.AlgorithmEnum.Sugiyama)
                {
                    var layoutParameters = new SugiyamaLayoutParameters();
                    layoutParameters.MaxWidth    = 1024;
                    layoutParameters.VerticalGap = 1.0f;
                    layoutParameters.DirtyRound  = true;

                    layoutAlgorithm = layoutAlgorithms.CreateAlgorithm("Sugiyama", layoutContext, layoutParameters);
                }
                else if (algorithm == NetworkLayoutOptions.AlgorithmEnum.CompoundFDP)
                {
                    var layoutParameters = new CompoundFDPLayoutParameters();
                    layoutParameters.GravitationFactor = 0.8;
                    layoutParameters.IdealEdgeLength   = 30;
                    layoutParameters.RepulsionConstant = 300;
                    layoutAlgorithm = layoutAlgorithms.CreateAlgorithm("CompoundFDP", layoutContext, layoutParameters);
                }
                else
                {
                    throw new InvalidOperationException("Unknown layout.");
                }

                // Compute.
                layoutAlgorithm.Compute();

                // Store Results.
                this.Positions
                    = layoutAlgorithm.VertexPositions.ToDictionary(
                          (kvp) => kvp.Key,
                          (kvp) => kvp.Value
                          );

                // Done.
                IterationCount += iterations;
            }
示例#7
0
 public override CompoundFDPLayoutAlgorithm <Message, MessageEdge, CompoundGraph <Message, MessageEdge> > NewLayout(CompoundFDPLayoutParameters cparams)
 {
     return(new CompoundFDPLayoutAlgorithm <Message, MessageEdge, CompoundGraph <Message, MessageEdge> >(graph, VSize, VThickness, VType, VPos, cparams));
 }
        public void StandardFactory()
        {
            var positions     = new Dictionary <TestVertex, Point>();
            var sizes         = new Dictionary <TestVertex, Size>();
            var borders       = new Dictionary <TestVertex, Thickness>();
            var layoutTypes   = new Dictionary <TestVertex, CompoundVertexInnerLayoutType>();
            var graph         = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();
            var simpleContext = new LayoutContext <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(
                graph,
                positions,
                sizes,
                LayoutMode.Simple);
            var compoundContext1 = new LayoutContext <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(
                graph,
                positions,
                sizes,
                LayoutMode.Compound);
            var compoundContext2 = new CompoundLayoutContext <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(
                graph,
                positions,
                sizes,
                LayoutMode.Compound,
                borders,
                layoutTypes);
            var nullGraphContext = new LayoutContext <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(
                null,
                positions,
                sizes,
                LayoutMode.Simple);

            var factory = new StandardLayoutAlgorithmFactory <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >();

            CollectionAssert.AreEqual(
                new[]
            {
                "Circular", "Tree", "FR", "BoundedFR", "KK",
                "ISOM", "LinLog", "Sugiyama", "CompoundFDP",
                "Random"
            },
                factory.AlgorithmTypes);


            Assert.IsNull(
                factory.CreateAlgorithm(
                    string.Empty,
                    simpleContext,
                    new CircularLayoutParameters()));

            Assert.IsNull(
                factory.CreateAlgorithm(
                    "NotExist",
                    simpleContext,
                    new CircularLayoutParameters()));

            Assert.IsNull(
                factory.CreateAlgorithm(
                    "Circular",
                    nullGraphContext,
                    new CircularLayoutParameters()));

            Assert.IsInstanceOf <CircularLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "Circular",
                    simpleContext,
                    new CircularLayoutParameters()));

            Assert.IsInstanceOf <SimpleTreeLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "Tree",
                    simpleContext,
                    new SimpleTreeLayoutParameters()));

            Assert.IsInstanceOf <FRLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "FR",
                    simpleContext,
                    new FreeFRLayoutParameters()));

            Assert.IsInstanceOf <FRLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "BoundedFR",
                    simpleContext,
                    new BoundedFRLayoutParameters()));

            Assert.IsInstanceOf <KKLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "KK",
                    simpleContext,
                    new KKLayoutParameters()));

            Assert.IsInstanceOf <ISOMLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "ISOM",
                    simpleContext,
                    new ISOMLayoutParameters()));

            Assert.IsInstanceOf <LinLogLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "LinLog",
                    simpleContext,
                    new LinLogLayoutParameters()));

            Assert.IsInstanceOf <SugiyamaLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "Sugiyama",
                    simpleContext,
                    new SugiyamaLayoutParameters()));

            Assert.IsInstanceOf <CompoundFDPLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "CompoundFDP",
                    simpleContext,
                    new CompoundFDPLayoutParameters()));

            Assert.IsInstanceOf <RandomLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "Random",
                    simpleContext,
                    new RandomLayoutParameters()));

            Assert.IsNull(
                factory.CreateAlgorithm(
                    "CompoundFDP",
                    compoundContext1,
                    new CompoundFDPLayoutParameters()));

            Assert.IsNull(
                factory.CreateAlgorithm(
                    "Circular",
                    compoundContext2,
                    new CompoundFDPLayoutParameters()));

            Assert.IsInstanceOf <CompoundFDPLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "CompoundFDP",
                    compoundContext2,
                    new CompoundFDPLayoutParameters()));


            var testParameters     = new TestLayoutParameters();
            var circularParameters = new CircularLayoutParameters();
            ILayoutParameters createdParameters = factory.CreateParameters(string.Empty, circularParameters);

            Assert.IsNull(createdParameters);

            createdParameters = factory.CreateParameters("NotExist", circularParameters);
            Assert.IsNull(createdParameters);

            createdParameters = factory.CreateParameters("Circular", null);
            Assert.IsInstanceOf <CircularLayoutParameters>(createdParameters);
            Assert.AreNotSame(circularParameters, createdParameters);

            createdParameters = factory.CreateParameters("Circular", testParameters);
            Assert.IsInstanceOf <CircularLayoutParameters>(createdParameters);
            Assert.AreNotSame(testParameters, createdParameters);

            createdParameters = factory.CreateParameters("Circular", circularParameters);
            Assert.IsInstanceOf <CircularLayoutParameters>(createdParameters);
            Assert.AreNotSame(circularParameters, createdParameters);

            var treeParameters = new SimpleTreeLayoutParameters();

            createdParameters = factory.CreateParameters("Tree", null);
            Assert.IsInstanceOf <SimpleTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("Tree", testParameters);
            Assert.IsInstanceOf <SimpleTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(testParameters, createdParameters);

            createdParameters = factory.CreateParameters("Tree", treeParameters);
            Assert.IsInstanceOf <SimpleTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            var frParameters = new FreeFRLayoutParameters();

            createdParameters = factory.CreateParameters("FR", null);
            Assert.IsInstanceOf <FreeFRLayoutParameters>(createdParameters);
            Assert.AreNotSame(frParameters, createdParameters);

            createdParameters = factory.CreateParameters("FR", testParameters);
            Assert.IsInstanceOf <FreeFRLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("FR", frParameters);
            Assert.IsInstanceOf <FreeFRLayoutParameters>(createdParameters);
            Assert.AreNotSame(frParameters, createdParameters);

            var boundedFrParameters = new BoundedFRLayoutParameters();

            createdParameters = factory.CreateParameters("BoundedFR", null);
            Assert.IsInstanceOf <BoundedFRLayoutParameters>(createdParameters);
            Assert.AreNotSame(boundedFrParameters, createdParameters);

            createdParameters = factory.CreateParameters("BoundedFR", testParameters);
            Assert.IsInstanceOf <BoundedFRLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("BoundedFR", boundedFrParameters);
            Assert.IsInstanceOf <BoundedFRLayoutParameters>(createdParameters);
            Assert.AreNotSame(boundedFrParameters, createdParameters);

            var kkParameters = new KKLayoutParameters();

            createdParameters = factory.CreateParameters("KK", null);
            Assert.IsInstanceOf <KKLayoutParameters>(createdParameters);
            Assert.AreNotSame(kkParameters, createdParameters);

            createdParameters = factory.CreateParameters("KK", testParameters);
            Assert.IsInstanceOf <KKLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("KK", kkParameters);
            Assert.IsInstanceOf <KKLayoutParameters>(createdParameters);
            Assert.AreNotSame(kkParameters, createdParameters);

            var isomParameters = new ISOMLayoutParameters();

            createdParameters = factory.CreateParameters("ISOM", null);
            Assert.IsInstanceOf <ISOMLayoutParameters>(createdParameters);
            Assert.AreNotSame(isomParameters, createdParameters);

            createdParameters = factory.CreateParameters("ISOM", testParameters);
            Assert.IsInstanceOf <ISOMLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("ISOM", isomParameters);
            Assert.IsInstanceOf <ISOMLayoutParameters>(createdParameters);
            Assert.AreNotSame(isomParameters, createdParameters);

            var linLogParameters = new LinLogLayoutParameters();

            createdParameters = factory.CreateParameters("LinLog", null);
            Assert.IsInstanceOf <LinLogLayoutParameters>(createdParameters);
            Assert.AreNotSame(linLogParameters, createdParameters);

            createdParameters = factory.CreateParameters("LinLog", testParameters);
            Assert.IsInstanceOf <LinLogLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("LinLog", linLogParameters);
            Assert.IsInstanceOf <LinLogLayoutParameters>(createdParameters);
            Assert.AreNotSame(linLogParameters, createdParameters);

            var sugiyamaParameters = new SugiyamaLayoutParameters();

            createdParameters = factory.CreateParameters("Sugiyama", null);
            Assert.IsInstanceOf <SugiyamaLayoutParameters>(createdParameters);
            Assert.AreNotSame(sugiyamaParameters, createdParameters);

            createdParameters = factory.CreateParameters("Sugiyama", testParameters);
            Assert.IsInstanceOf <SugiyamaLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("Sugiyama", sugiyamaParameters);
            Assert.IsInstanceOf <SugiyamaLayoutParameters>(createdParameters);
            Assert.AreNotSame(sugiyamaParameters, createdParameters);

            var compoundFDPParameters = new CompoundFDPLayoutParameters();

            createdParameters = factory.CreateParameters("CompoundFDP", null);
            Assert.IsInstanceOf <CompoundFDPLayoutParameters>(createdParameters);
            Assert.AreNotSame(compoundFDPParameters, createdParameters);

            createdParameters = factory.CreateParameters("CompoundFDP", testParameters);
            Assert.IsInstanceOf <CompoundFDPLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("CompoundFDP", compoundFDPParameters);
            Assert.IsInstanceOf <CompoundFDPLayoutParameters>(createdParameters);
            Assert.AreNotSame(compoundFDPParameters, createdParameters);

            var randomParameters = new RandomLayoutParameters();

            createdParameters = factory.CreateParameters("Random", null);
            Assert.IsInstanceOf <RandomLayoutParameters>(createdParameters);
            Assert.AreNotSame(randomParameters, createdParameters);

            createdParameters = factory.CreateParameters("Random", testParameters);
            Assert.IsInstanceOf <RandomLayoutParameters>(createdParameters);
            Assert.AreNotSame(treeParameters, createdParameters);

            createdParameters = factory.CreateParameters("Random", randomParameters);
            Assert.IsInstanceOf <RandomLayoutParameters>(createdParameters);
            Assert.AreNotSame(randomParameters, createdParameters);


            Assert.IsFalse(factory.IsValidAlgorithm(null));
            Assert.IsFalse(factory.IsValidAlgorithm(string.Empty));
            Assert.IsTrue(factory.IsValidAlgorithm("Circular"));
            Assert.IsFalse(factory.IsValidAlgorithm("circular"));
            Assert.IsTrue(factory.IsValidAlgorithm("Tree"));
            Assert.IsTrue(factory.IsValidAlgorithm("FR"));
            Assert.IsTrue(factory.IsValidAlgorithm("BoundedFR"));
            Assert.IsTrue(factory.IsValidAlgorithm("KK"));
            Assert.IsTrue(factory.IsValidAlgorithm("ISOM"));
            Assert.IsTrue(factory.IsValidAlgorithm("LinLog"));
            Assert.IsTrue(factory.IsValidAlgorithm("Sugiyama"));
            Assert.IsTrue(factory.IsValidAlgorithm("CompoundFDP"));
            Assert.IsTrue(factory.IsValidAlgorithm("Random"));


            var algorithm1 = new TestLayoutAlgorithm();

            Assert.IsEmpty(factory.GetAlgorithmType(algorithm1));

            var algorithm2 = new CircularLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, sizes, circularParameters);

            Assert.AreEqual("Circular", factory.GetAlgorithmType(algorithm2));

            var algorithm3 = new SimpleTreeLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, sizes, treeParameters);

            Assert.AreEqual("Tree", factory.GetAlgorithmType(algorithm3));

            var algorithm4 = new FRLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, frParameters);

            Assert.AreEqual("FR", factory.GetAlgorithmType(algorithm4));

            var algorithm5 = new FRLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, boundedFrParameters);

            Assert.AreEqual("BoundedFR", factory.GetAlgorithmType(algorithm5));

            var algorithm6 = new KKLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, kkParameters);

            Assert.AreEqual("KK", factory.GetAlgorithmType(algorithm6));

            var algorithm7 = new ISOMLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, isomParameters);

            Assert.AreEqual("ISOM", factory.GetAlgorithmType(algorithm7));

            var algorithm8 = new LinLogLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph);

            Assert.AreEqual("LinLog", factory.GetAlgorithmType(algorithm8));

            var algorithm9 = new SugiyamaLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, sizes, sugiyamaParameters);

            Assert.AreEqual("Sugiyama", factory.GetAlgorithmType(algorithm9));

            var algorithm10 = new CompoundFDPLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, sizes, borders, layoutTypes);

            Assert.AreEqual("CompoundFDP", factory.GetAlgorithmType(algorithm10));

            var algorithm11 = new RandomLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, sizes, null, randomParameters);

            Assert.AreEqual("Random", factory.GetAlgorithmType(algorithm11));


            Assert.IsFalse(factory.NeedEdgeRouting(string.Empty));
            Assert.IsTrue(factory.NeedEdgeRouting("Circular"));
            Assert.IsTrue(factory.NeedEdgeRouting("Tree"));
            Assert.IsTrue(factory.NeedEdgeRouting("FR"));
            Assert.IsTrue(factory.NeedEdgeRouting("BoundedFR"));
            Assert.IsTrue(factory.NeedEdgeRouting("KK"));
            Assert.IsTrue(factory.NeedEdgeRouting("ISOM"));
            Assert.IsTrue(factory.NeedEdgeRouting("LinLog"));
            Assert.IsFalse(factory.NeedEdgeRouting("Sugiyama"));
            Assert.IsTrue(factory.NeedEdgeRouting("CompoundFDP"));
            Assert.IsTrue(factory.NeedEdgeRouting("Random"));


            Assert.IsFalse(factory.NeedOverlapRemoval(string.Empty));
            Assert.IsFalse(factory.NeedOverlapRemoval("Circular"));
            Assert.IsFalse(factory.NeedOverlapRemoval("Tree"));
            Assert.IsTrue(factory.NeedOverlapRemoval("FR"));
            Assert.IsTrue(factory.NeedOverlapRemoval("BoundedFR"));
            Assert.IsTrue(factory.NeedOverlapRemoval("KK"));
            Assert.IsTrue(factory.NeedOverlapRemoval("ISOM"));
            Assert.IsTrue(factory.NeedOverlapRemoval("LinLog"));
            Assert.IsFalse(factory.NeedOverlapRemoval("Sugiyama"));
            Assert.IsFalse(factory.NeedOverlapRemoval("CompoundFDP"));
            Assert.IsTrue(factory.NeedOverlapRemoval("Random"));
        }
示例#9
0
        public void ParameterRaise()
        {
            string expectedPropertyName = null;

            var parameters = new CompoundFDPLayoutParameters();

            parameters.PropertyChanged += (sender, args) =>
            {
                // ReSharper disable AccessToModifiedClosure
                if (expectedPropertyName is null)
                {
                    Assert.Fail("Must not raise.");
                }
                else
                {
                    Assert.AreEqual(expectedPropertyName, args.PropertyName);
                }
                // ReSharper restore AccessToModifiedClosure
            };

            parameters.IdealEdgeLength = 25;

            expectedPropertyName       = nameof(CompoundFDPLayoutParameters.IdealEdgeLength);
            parameters.IdealEdgeLength = 30;

            expectedPropertyName       = null;
            parameters.ElasticConstant = 0.005;

            expectedPropertyName       = nameof(CompoundFDPLayoutParameters.ElasticConstant);
            parameters.ElasticConstant = 0.08;

            expectedPropertyName         = null;
            parameters.RepulsionConstant = 150;

            expectedPropertyName         = nameof(CompoundFDPLayoutParameters.RepulsionConstant);
            parameters.RepulsionConstant = 42;

            expectedPropertyName     = null;
            parameters.NestingFactor = 0.2;

            expectedPropertyName     = nameof(CompoundFDPLayoutParameters.NestingFactor);
            parameters.NestingFactor = 0.3;

            expectedPropertyName         = null;
            parameters.GravitationFactor = 8;

            expectedPropertyName         = nameof(CompoundFDPLayoutParameters.GravitationFactor);
            parameters.GravitationFactor = 10;

            expectedPropertyName        = null;
            parameters.Phase1Iterations = 50;

            expectedPropertyName        = nameof(CompoundFDPLayoutParameters.Phase1Iterations);
            parameters.Phase1Iterations = 60;

            expectedPropertyName        = null;
            parameters.Phase2Iterations = 70;

            expectedPropertyName        = nameof(CompoundFDPLayoutParameters.Phase2Iterations);
            parameters.Phase2Iterations = 80;

            expectedPropertyName        = null;
            parameters.Phase3Iterations = 30;

            expectedPropertyName        = nameof(CompoundFDPLayoutParameters.Phase3Iterations);
            parameters.Phase3Iterations = 40;

            expectedPropertyName = null;
            parameters.Phase2TemperatureInitialMultiplier = 0.5;

            expectedPropertyName = nameof(CompoundFDPLayoutParameters.Phase2TemperatureInitialMultiplier);
            parameters.Phase2TemperatureInitialMultiplier = 0.6;

            expectedPropertyName = null;
            parameters.Phase3TemperatureInitialMultiplier = 0.2;

            expectedPropertyName = nameof(CompoundFDPLayoutParameters.Phase3TemperatureInitialMultiplier);
            parameters.Phase3TemperatureInitialMultiplier = 0.3;

            expectedPropertyName             = null;
            parameters.TemperatureDecreasing = 0.5;

            expectedPropertyName             = nameof(CompoundFDPLayoutParameters.TemperatureDecreasing);
            parameters.TemperatureDecreasing = 0.4;

            expectedPropertyName = null;
            parameters.DisplacementLimitMultiplier = 0.5;

            expectedPropertyName = nameof(CompoundFDPLayoutParameters.DisplacementLimitMultiplier);
            parameters.DisplacementLimitMultiplier = 0.6;

            expectedPropertyName            = null;
            parameters.SeparationMultiplier = 15;

            expectedPropertyName            = nameof(CompoundFDPLayoutParameters.SeparationMultiplier);
            parameters.SeparationMultiplier = 16;
        }
示例#10
0
        public void Evaluate(int SpreadMax)
        {
            if (FBuild[0] || (pd.InputChanged && init))
            {
                graph.Clear();
                VSize.Clear();
                VThickness.Clear();
                VType.Clear();
                VPos.Clear();
                VCache.Clear();

                for (int i = 0; i < FVertices.SliceCount; i++)
                {
                    graph.AddVertex(FVertices[i]);
                    VSize.Add(FVertices[i], new Size(FVSize[i], FVSize[i]));
                    VThickness.Add(FVertices[i], new Thickness(1.0));
                    VType.Add(FVertices[i], FVType[i]);
                    VPos.Add(FVertices[i], new Point(FVPos[i].x, FVPos[i].y));
                    VCache.Add(FVertices[i]);
                }
                for (int i = 0; i < Math.Max(FEdgeFrom.SliceCount, FEdgeTo.SliceCount); i++)
                {
                    graph.AddEdge(new Edge <string>(FEdgeFrom[i], FEdgeTo[i]));
                }

                var cparams = new CompoundFDPLayoutParameters();
                foreach (var prop in typeof(CompoundFDPLayoutParameters).GetProperties())
                {
                    var input = pd.InputPins[prop.Name].Spread[0];
                    if (!(input.ToString().StartsWith("0") && input.ToString().EndsWith("0")))
                    {
                        prop.SetValue(cparams, pd.InputPins[prop.Name].Spread[0]);
                    }
                }
                layout = new CompoundFDPLayoutAlgorithm <string, IEdge <string>, CompoundGraph <string, IEdge <string> > >(graph, VSize, VThickness, VType, VPos, cparams);
                foreach (var prop in typeof(CompoundFDPLayoutParameters).GetProperties())
                {
                    var input = pd.InputPins[prop.Name].Spread[0];
                    if (!(input.ToString().StartsWith("0") && input.ToString().EndsWith("0")))
                    {
                        prop.SetValue(layout.Parameters, pd.InputPins[prop.Name].Spread[0]);
                    }
                }
                layout.Finished += (sender, args) =>
                {
                    FPosOut.SliceCount = VCache.Count;
                    for (int i = 0; i < VCache.Count; i++)
                    {
                        var point = layout.VertexPositions[VCache[i]];
                        FPosOut[i] = new Vector2D(point.X, point.Y);
                    }
                };
                if (FAsync[0])
                {
                    Task.Run(() =>
                    {
                        layout.Compute();
                    });
                }
                else
                {
                    layout.Compute();
                }
                init = true;
            }
            if (layout != null)
            {
                FState[0] = layout.State.ToString();
            }
        }