Ejemplo n.º 1
0
 public BkwdNCommsGraphBuilder(
     MEAPContext meapContext,
     SortedDictionary <long, LinkedList <long> > nodeToCommoditiesMap,
     long kStep,
     FwdBkwdNCommsGraphPair fwdBkwdNCommsGraphPair)
 {
     this.meapContext          = meapContext;
     this.CPLTMInfo            = meapContext.MEAPSharedContext.CPLTMInfo;
     this.nodeToCommoditiesMap = nodeToCommoditiesMap;
     this.kStep = kStep;
     this.bkwdNestedCommsGraph     = fwdBkwdNCommsGraphPair.BkwdNestedCommsGraph;
     this.bkwdCFGNodeToNCGNodesMap = fwdBkwdNCommsGraphPair.BkwdCFGNodeToNCGNodesMap;
     this.bkwdNCGEdgeToCFGEdgeMap  = fwdBkwdNCommsGraphPair.BkwdNCGEdgeToCFGEdgeMap;
 }
        public void Run()
        {
            log.Info("Creating NCG joint nodes");

            long[] kTapeLRSubseq = CPLTMInfo.KTapeLRSubseq().ToArray();

            for (int i = 0; i < (kTapeLRSubseq.Length - 3); i++)
            {
                long kStep     = kTapeLRSubseq[i];
                long kStepNext = kTapeLRSubseq[i + 1];

                FwdBkwdNCommsGraphPair fwdBkwdNCommsGraphPairL = AppHelper.TakeValueByKey(
                    meapContext.muToNestedCommsGraphPair,
                    kStep,
                    () => new FwdBkwdNCommsGraphPair());

                FwdBkwdNCommsGraphPair fwdBkwdNCommsGraphPairR = AppHelper.TakeValueByKey(
                    meapContext.muToNestedCommsGraphPair,
                    kStepNext,
                    () => new FwdBkwdNCommsGraphPair());

                SortedDictionary <long, SortedSet <long> > nodeVLevels =
                    meapContext.MEAPSharedContext.NodeLevelInfo.NodeVLevels;

                long[] bkwdKStepSequence = CPLTMInfo.BkwdCommsKStepSequence(kStep).ToArray();

                SortedDictionary <long, List <long> > bkwdCFGNodeToNCGNodesMap =
                    fwdBkwdNCommsGraphPairL.BkwdCFGNodeToNCGNodesMap;
                SortedDictionary <long, List <long> > fwdCFGNodeToNCGNodesMap =
                    fwdBkwdNCommsGraphPairR.FwdCFGNodeToNCGNodesMap;

                log.InfoFormat($"building ncg nodes for kStep = {kStep}");

                foreach (long level in bkwdKStepSequence)
                {
                    SortedSet <long> cfgNodesAtLevel = nodeVLevels[level];

                    long ncgJointNodeCount     = 0;
                    long inCommodityNodeCount  = 0;
                    long outCommodityNodeCount = 0;

                    foreach (long cfgNodeId in cfgNodesAtLevel)
                    {
                        NCommsGraphJointNode ncgJointNode = AppHelper.TakeValueByKey(
                            meapContext.CfgNodeIdToNCGJointNode,
                            cfgNodeId,
                            () => new NCommsGraphJointNode());

                        if (bkwdCFGNodeToNCGNodesMap.TryGetValue(cfgNodeId, out List <long>?bkwdCfgNodes))
                        {
                            if (fwdCFGNodeToNCGNodesMap.TryGetValue(cfgNodeId, out List <long>?fwdCfgNodes))
                            {
                                ProcessBkwdFwdNodesLists(
                                    fwdBkwdNCommsGraphPairL,
                                    fwdBkwdNCommsGraphPairR,
                                    bkwdCfgNodes,
                                    fwdCfgNodes,
                                    ncgJointNode);

                                ncgJointNodeCount++;
                                inCommodityNodeCount  += ncgJointNode.InCommodityNodes.Count;
                                outCommodityNodeCount += ncgJointNode.OutCommodityNodes.Count;
                            }
                        }
                    }

                    log.InfoFormat($"level: {level}");
                    log.InfoFormat($"ncg jointNodes count at level: {ncgJointNodeCount}");
                    log.InfoFormat($"InCommodityNodes count at level: {inCommodityNodeCount}");
                    log.InfoFormat($"OutCommodityNodes count at level: {outCommodityNodeCount}");
                }
            }

            log.InfoFormat($"ncg jointNodes count: {meapContext.CfgNodeIdToNCGJointNode.Count}");
            log.InfoFormat($"total InCommodityNodes count: {meapContext.CfgNodeIdToNCGJointNode.Sum(t => t.Value.InCommodityNodes.Count)}");
            log.InfoFormat($"total OutCommodityNodes count: {meapContext.CfgNodeIdToNCGJointNode.Sum(t => t.Value.OutCommodityNodes.Count)}");
        }