示例#1
0
        public void DepthFirstTraversalIsLazy()
        {
            var guid       = Guid.NewGuid();
            var descriptor = GraphDescriptor.Create(n => n, Function(new Dictionary <int, IEnumerable <int> >
            {
                { 0, A(1, 2) },
                { 1, A(3, 4) },
                { 2, EnumerableEx.Throw <int>(new Exception(guid.ToString())) }
            }));

            var enumerator = Graph.DepthFirstTraversal(A(0), descriptor).GetEnumerator();

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(0, enumerator.Current);
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(1, enumerator.Current);
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(3, enumerator.Current);
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(4, enumerator.Current);
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(2, enumerator.Current);
            try
            {
                enumerator.MoveNext();
            }
            catch (Exception e)
            {
                Assert.AreEqual(guid.ToString(), e.Message);
                return;
            }
            Assert.Fail();
        }
示例#2
0
        public static IEnumerable <IGraphDescriptor <T, T> > AllDirectedAcyclicGraphs <T>(IList <T> nodes)
        {
            var E = new Combinations <T>(nodes, 2).Where(e => e.Count == 2).ToList();

            foreach (var F in Enumerable.Range(0, E.Count + 1).SelectMany(k => new Combinations <IList <T> >(E, k)))
            {
                yield return(GraphDescriptor.Create(u => u, Function(F.GroupBy(e => e[0]).ToDictionary(g => g.Key, g => g.Select(e => e[1])))));
            }
        }
示例#3
0
        //------------------------------------------------------------------------------------------------------------------------
        public Graph BuildGraph(GraphDescriptor graphDescriptor)
        {
            lock (locker)
            {
                //check
                if (graphDescriptor == null)
                {
                    DebugEx.Assert("Null detected");
                    return(null);
                }

                //Build Graph
                var builderResult = GraphBuilder.BuildFromDescriptor(GraphManager, graphDescriptor,
                                                                     (bmvType, blockMV) =>
                {
                    // Handle YThing-constructed instantiation
#if NETFX
                    if (typeof(Logic.BaseThings).IsAssignableFrom(bmvType))
#elif UNIVERSAL
                    if (typeof(Logic.BaseThings).GetTypeInfo().IsAssignableFrom(bmvType.GetTypeInfo()))
#endif
                    {
                        //find thing key
                        var thingKey = blockMV.ThingKey;

                        var thing = Node.Things.TryGetOrDefaultReadOnly(thingKey);
                        if (thing == null)
                        {
                            DebugEx.Assert("GenerateGraphFromModelView:: Thing with requested ThingKey" + thingKey + " not found");
                            return(null);
                        }

                        return(bmvType
#if NETFX
                               .GetConstructor(new[] { typeof(Thing) })
#elif UNIVERSAL
                               .GetTypeInfo().DeclaredConstructors.FirstOrDefault(ci => ci.GetParameters().Length == 1 && ci.GetParameters()[0].ParameterType == typeof(Thing))
#endif
                               ?.Invoke(new[] { thing }) as Block);
                    }
                    else
                    {
                        return(null);
                    }
                });

                //Check results
                DebugEx.Assert(builderResult.Graph != null, "Could not build graph");
                return(builderResult.Graph);
            }
        }
示例#4
0
 public GraphDescriptor CreateGraphDecriptor()
 {
     GraphDescriptor descr = new GraphDescriptor(_context);
     return descr;
 }
示例#5
0
        //------------------------------------------------------------------------------------------------------------------------
        public Graph BuildGraph(GraphDescriptor graphDescriptor)
        {
            lock (locker)
            {
                //check
                if (graphDescriptor == null)
                {
                    DebugEx.Assert("Null detected");
                    return null;
                }

                //Build Graph
                var builderResult = GraphBuilder.BuildFromDescriptor(GraphManager, graphDescriptor,
                    (bmvType, blockMV) =>
                    {
                        // Handle YThing-constructed instantiation
#if NETFX
                        if (typeof(Logic.BaseThings).IsAssignableFrom(bmvType))
#elif UNIVERSAL
                        if (typeof(Logic.BaseThings).GetTypeInfo().IsAssignableFrom(bmvType.GetTypeInfo()))
#endif
                        {
                            //find thing key
                            var thingKey = blockMV.ThingKey;

                            var thing = Node.Things.TryGetOrDefaultReadOnly(thingKey);
                            if (thing == null)
                            {
                                DebugEx.Assert("GenerateGraphFromModelView:: Thing with requested ThingKey" + thingKey + " not found");
                                return null;
                            }

                            return bmvType
#if NETFX
                                .GetConstructor(new[] { typeof(Thing) })
#elif UNIVERSAL
                                .GetTypeInfo().DeclaredConstructors.FirstOrDefault(ci => ci.GetParameters().Length == 1 && ci.GetParameters()[0].ParameterType == typeof(Thing))
#endif
                                ?.Invoke(new[] { thing }) as Block;
                        }
                        else
                            return null;
                    });

                //Check results
                DebugEx.Assert(builderResult.Graph != null, "Could not build graph");
                return builderResult.Graph;
            }
        }