Esempio n. 1
0
        public void ComputeAggregateCosts()
        {
            PipAndPriority maxPipAndPriority = default(PipAndPriority);
            List <NodeId>  sortedNodes       = new List <NodeId>();

            sortedNodes.AddRange(DataflowGraph.Nodes);
            sortedNodes.Sort((n1, n2) => DataflowGraph.GetNodeHeight(n1).CompareTo(DataflowGraph.GetNodeHeight(n2)));
            foreach (var node in sortedNodes)
            {
                ulong aggregateCost = 0;
                foreach (var incoming in DataflowGraph.GetIncomingEdges(node))
                {
                    BottomUpAggregateCosts[incoming.OtherNode].Max(ref aggregateCost);
                }

                aggregateCost += Durations[node];
                BottomUpAggregateCosts[node] = aggregateCost;
            }

            sortedNodes.Sort((n1, n2) => - DataflowGraph.GetNodeHeight(n1).CompareTo(DataflowGraph.GetNodeHeight(n2)));
            foreach (var node in sortedNodes)
            {
                // int maxConeConcurrency = 0;
                ulong  aggregateCost = 0, constrainedAggregateCost = 0;
                NodeId maxChild = NodeId.Invalid;
                foreach (var outgoing in DataflowGraph.GetOutgoingEdges(node))
                {
                    ConstrainedAggregateCosts[outgoing.OtherNode].Max(ref constrainedAggregateCost);

                    if (AggregateCosts[outgoing.OtherNode].Max(ref aggregateCost) || !maxChild.IsValid)
                    {
                        maxChild = outgoing.OtherNode;
                    }
                }

                FormattedSemistableHashes[node] = CachedGraph.PipTable.GetFormattedSemiStableHash(node.ToPipId());
                aggregateCost       += Durations[node];
                AggregateCosts[node] = aggregateCost;
                aggregateCost.Max(ref MaxAggregateCost);
                CriticalChain[node] = maxChild;

                new PipAndPriority
                {
                    Node     = node,
                    Priority = aggregateCost,
                }.Max(ref maxPipAndPriority);
            }

            CriticalPathHeadNode = maxPipAndPriority.Node;

            NodeId criticalChainNode = CriticalPathHeadNode;

            while (criticalChainNode.IsValid)
            {
                CriticalPath.Add(criticalChainNode);
                criticalChainNode = CriticalChain[criticalChainNode];
            }
        }
Esempio n. 2
0
        public SortedSet <PipAndPriority> GetSortedPips(int count, bool max, Func <NodeId, bool> selector, Func <NodeId, ulong> getPriority)
        {
            Comparer <PipAndPriority> comparer = Comparer <PipAndPriority> .Default;

            if (max)
            {
                comparer = Comparer <PipAndPriority> .Create((p1, p2) => p2.CompareTo(p1));
            }

            var sorted   = new SortedSet <PipAndPriority>(comparer);
            var baseline = default(PipAndPriority);

            if (!max)
            {
                baseline.Priority = ulong.MaxValue;
            }

            foreach (var node in DataflowGraph.Nodes)
            {
                if (selector(node))
                {
                    var pipAndDuration = new PipAndPriority()
                    {
                        Node     = node,
                        Priority = getPriority(node),
                    };

                    if (sorted.Count < count || CompareExchange(ref baseline, pipAndDuration, max))
                    {
                        sorted.Add(pipAndDuration);
                        baseline = sorted.Max;

                        if (sorted.Count > count)
                        {
                            sorted.Remove(baseline);
                            baseline = sorted.Max;
                        }
                    }
                }
            }

            return(sorted);
        }