Пример #1
0
        public void AddLocCvgToMap()
        {
            //aggregate losses from children
            for (int cIdx = 0; cIdx < this.m_vChildNode.Count; ++cIdx)
            {
                TermNode child = (TermNode)this.m_vChildNode[cIdx];
                child.AddLocCvgToMap();
            }

            _Schedule sar = this.m_subject.Schedule;

            if (sar.SetSchedule.Count > 0)
            {
                foreach (RiskItem riskItem in sar.SetSchedule)
                {
                    if (riskItem is LocationCvg)
                    {
                        if (!MapIntIdToRit.ContainsKey(riskItem.IntId))
                        {
                            MapIntIdToRit.Add(riskItem.IntId, riskItem);
                        }
                    }
                }
            }

            return;
        }
Пример #2
0
 public override bool Overlaps(Node n)
 {
     if (n is TermNode)
     {
         TermNode tn = (TermNode)n;
         return(base.Subject.Overlaps(tn.Subject));
     }
     else
     {
         //should just return false?
         throw new Exception("nodes are not of same type for proper subset comparison");
     }
 }
Пример #3
0
        public string BuildXMLRepresentationRecurse(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];
                tree_xml += "\n<child" + " id = \"" + child.IntId.ToString() + "\">\n" + child.BuildXMLRepresentationRecurse(cdlMsg, bDebug) + "\n</child>\n";

                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));
                }
            }

            _Schedule sar = this.m_subject.Schedule;

            if (sar.SetSchedule.Count > 0)
            {
                string leaf = "";
                foreach (RiskItem riskItem in sar.SetSchedule)
                {
                    if (riskItem is LocationCvg)
                    {
                        string newLeaf = riskItem.IntId.ToString().PadLeft(2, '0');
                        for (int n1 = 0; n1 < tree_xml.Length / 2; n1++)
                        {
                            if (newLeaf.Equals(tree_xml.Substring(n1 * 2, 2))) //no need to add twice
                            {
                                newLeaf = "";
                            }
                        }

                        leaf += newLeaf;
                    }
                }

                if (leaf.Length > 0)
                {
                    tree_xml += leaf;
                }
            }

            return(tree_xml);
        }
Пример #4
0
        public void SearchUpTreeRecursive(T node, T nodeToAdd)
        {
            TermNode tn = node as TermNode;

            if (!tn.Visited)
            {
                tn.Visited = true;
                if (nodeToAdd.IsProperSubsetTo(node))
                {//hang node
                    node.AddChildNode(nodeToAdd);
                    nodeToAdd.AddParentNode(node);
                    SetPathToRootVisited(node);
                }
                else if (node.IsProperSubsetTo(nodeToAdd))
                {//insert node
                }
            }
        }
Пример #5
0
        //public ENUM_TERM_NODE_TYPE EnumTermNodeType
        //{
        //    get { return this.m_enumTermNodeType; }
        //    set { this.m_enumTermNodeType = value; }
        //}
        #endregion

        public int CompareTo(object obj)
        {
            if (this == obj)
            {
                return(0);
            }

            if (obj is TermNode)
            {
                TermNode tnComp = (TermNode)obj;

                if (this.m_prelimReSar == tnComp.PrelimReSar)
                {
                    double thisLossState = this.GetLossState();
                    double compLossState = tnComp.GetLossState();

                    if (thisLossState == compLossState)
                    {
                        return(this.m_intId > tnComp.IntId ? 1 : -1);
                    }
                    else
                    {
                        return(thisLossState > compLossState ? 1 : -1);
                    }
                }
                else
                {
                    return(this.m_prelimReSar > tnComp.PrelimReSar ? 1 : -1);
                }
            }
            else
            {
                //do we need to throw an exception here?
                return(0);
            }
        }
Пример #6
0
        public virtual void DetermineSubjectsAtRisk()
        {
            for (int cIdx = 0; cIdx < this.m_vChildNode.Count; ++cIdx)
            {
                TermNode child = (TermNode)this.m_vChildNode[cIdx];

                child.DetermineSubjectsAtRisk();

                List <int> vChildSarId = child.vSarId;
                for (int sIdx = 0; sIdx < vChildSarId.Count; ++sIdx)
                {
                    this.AddSarId(vChildSarId[sIdx]);
                }
            }

            _Schedule schedule = this.m_subject.Schedule;

            IList vLocCvg = schedule.SetSchedule.Where(riskItem => riskItem is LocationCvg).ToList();

            foreach (LocationCvg lcvg in vLocCvg)
            {
                this.AddSarId(lcvg.LocationExtnId);
            }
        }
