コード例 #1
0
        private void unfoldAndOptimizeAndStore(IList <RewriteTreeElement> rewriteTreeElementsFromRootToChildrens)
        {
            RewriteTreeElement lastChildrenRewriteTreeElement = rewriteTreeElementsFromRootToChildrens[rewriteTreeElementsFromRootToChildrens.Count - 1];

            // we have to copy because CausalSetNodeFuser.fuse() modifies the argument
            CausalSetSystemBlock modifiedRootSystemBlock = unmodifiedRootSystemBlock.copyShallow();

            CausalSetSystemBlock currentTopBlock = unmodifiedRootSystemBlock;

            for (int rewriteChainIndex = 0; rewriteChainIndex < rewriteTreeElementsFromRootToChildrens.Count(); rewriteChainIndex++)
            {
                RewriteTreeElement iterationRewriteTreeElement = rewriteTreeElementsFromRootToChildrens[rewriteChainIndex];

                CausalSetSystemBlock modifiedParent;
                CausalSetSystemBlock afterFusion = CausalSetNodeFuser.fuse(currentTopBlock, out modifiedParent, iterationRewriteTreeElement.indicesOfParentNodesForRewrite.ToList());

                currentTopBlock = afterFusion;
            }


            // linearize and calculate energy, store back to tree (in the children)
            IList <uint> globalLinearized = linearizer.linearize(modifiedRootSystemBlock, /*recursive*/ true);

            lastChildrenRewriteTreeElement.globalLinearized = GlobalLinearization.make(linearizer.linearize(modifiedRootSystemBlock, /*recursive*/ true));
            Debug.Assert(lastChildrenRewriteTreeElement.globalLinearized.linearization.Count == unmodifiedRootSystemBlock.nodes.Count);

            //  calculate global energy
            lastChildrenRewriteTreeElement.globalEnergyAfterRewrite = calculateEnergy(lastChildrenRewriteTreeElement.globalLinearized, modifiedRootSystemBlock);
        }
コード例 #2
0
        void buildRewriteTreeRecursive(RewriteTreeElement parentRewriteTreeElement, CausalSetSystemBlock recursedSystemBlock)
        {
            uint rewriteRounds = 1; // for now we just do one rewrite for testing

            for (uint rewriteRound = 0; rewriteRound < rewriteRounds; rewriteRound++)
            {
                uint fuseEntryIndex = (uint)random.Next(recursedSystemBlock.nodes.Count);

                RewriteTreeElement rewriteTreeElementAfterRewrite = new RewriteTreeElement();
                rewriteTreeElementAfterRewrite.indicesOfParentNodesForRewrite = recursedSystemBlock.getRandomFollowerAsEnumerable(fuseEntryIndex, terminationPropability);

                // rewrite
                rewriteTreeElementAfterRewrite.blockAfterRewrite = CausalSetNodeFuser.fuse(recursedSystemBlock, out recursedSystemBlock, rewriteTreeElementAfterRewrite.indicesOfParentNodesForRewrite.ToList());

                parentRewriteTreeElement.childrenRewrites.Add(rewriteTreeElementAfterRewrite);
            }
        }