Esempio n. 1
0
        private bool VerifyGraphSyncData(IEnumerable <NodeModel> nodes)
        {
            GraphSyncData graphSyncdata = syncDataManager.GetSyncData();

            syncDataManager.ResetStates();

            var reExecuteNodesIds = new HashSet <Guid>(
                nodes.Where(n => n.NeedsForceExecution)
                .Select(n => n.GUID));

            if (reExecuteNodesIds.Any())
            {
                for (int i = 0; i < graphSyncdata.ModifiedSubtrees.Count; ++i)
                {
                    var st = graphSyncdata.ModifiedSubtrees[i];
                    if (reExecuteNodesIds.Contains(st.GUID))
                    {
                        Subtree newSt = new Subtree(st.AstNodes, st.GUID);
                        newSt.ForceExecution = true;
                        graphSyncdata.ModifiedSubtrees[i] = newSt;
                    }
                }
            }

            if (graphSyncdata.AddedSubtrees.Any() || graphSyncdata.ModifiedSubtrees.Any() || graphSyncdata.DeletedSubtrees.Any())
            {
                lock (graphSyncDataQueue)
                {
                    graphSyncDataQueue.Enqueue(graphSyncdata);
                }
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public void TestPeriodicUpdate01()
        {
            int    rhs  = 0;
            string code = String.Format("a = {0};", rhs.ToString());

            Guid guid = System.Guid.NewGuid();

            // First run
            // a = 1
            List <Subtree> added = new List <Subtree>();
            Subtree        st    = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, code);

            st.IsInput = true;
            added.Add(st);
            var syncData = new GraphSyncData(null, added, null);

            liverunner.UpdateGraph(syncData);
            instrStreamStart = runtimeDiagnostics.GetExecutableInstructionCount();

            ProtoCore.Mirror.RuntimeMirror mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 0);

            List <Subtree> modified = null;

            const int maxUpdate = 100;

            for (int n = 1; n <= maxUpdate; ++n)
            {
                // Modify a
                code       = String.Format("a = {0};", n.ToString());
                modified   = new List <Subtree>();
                st         = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, code);
                st.IsInput = true;
                modified.Add(st);
                syncData = new GraphSyncData(null, null, modified);
                liverunner.UpdateGraph(syncData);

                instrStreamEnd = runtimeDiagnostics.GetExecutableInstructionCount();
                Assert.AreEqual(instrStreamStart, instrStreamEnd);
            }

            mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 100);
        }
Esempio n. 3
0
        public void TestInstructionStreamMemory_FunctionRedefinition01()
        {
            List <string> codes = new List <string>()
            {
                "def f() {return = 1;}",
                "a = f();",
                "def f() {return = 2;}"
            };

            Guid guid1 = System.Guid.NewGuid();
            Guid guid2 = System.Guid.NewGuid();

            // First run
            List <Subtree> added = new List <Subtree>();
            Subtree        st    = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[0]);

            added.Add(st);

            st = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[1]);
            added.Add(st);

            var syncData = new GraphSyncData(null, added, null);

            liverunner.UpdateGraph(syncData);
            instrStreamStart = runtimeDiagnostics.GetExecutableInstructionCount();

            ProtoCore.Mirror.RuntimeMirror mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 1);

            // Modify function
            List <Subtree> modified = new List <Subtree>();

            st = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[2]);
            modified.Add(st);
            syncData = new GraphSyncData(null, null, modified);
            liverunner.UpdateGraph(syncData);
            instrStreamEnd = runtimeDiagnostics.GetExecutableInstructionCount();

            mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 2);

            Assert.AreEqual(instrStreamStart, instrStreamEnd);
        }
Esempio n. 4
0
        public override void Add(TreeAssignment item)
        {
            ITree last    = _leaf;
            var   current = _leaf.OwnerSubtreeForOne ?? _leaf.OwnerSubtreeForZero;

            while (current != null)
            {
                if (current.Port == item.Port)
                {
                    if ((current.TreeForOne == last && item.Value) || (current.TreeForZero == last && !item.Value))
                    {
                        return;
                    }
                    ChangeAssignment(current, item);
                }
                last    = current;
                current = current.OwnerSubtreeForOne ?? current.OwnerSubtreeForZero;
            }

            var ownerForOne  = _leaf.OwnerSubtreeForOne;
            var ownerForZero = _leaf.OwnerSubtreeForZero;
            var ownerBdd     = _leaf.OwnerBDD;

            var subTree = new Subtree()
            {
                Port = item.Port,
            };

            if (item.Value)
            {
                subTree.TreeForOne = _leaf;
            }
            else
            {
                subTree.TreeForZero = _leaf;
            }

            subTree.OwnerSubtreeForOne  = ownerForOne;
            subTree.OwnerSubtreeForZero = ownerForZero;
            subTree.OwnerBDD            = ownerBdd;
        }
