Пример #1
0
        public override void CalculateLoss(SimulationMsg cdlMsg, bool bDebug)
        {
            if (bDebug)
            {
                cdlMsg.SendMessage(string.Format("Calculate Loss TermNode: intId={0}, begin {1}", this.m_intId, this.CalcState));
            }

            //aggregate losses from children
            for (int cIdx = 0; cIdx < this.m_vChildNode.Count; ++cIdx)
            {
                TermNode child = (TermNode)this.m_vChildNode[cIdx];
                child.CalculateLoss(cdlMsg, bDebug);

                if (bDebug)
                {
                    cdlMsg.SendMessage(string.Format("For TermNode: intId={0} initial {1}, Adding Child TermNode: intId={2}, {3}",
                                                     this.m_intId, this.m_calcState, child.IntId, child.CalcState));
                }
            }


            if (BucketList != null)
            {
                List <int> overlapBuckets = new List <int>();
                for (int b0 = 0; b0 < bucketList.Count; b0++)
                {
                    List <int> bucket = bucketList[b0];
                    for (int b1 = 0; b1 < bucket.Count - 1; b1++)
                    {
                        for (int b2 = 1; b2 < bucket.Count; b2++)
                        {
                            if (IsOverlap(bucket[b1], bucket[b2]))
                            {
                                if (!overlapBuckets.Contains(b0))
                                {
                                    overlapBuckets.Add(b0);
                                }
                            }
                        }
                    }
                }

                foreach (int ob in overlapBuckets)
                {
                    BucketList.Remove(bucketList[ob]);
                }

                int         b = 0;
                CalcState[] calcStateArray = new CalcState[BucketList.Count];

                foreach (List <int> bucket in BucketList)
                {
                    calcStateArray[b]   = new CalcState();
                    calcStateArray[b].X = 0;
                    calcStateArray[b].S = 0;
                    calcStateArray[b].D = 0;

                    foreach (int intId in bucket)
                    {
                        if (MapIntIdToNode.ContainsKey(intId))
                        {
                            TermNode  tn  = MapIntIdToNode[intId];
                            _Schedule sar = tn.Subject.Schedule;
                            foreach (RiskItem riskItem in sar.SetSchedule)
                            {
                                calcStateArray[b].X += riskItem.CalcState.X;
                                calcStateArray[b].S += riskItem.CalcState.S;
                                calcStateArray[b].D += riskItem.CalcState.D;
                            }
                        }
                        else if (MapIntIdToRit.ContainsKey(intId))
                        {
                            RiskItem ri = MapIntIdToRit[intId];
                            calcStateArray[b].X += ri.CalcState.X;
                            calcStateArray[b].S += ri.CalcState.S;
                            calcStateArray[b].D += ri.CalcState.D;
                        }
                    }

                    foreach (TermObject termObj in this.m_sortTermObj)
                    {
                        termObj.ApplyTermObject(calcStateArray[b]);
                    }

                    b++;
                }

                this.m_calcState = FindWinningBucket(calcStateArray, BucketList);
            }
            else
            {
                _Schedule sar = this.m_subject.Schedule;
                foreach (RiskItem riskItem in sar.SetSchedule)
                {
                    this.m_calcState.X += riskItem.CalcState.X;
                    this.m_calcState.S += riskItem.CalcState.S;
                    this.m_calcState.D += riskItem.CalcState.D;
                }

                //apply term objects to the term node..
                foreach (TermObject termObj in this.m_sortTermObj)
                {
                    termObj.ApplyTermObject(this.m_calcState);
                }
            }


            if (bDebug)
            {
                cdlMsg.SendMessage(string.Format("Calculate Loss TermNode: intId={0}, final {1}", this.m_intId, this.CalcState));
            }
        }