Пример #7
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));
            }
        }
Пример #8
0
        public override void CalculateLoss(SimulationMsg cdlMsg, bool bDebug)
        {
            //process children node payouts.
            for (int cIdx = 0; cIdx < base.m_vChildNode.Count; ++cIdx)
            {
                CoverNode cn = (CoverNode)base.m_vChildNode[cIdx];
                cn.CalculateLoss(cdlMsg, bDebug);
            }

            List <CalcState> vResolvedCalcState = new List <CalcState>();
            _Schedule        sar = this.m_subject.Schedule;

            foreach (RiskItem riskItem in sar.SetSchedule)
            {
                if (riskItem is ReinCoverNode)
                {
                    this.m_calcState.S += riskItem.GetLossState();
                }
                else
                {
                    if (this.m_resolution != ENUM_RESOLUTION_TYPE.NONE)
                    {
                        //each resolved risk item is effectively treated as a subcover to the current cover
                        List <RiskItem> vResolvedRiskItem = ApplyResolution(riskItem, this.m_resolution);

                        #region debug output
                        if (bDebug)
                        {
                            cdlMsg.SendMessage(string.Format("RiskItems resolved for ReinCoverNode: \r\n{0}", riskItem));
                            for (int rIdx = 0; rIdx < vResolvedRiskItem.Count; ++rIdx)
                            {
                                cdlMsg.SendMessage(string.Format("\t{0}", vResolvedRiskItem[rIdx]));
                            }
                        }
                        #endregion

                        //temporary calculation state for the resolved risk items.
                        //RMS.ContractObjectModel.CalcState resCalcState = new CalcState();

                        for (int rIdx = 0; rIdx < vResolvedRiskItem.Count; ++rIdx)
                        {
                            RiskItem resRiskItem = vResolvedRiskItem[rIdx];

                            RMS.ContractObjectModel.CalcState calcState = new CalcState();

                            //reinsurance cover operating on allocated loss
                            switch (base.m_contract.AllocType)
                            {
                            case ENUM_ALLOCATION_TYPE.ALLOC_TYPE_PROPORTIONAL:
                                calcState.S = Math.Min(resRiskItem.GetLossState(), resRiskItem.GetAllocLossState());
                                break;

                            case ENUM_ALLOCATION_TYPE.ALLOC_TYPE_PERRISK:
                                calcState.S = resRiskItem.GetAllocLossState();
                                break;

                            case ENUM_ALLOCATION_TYPE.ALLOC_TYPE_NONE:
                                calcState.S = resRiskItem.GetLossState();
                                break;
                            }

                            double prelimReSar = DetermineCoverPayout(calcState);
                            if (resRiskItem is TermNode)
                            {
                                TermNode resTermNode = (TermNode)resRiskItem;
                                resTermNode.PrelimReSar = prelimReSar;
                            }

                            //this.m_calcState.S += prelimReSar;

                            this.m_payout += prelimReSar;

                            //resCalcState.S += prelimReSar;

                            //resCalcState.S += calcState.S;
                            //resCalcState.D += calcState.D;
                            //resCalcState.X += calcState.X;
                        }

                        //this.m_calcState.S += resCalcState.S;
                        //this.m_calcState.D += resCalcState.D;
                        //this.m_calcState.X += resCalcState.X;
                    }
                    else
                    {
                        switch (base.m_contract.AllocType)
                        {
                        case ENUM_ALLOCATION_TYPE.ALLOC_TYPE_PROPORTIONAL:
                            this.m_calcState.S = Math.Min(riskItem.GetLossState(), riskItem.GetAllocLossState());
                            break;

                        case ENUM_ALLOCATION_TYPE.ALLOC_TYPE_PERRISK:
                            this.m_calcState.S = riskItem.GetAllocLossState();
                            break;

                        case ENUM_ALLOCATION_TYPE.ALLOC_TYPE_NONE:
                            this.m_calcState.S = riskItem.GetLossState();
                            break;
                        }
                        ;
                    }
                }
            }

            if (this.m_resolution == ENUM_RESOLUTION_TYPE.NONE)
            {
                this.m_payout += DetermineCoverPayout(this.m_calcState);
            }
        }