Example #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)
            {
                //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;
                    }
                }

                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];
            }
        }
Example #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 = new 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 < 20 || CompareExchange(ref baseline, pipAndDuration, max))
                    {
                        sorted.Add(pipAndDuration);
                        baseline = sorted.Max;

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

            return(sorted);
        }