Exemplo n.º 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);
        }
Exemplo n.º 2
0
        void buildTree(CausalSetSystemBlock entryBlock)
        {
            // store it for later reference for calculating the global energy
            unmodifiedRootSystemBlock = entryBlock;

            rootRewriteTreeElement = new RewriteTreeElement();
            buildRewriteTreeRecursive(rootRewriteTreeElement, entryBlock.copyDeep());
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        private void getBestGlobalLinearizationAndEnergyRecursive(RewriteTreeElement entry, ref long minimalEnergy, ref GlobalLinearization linearization)
        {
            if (entry != rootRewriteTreeElement)
            {
                Ensure.ensureHard(entry.globalLinearized != null);
                if (entry.globalEnergyAfterRewrite < minimalEnergy)
                {
                    minimalEnergy = entry.globalEnergyAfterRewrite;
                    linearization = entry.globalLinearized;
                }
            }

            foreach (RewriteTreeElement iterationChildren in entry.childrenRewrites)
            {
                getBestGlobalLinearizationAndEnergyRecursive(iterationChildren, ref minimalEnergy, ref linearization);
            }
        }
Exemplo n.º 5
0
        private IEnumerable <RewriteTreeElement> getRewriteTreeElementsFromParentsToRoot(RewriteTreeElement startParent)
        {
            IList <RewriteTreeElement> result = new List <RewriteTreeElement>();

            RewriteTreeElement currentElement = startParent;

            for (;;)
            {
                if (currentElement == null)
                {
                    break;
                }

                result.Add(currentElement);

                currentElement = currentElement.parent;
            }

            return(result);
        }
Exemplo n.º 6
0
        private void calcEntropyOfAllElementsInTreeRecursive(RewriteTreeElement rewriteTreeElement)
        {
            // calculate energy, of the whole permutation described by rewriteTreeElement and store the best found global linearization and the corresponding energy
            {
                IEnumerable <RewriteTreeElement> pathFromIterationChildrenToParentToRoot = getRewriteTreeElementsFromParentsToRoot(rewriteTreeElement);
                IEnumerable <RewriteTreeElement> pathFromRootToIterationChildren         = pathFromIterationChildrenToParentToRoot.Reverse();

                Debug.Assert(pathFromRootToIterationChildren.Count() > 0);
                // if we are at the RewriteTreeElement which describes the root then we can't calculate the entropy because there is no permutation
                if (rewriteTreeElement != rootRewriteTreeElement)
                {
                    unfoldAndOptimizeAndStore(pathFromRootToIterationChildren.ToList());
                }
            }

            foreach (RewriteTreeElement iteratorChildren in rewriteTreeElement.childrenRewrites)
            {
                calcEntropyOfAllElementsInTreeRecursive(iteratorChildren);
            }
        }