Пример #1
0
        public static DynamicPlotter GetDynamicPlotter(DynamicPlotData data)
        {
            var plotter = new GameObject().AddComponent <DynamicPlotter>();
            var graph   = new DynamicGraph();

            data.Points.ForEach(point =>
                                graph.AddPlotPoint(new PlotPoint(point.XColumn, point.YColumn, point.ZColumn))
                                );

            graph.AddTimePoints(data.TimeColumn);

            plotter.Graph = graph;

            plotter.PointHolder = GetPlotHolder();
            plotter.PointPrefab = data.PointObject.transform;
            plotter.Text        = GetText3D();

            plotter.PlotTitle = data.Title;
            plotter.XAxisName = data.XName;
            plotter.YAxisName = data.YName;
            plotter.ZAxisName = data.ZName;

            plotter.PlotScale = data.PlotScale;

            plotter.Init();

            return(plotter);
        }
Пример #2
0
        public static void wikipedia_graph_sample()
        {
            var nodes = new[] { 1, 2, 3, 4, 5, 6 };
            var edges = new Dictionary <DualKey <int>, double> {
                { new DualKey <int>(1, 2), 7 },
                { new DualKey <int>(1, 3), 9 },
                { new DualKey <int>(1, 6), 14 },
                { new DualKey <int>(2, 3), 10 },
                { new DualKey <int>(2, 4), 15 },
                { new DualKey <int>(3, 4), 11 },
                { new DualKey <int>(3, 6), 2 },
                { new DualKey <int>(4, 5), 6 },
                { new DualKey <int>(5, 6), 9 }
            };

            // add the reverse edges
            foreach (var reversedEdgeData in edges.Select(x => new { Key = new DualKey <int>(x.Key.B, x.Key.A), x.Value }).ToList())
            {
                edges.Add(reversedEdgeData.Key, reversedEdgeData.Value);
            }

            var result = DynamicGraph.FindPath(
                1, 5,
                (int node, double curCost) => edges
                .Where(x => x.Key.A == node)
                .Select(edge => new DynamicGraphNodeData <int, double, KeyValuePair <DualKey <int>, double> >(edge.Key.B, curCost + edge.Value, edge))
                );

            result.Select(x => x.Node).Should().Equal(new[] { 1, 3, 6, 5 });
            //Assert.AreEqual(new[] { 1, 3, 6, 5 }, result.Select(x => x.Node).ToArray());
            result.Last().Cost.Should().Be(20);
            //Assert.AreEqual(20, result.Last().Cost);
        }
Пример #3
0
 public DiagramSettingsView(DynamicGraph dGraph)
 {
     this.GSettings = new GraphSettings();
     this.Graph = dGraph;
     this.Graph.Settings = this.GSettings;
 }
Пример #4
0
        /// <summary>
        /// Finds a path through all the given transformations and determines the required to and from types for each transformation.
        /// </summary>
        /// <param name="transformations">The transformations to find a casting path between.</param>
        /// <param name="startType">The from type of the first transformation.</param>
        /// <param name="endType">The to type of the last transformation.</param>
        /// <returns>Transformation nodes providing cast information for a path from start to finish.</returns>
        public static TransformationCastNode[] FindCastPath(IList <ITransformation> transformations, Type startType, Type endType)
        {
            if (null == transformations)
            {
                throw new ArgumentNullException("transformations");
            }
            if (null == startType)
            {
                throw new ArgumentNullException("startType");
            }
            if (null == endType)
            {
                throw new ArgumentNullException("endType");
            }
            if (transformations.Any(x => null == x))
            {
                throw new ArgumentException("transformations must all be non-null", "transformations");
            }
            Contract.EndContractBlock();

            if (transformations.Count == 0)
            {
                return(null); // NO DATA
            }
            // determine the valid start nodes
            Contract.Assume(transformations[0] != null);
            var startNodes = GenerateNodes(transformations[0])
                             .Where(x => x.FromType == startType)
                             .ToArray();

            Contract.Assume(Contract.ForAll(startNodes, x => x != null));

            // if there is only one transformation, just use that
            if (transformations.Count == 1)
            {
                var selectedTx = startNodes.FirstOrDefault(x => x.ToType == endType);
                return(null != selectedTx ? new[] { selectedTx } : null);
            }

            // build the edges and nodes between the start and end types
            var previousNodes = startNodes;
            var edges         = new Dictionary <TransformationCastNode, List <TransformationCastNode> >();

            for (int i = 1; i < transformations.Count; i++)
            {
                Contract.Assume(transformations[i] != null);
                var currentNodes = GenerateNodes(transformations[i]).ToArray();
                Contract.Assume(Contract.ForAll(currentNodes, x => x != null));
                foreach (var priorNode in previousNodes)
                {
                    foreach (var curNode in currentNodes)
                    {
                        if (priorNode.ToType == curNode.FromType)
                        {
                            List <TransformationCastNode> edgeData;
                            if (!edges.TryGetValue(priorNode, out edgeData))
                            {
                                edgeData = new List <TransformationCastNode>();
                                edges.Add(priorNode, edgeData);
                            }
                            Contract.Assume(edgeData != null);
                            edgeData.Add(curNode);
                        }
                    }
                }
                previousNodes = currentNodes;
            }

            // the end types are the last nodes that have matching end types
            var endNodes = previousNodes.Where(x => x.ToType == endType).ToArray();

            // the neighborhood
            GetDynamicGraphNeighborInfo <TransformationCastNode, int, TransformationCastNode> getNeighborhood = (node, curCost) => {
                List <TransformationCastNode> edgeData;
                edges.TryGetValue(node, out edgeData);
                return((edgeData ?? Enumerable.Empty <TransformationCastNode>()).Select(x => new DynamicGraphNodeData <TransformationCastNode, int, TransformationCastNode>(x, curCost + 1, x)));
            };

            // go through each combination of start and end types until something is found
            foreach (var startNode in startNodes)
            {
                foreach (var endNode in endNodes)
                {
                    Contract.Assume(endNode != null); // because GenerateNodes will not return a null element
                    var result = DynamicGraph.FindPath(startNode, endNode, getNeighborhood);
                    if (null != result)
                    {
                        return(result.Select(x => x.Node).ToArray()); // OK!
                    }
                }
            }

            return(null); // no path found
        }