Esempio n. 5
0
        public void TestInstructionStreamMemory_SimpleWorkflow01()
        {
            List <string> codes = new List <string>()
            {
                "a = 1;",
                "a = 2;"
            };

            Guid guid = System.Guid.NewGuid();

            // First run
            // a = 1
            List <Subtree> added = new List <Subtree>();
            Subtree        st    = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[0]);

            st.IsInput = true;
            added.Add(st);
            var syncData = new GraphSyncData(null, added, null);

            liverunner.UpdateGraph(syncData);
            instrStreamStart = runtimeDiagnostics.GetExecutableInstructionCount();

            ProtoCore.Mirror.RuntimeMirror mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 1);

            // Modify
            // a = 2
            List <Subtree> modified = new List <Subtree>();

            st         = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[1]);
            st.IsInput = true;
            modified.Add(st);
            syncData = new GraphSyncData(null, null, modified);
            liverunner.UpdateGraph(syncData);
            instrStreamEnd = runtimeDiagnostics.GetExecutableInstructionCount();

            mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 2);

            Assert.AreEqual(instrStreamStart, instrStreamEnd);
        }
Esempio n. 6
0
        private bool VerifyGraphSyncData(IEnumerable <NodeModel> nodes)
        {
            GraphSyncData data = syncDataManager.GetSyncData();

            syncDataManager.ResetStates();

            var reExecuteNodesIds = new HashSet <Guid>(
                nodes.Where(n => n.ForceReExecuteOfNode)
                .Select(n => n.GUID));

            if (reExecuteNodesIds.Any() && data.ModifiedSubtrees != null)
            {
                for (int i = 0; i < data.ModifiedSubtrees.Count; ++i)
                {
                    var st = data.ModifiedSubtrees[i];
                    if (reExecuteNodesIds.Contains(st.GUID))
                    {
                        var newSt = new Subtree(st.AstNodes, st.GUID)
                        {
                            ForceExecution = true
                        };
                        data.ModifiedSubtrees[i] = newSt;
                    }
                }
            }

            if ((data.AddedSubtrees != null && data.AddedSubtrees.Count > 0) ||
                (data.ModifiedSubtrees != null && data.ModifiedSubtrees.Count > 0) ||
                (data.DeletedSubtrees != null && data.DeletedSubtrees.Count > 0))
            {
                lock (graphSyncDataQueue)
                {
                    graphSyncDataQueue.Enqueue(data);
                }
                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        private bool VerifyGraphSyncData()
        {
            GraphSyncData data = syncDataManager.GetSyncData();

            syncDataManager.ResetStates();

            var reExecuteNodesIds = dynamoModel.HomeSpace.Nodes
                                    .Where(n => n.ForceReExecuteOfNode)
                                    .Select(n => n.GUID);

            if (reExecuteNodesIds.Any() && data.ModifiedSubtrees != null)
            {
                for (int i = 0; i < data.ModifiedSubtrees.Count; ++i)
                {
                    var st = data.ModifiedSubtrees[i];
                    if (reExecuteNodesIds.Contains(st.GUID))
                    {
                        Subtree newSt = new Subtree(st.AstNodes, st.GUID);
                        newSt.ForceExecution     = true;
                        data.ModifiedSubtrees[i] = newSt;
                    }
                }
            }

            if ((data.AddedSubtrees != null && data.AddedSubtrees.Count > 0) ||
                (data.ModifiedSubtrees != null && data.ModifiedSubtrees.Count > 0) ||
                (data.DeletedSubtrees != null && data.DeletedSubtrees.Count > 0))
            {
                lock (graphSyncDataQueue)
                {
                    graphSyncDataQueue.Enqueue(data);
                }
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
        public override void Add(ILeaf item)
        {
            ITree current     = item;
            var   assignments = new Dictionary <IInputPort, bool>();
            var   treeStack   = new Stack <ISubtree>();

            while (current != null)
            {
                if (current.OwnerSubtreeForOne != null)
                {
                    assignments.Add(current.OwnerSubtreeForOne.Port, true);
                    treeStack.Push(current.OwnerSubtreeForOne);
                    current = current.OwnerSubtreeForOne;
                }
                else if (current.OwnerSubtreeForZero != null)
                {
                    assignments.Add(current.OwnerSubtreeForZero.Port, false);
                    treeStack.Push(current.OwnerSubtreeForZero);
                    current = current.OwnerSubtreeForZero;
                }
                else
                {
                    if (_bdd.Tree == null)
                    {
                        _bdd.Tree = current;
                        return;
                    }
                    break;
                }
            }

            current = _bdd.Tree;
            while (current != null)
            {
                if (current is ISubtree subTree)
                {
                    if (assignments.TryGetValue(subTree.Port, out var assignedValue))
                    {
                        if (assignedValue)
                        {
                            current = subTree.TreeForOne;
                        }
                        else
                        {
                            current = subTree.TreeForZero;
                        }
                        if (treeStack != null && treeStack.Pop().Port != subTree.Port)
                        {
                            treeStack = null;
                        }
                        assignments.Remove(subTree.Port);
                        if (current == null)
                        {
                            if (treeStack != null)
                            {
                                ITree value = treeStack.Count > 0 ? treeStack.Pop() as ITree : item;
                                if (assignedValue)
                                {
                                    subTree.TreeForOne = value;
                                }
                                else
                                {
                                    subTree.TreeForZero = value;
                                }
                            }
                            else
                            {
                                ITree value = item;
                                foreach (var assignment in assignments)
                                {
                                    var tempTree = new Subtree()
                                    {
                                        Port = assignment.Key
                                    };
                                    if (assignment.Value)
                                    {
                                        tempTree.TreeForOne = value;
                                    }
                                    else
                                    {
                                        tempTree.TreeForZero = value;
                                    }
                                    value = tempTree;
                                }
                                if (assignedValue)
                                {
                                    subTree.TreeForOne = value;
                                }
                                else
                                {
                                    subTree.TreeForZero = value;
                                }
                            }
                            return;
                        }
                    }
                    else
                    {
                        // the new child will dominate all existing ones
                        if (treeStack != null && treeStack.Count > 0)
                        {
                            var ownerForZero = subTree.OwnerSubtreeForZero;
                            var ownerForOne  = subTree.OwnerSubtreeForOne;
                            var ownerBdd     = subTree.OwnerBDD;
                            var peek         = treeStack.Peek();
                            if (peek.TreeForZero == null)
                            {
                                peek.TreeForZero = subTree;
                            }
                            else if (peek.TreeForOne == null)
                            {
                                peek.TreeForOne = subTree;
                            }
                            // we need to be careful not to accidently delete peek
                            if (ownerForOne != null)
                            {
                                peek.OwnerSubtreeForOne = ownerForOne;
                            }
                            else if (ownerForZero != null)
                            {
                                peek.OwnerSubtreeForZero = ownerForZero;
                            }
                            else if (ownerBdd != null)
                            {
                                peek.OwnerBDD = ownerBdd;
                            }
                            return;
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }
                    }
                }
            }
        }
Esempio n. 9
0
 public override void Execute(object args)
 {
     Subtree.Load();
     //System.Threading.Thread.Sleep(400);
 }
        public static List<PNode> FindIndependentTrees(PNode original)
        {
            List<Subtree> subtrees = new List<Subtree>();

            PVNode parent = original.Children.First();

            foreach (PNode pnode in parent.Children)
            {
                //Console.Write("{0}: ", pnode.Id);

                HashSet<string> participants = new HashSet<string>();
                participants.Add(pnode.Id);

                GetParticipants(pnode, participants);

                bool newSubtreeNeeded = true;
                foreach (Subtree subtree in subtrees)
                {
                    if (subtree.HasOverlap(participants))
                    {
                        subtree.Roots.Add(pnode);
                        newSubtreeNeeded = false;
                        break;
                    }
                }

                if (newSubtreeNeeded)
                {
                    Subtree newSubtree = new Subtree();
                    newSubtree.Roots.Add(pnode);

                    foreach (string s in participants)
                    {
                        newSubtree.Participants.Add(s);
                    }

                    subtrees.Add(newSubtree);
                }

                //foreach (string participant in participants)
                //{
                //    Console.Write("{0} ", participant);
                //}
                //Console.WriteLine();
            }

            List<PNode> result = new List<PNode>();

            foreach (Subtree subtree in subtrees)
            {
                PNode newRoot = new PNode("$");
                PVNode newRootVersion = new PVNode(new SemanticVersion(0));
                newRoot.Children.Add(newRootVersion);

                foreach (PNode newRootChild in subtree.Roots)
                {
                    newRootVersion.AddChild(newRootChild);
                }

                result.Add(newRoot);
            }

            return result;
        }
Esempio n. 11
0
                    private unsafe void parseRawData(byte[] rawData)
                    {
#if UNITYPIC_DEBUG
                        if (IsLoaded)
                        {
                            throw new Exception("Subtree already loaded.");
                        }
#endif

                        string directoryPrefix = Potree.DataDirectory + SubDirectory + FileNamePrefix;

                        fixed(byte *ptr = rawData)
                        {
                            HRCByte *hrcData   = (HRCByte *)ptr;
                            int      nodeCount = rawData.Length / sizeof(HRCByte);

                            Queue <NodeType> q = new Queue <NodeType>(nodeCount);

                            q.Enqueue(Root);

                            int i,
                                qCount,
                                hrcDataIndex = 0,
                                depth        = 0;

                            Vector3 center, min;
                            Subtree subtree;
                            string  localName;

                            Vector3 extents = Root.Extents;
                            float   spacing = Root.Spacing;

                            NodeType current, child;


                            while (depth++ < 5)
                            {
                                spacing   *= 0.5f;
                                extents.x *= 0.5f;
                                extents.y *= 0.5f;
                                extents.z *= 0.5f;

                                qCount = q.Count;

                                while (qCount-- > 0)
                                {
                                    current = q.Dequeue();

                                    current.DescendantMask = hrcData[hrcDataIndex].Mask;
                                    current.PointCount     = hrcData[hrcDataIndex].Count;

                                    if (current.PointCount == 0)
                                    {
                                        current.PointCount          = (int)(new FileInfo(directoryPrefix + current.LocalName + Constants.BinExt)).Length / Potree.PointStride;
                                        hrcData[hrcDataIndex].Count = current.PointCount;
                                    }

                                    ++hrcDataIndex;

                                    min.x = current.Center.x - current.Extents.x;
                                    min.y = current.Center.y - current.Extents.y;
                                    min.z = current.Center.z - current.Extents.z;

                                    current.Children = new NodeType[8];

                                    for (i = 0; i < 8; ++i)
                                    {
                                        current.Children[i] = new NodeType();
                                        child = current.Children[i];

                                        center = new Vector3()
                                        {
                                            x = (((i >> (2 - Constants.XAxisIndex)) & 1) + 0.5f) * 2 * extents.x + min.x,
                                            y = (((i >> (2 - Constants.YAxisIndex)) & 1) + 0.5f) * 2 * extents.y + min.y,
                                            z = (((i >> (2 - Constants.ZAxisIndex)) & 1) + 0.5f) * 2 * extents.z + min.z,
                                        };

                                        localName = current.LocalName + (char)('0' + i);

                                        if ((current.DescendantMask & (1 << i)) == 0)
                                        {
                                            // ghost node;
                                            subtree          = this;
                                            child.PointCount = -1;
                                        }
                                        else if (current.LocalName.Length == Potree.Info.StepSize - 1)
                                        {
                                            // nodes on depth = root.depth + 5;
                                            subtree                = new Subtree();
                                            subtree.Potree         = Potree;
                                            subtree.Root           = child;
                                            subtree.SubDirectory   = SubDirectory + localName + '/';
                                            subtree.FileNamePrefix = FileNamePrefix + localName;
                                            localName              = "";
                                        }
                                        else
                                        {
                                            // nodes on depth < root.depth + 5;
                                            subtree = this;
                                            q.Enqueue(child);
                                        }

                                        child.Parent    = current;
                                        child.Subtree   = subtree;
                                        child.LocalName = localName;
                                        child.Center    = center;
                                        child.Extents   = extents;
                                        child.Spacing   = current.Spacing * 0.5f;
                                        child.Depth     = (byte)(current.Depth + 1);
                                        child.OctantId  = (byte)i;
                                    }
                                }
                            }

                            if (Root.PointCount == 0 && Root.IsLeaf)
                            {
                                //Debug.Log("Found");
                            }
                        }
                    }