Exemple #1
0
        public void TermFunction(InteractionObject[] IntObject)
        {
            int NumBldgs = CurrNode.CurrentLossStateCollection.NumBldgs;

            int intObjCount = IntObject.Count();
            DeductibleCollection sortedDeductibles = CurrNode.Deductibles.SortByExecOrder(CurrNode.Deductibles);

            //initialize
            for (int i = 0; i < NumBldgs; i++)
            {
                if (intObjCount > 0)
                {
                    CurrNode.CurrentLossStateCollection.collection[i].X = IntObject[i].ExcessFromChildren;
                    CurrNode.CurrentLossStateCollection.collection[i].D = IntObject[i].DedFromChildren;
                }
                else
                {
                    CurrNode.CurrentLossStateCollection.collection[i].X = 0;
                    CurrNode.CurrentLossStateCollection.collection[i].D = 0;
                }
            }

            //Do Ground-up sub-Limit first
            foreach (Limit limObj in CurrNode.Limits)
            {
                if (limObj.LimitIsNetOfDed == false)
                {
                    double limitTot = 0;
                    if (limObj.LimType == TermValueType.Numeric)
                    {
                        limitTot = limObj.Amount;
                    }
                    else if (limObj.LimType == TermValueType.PercentCovered)
                    {
                        limitTot = limObj.Amount / 100 * CurrNode.GetTIV();
                    }
                    else if (limObj.LimType == TermValueType.PercentAffected)
                    {
                        limitTot = limObj.Amount / 100 * CurrNode.GetAffectedTIV();
                    }
                    else if (limObj.LimType == TermValueType.PercentLoss)
                    {
                        limitTot = limObj.Amount / 100 * CurrNode.CurrentLossStateCollection.GetTotalSum.S;
                    }
                    else
                    {
                        throw new InvalidOperationException("Lim TermValueType is not Known");
                    }

                    double limit = limitTot;
                    for (int i = 0; i < NumBldgs; i++)
                    {
                        if (AggType == Aggregation.PerBuilding)
                        {
                            limit = limitTot * multiArr[i];
                        }

                        CurrNode.CurrentLossStateCollection.collection[i].X = Math.Max(CurrNode.CurrentLossStateCollection.collection[i].X, Math.Max(0.0, CurrNode.CurrentLossStateCollection.collection[i].S - limit));
                        CurrNode.CurrentLossStateCollection.collection[i].AdjustX();
                    }
                }  //end: each Group-up Sub-Limits
            }

            //then do all Deductibles one by one, all deductibles are already in the right exec order
            foreach (Deductible dedObj in sortedDeductibles)
            {
                double dedTot = 0;
                if (dedObj.DedType == TermValueType.Numeric)
                {
                    dedTot = dedObj.Amount;
                }
                else if (dedObj.DedType == TermValueType.PercentCovered)
                {
                    dedTot = dedObj.Amount * CurrNode.GetTIV();
                }
                else if (dedObj.DedType == TermValueType.PercentAffected)
                {
                    dedTot = dedObj.Amount * CurrNode.GetAffectedTIV();
                }
                else if (dedObj.DedType == TermValueType.PercentLoss)
                {
                    dedTot = dedObj.Amount * CurrNode.CurrentLossStateCollection.GetTotalSum.S;
                }
                else
                {
                    throw new InvalidOperationException("Ded TermValueType is not Known");
                }

                double ded = dedTot;
                for (int i = 0; i < NumBldgs; i++)
                {
                    if (AggType == Aggregation.PerBuilding)
                    {
                        ded = dedTot * multiArr[i];
                    }

                    if (dedObj.DedIsFranchise)
                    {
                        ded = (CurrNode.CurrentLossStateCollection.collection[i].S > ded) ? 0.0 : CurrNode.CurrentLossStateCollection.collection[i].S;
                    }
                    else
                    {
                        ded = Math.Min(CurrNode.CurrentLossStateCollection.collection[i].S, ded);
                    }

                    if (dedObj.DedInterType == DedInteractionType.SingleLargest)
                    {
                        CurrNode.CurrentLossStateCollection.collection[i].D = IntObject[i].LargestDedFromChildren;
                    }
                    else if (dedObj.DedInterType == DedInteractionType.MAX)
                    {
                        CurrNode.CurrentLossStateCollection.collection[i].D = Math.Min(CurrNode.CurrentLossStateCollection.collection[i].D, ded);
                    }
                    else if (dedObj.DedInterType == DedInteractionType.MIN)
                    {
                        CurrNode.CurrentLossStateCollection.collection[i].D = Math.Max(CurrNode.CurrentLossStateCollection.collection[i].D, ded);
                    }
                    else if (dedObj.DedInterType == DedInteractionType.Absorbing)
                    {
                        CurrNode.CurrentLossStateCollection.collection[i].D = Math.Max(CurrNode.CurrentLossStateCollection.collection[i].D, ded - CurrNode.CurrentLossStateCollection.collection[i].X);
                    }
                    else
                    {
                        throw new InvalidOperationException("Interaction Type is not Known");
                    }

                    CurrNode.CurrentLossStateCollection.collection[i].AdjustD();
                }
            } //end: all deds


            for (int i = 0; i < NumBldgs; i++)
            {
                CurrNode.CurrentLossStateCollection.collection[i].AdjustD();
            }

            //then do all NetOfDed Sub-Limit
            foreach (Limit limObj in CurrNode.Limits)
            {
                if (limObj.LimitIsNetOfDed)
                {
                    double limitTot = 0;
                    if (limObj.LimType == TermValueType.Numeric)
                    {
                        limitTot = limObj.Amount;
                    }
                    else if (limObj.LimType == TermValueType.PercentCovered)
                    {
                        limitTot = limObj.Amount * CurrNode.GetTIV();
                    }
                    else if (limObj.LimType == TermValueType.PercentAffected)
                    {
                        limitTot = limObj.Amount * CurrNode.GetAffectedTIV();
                    }
                    else if (limObj.LimType == TermValueType.PercentLoss)
                    {
                        limitTot = limObj.Amount * CurrNode.CurrentLossStateCollection.GetTotalSum.S;
                    }
                    else
                    {
                        throw new InvalidOperationException("Lim TermValueType is not Known");
                    }

                    double limit = limitTot;
                    //Parallel.For(0, NumBldgs, i =>
                    for (int i = 0; i < NumBldgs; i++)
                    {
                        if (AggType == Aggregation.PerBuilding)
                        {
                            limit = limitTot * multiArr[i];
                        }

                        CurrNode.CurrentLossStateCollection.collection[i].X = Math.Max(CurrNode.CurrentLossStateCollection.collection[i].X, CurrNode.CurrentLossStateCollection.collection[i].S - CurrNode.CurrentLossStateCollection.collection[i].D - limit);

                        CurrNode.CurrentLossStateCollection.collection[i].AdjustX();
                    }
                    //);
                }
            } //end: NetOfDed sub-limit
        }
Exemple #2
0
        public void TermFunction(LossStateCollection2 LossFromBelow)
        {
            int NumBldgs = CurrNode.CurrentLossStateCollection.NumBldgs;

            //int intObjCount = IntObject.Count();
            double[] excessFromBelow = LossFromBelow.Excess;
            double[] dedFromBelow    = LossFromBelow.Deductible;
            double[] lossFromBelow   = LossFromBelow.SubjectLoss;
            double[] recovFromBelow  = LossFromBelow.Recoverable;

            double[] nodeexcess = CurrNode.CurrentLossStateCollection.Excess;
            double[] nodeded    = CurrNode.CurrentLossStateCollection.Deductible;
            double[] nodeloss   = CurrNode.CurrentLossStateCollection.SubjectLoss;
            double[] noderecov  = CurrNode.CurrentLossStateCollection.Recoverable;

            //if (LossFromBelow.NumBldgs != CurrNode.CurrentLossStateCollection.NumBldgs)
            //    throw new ArgumentOutOfRangeException("Number of buildings from below must equal number of buildings in current trem node...when performing interaction!");

            DeductibleCollection sortedDeductibles = CurrNode.Deductibles.SortByExecOrder(CurrNode.Deductibles);


            //Intialize
            if (LossFromBelow.NumBldgs == CurrNode.CurrentLossStateCollection.NumBldgs)
            {
                //CurrNode.CurrentLossStateCollection.collection[i].X = IntObject[i].ExcessFromChildren;
                //CurrNode.CurrentLossStateCollection.collection[i].D = IntObject[i].DedFromChildren;

                Array.Copy(excessFromBelow, nodeexcess, NumBldgs);
                Array.Copy(dedFromBelow, nodeded, NumBldgs);
            }
            else
            {
                //CurrNode.CurrentLossStateCollection.collection[i].X = 0;
                //CurrNode.CurrentLossStateCollection.collection[i].D = 0;

                Array.Clear(CurrNode.CurrentLossStateCollection.Excess, 0, NumBldgs);
                Array.Clear(CurrNode.CurrentLossStateCollection.Deductible, 0, NumBldgs);
            }

            //Do Ground-up sub-Limit first
            foreach (Limit limObj in CurrNode.Limits)
            {
                if (limObj.LimitIsNetOfDed == false)
                {
                    double limitTot = 0;
                    if (limObj.LimType == TermValueType.Numeric)
                    {
                        limitTot = limObj.Amount;
                    }
                    else if (limObj.LimType == TermValueType.PercentCovered)
                    {
                        limitTot = limObj.Amount / 100 * CurrNode.GetTIV();
                    }
                    else if (limObj.LimType == TermValueType.PercentAffected)
                    {
                        limitTot = limObj.Amount / 100 * CurrNode.GetAffectedTIV();
                    }
                    else if (limObj.LimType == TermValueType.PercentLoss)
                    {
                        limitTot = limObj.Amount / 100 * CurrNode.CurrentLossStateCollection.GetTotalSum.S;
                    }
                    else
                    {
                        throw new InvalidOperationException("Lim TermValueType is not Known");
                    }

                    double limit = limitTot;
                    for (int i = 0; i < NumBldgs; i++)
                    {
                        if (AggType == Aggregation.PerBuilding)
                        {
                            limit = limitTot * multiArr[i];
                        }

                        nodeexcess[i] = Math.Max(nodeexcess[i], Math.Max(0.0, nodeloss[i] - limit));
                    }

                    CurrNode.CurrentLossStateCollection.AdjustX();
                }  //end: each Group-up Sub-Limits
            }

            //then do all Deductibles one by one, all deductibles are already in the right exec order
            foreach (Deductible dedObj in sortedDeductibles)
            {
                double dedTot = 0;
                if (dedObj.DedType == TermValueType.Numeric)
                {
                    dedTot = dedObj.Amount;
                }
                else if (dedObj.DedType == TermValueType.PercentCovered)
                {
                    dedTot = dedObj.Amount * CurrNode.GetTIV();
                }
                else if (dedObj.DedType == TermValueType.PercentAffected)
                {
                    dedTot = dedObj.Amount * CurrNode.GetAffectedTIV();
                }
                else if (dedObj.DedType == TermValueType.PercentLoss)
                {
                    dedTot = dedObj.Amount * CurrNode.CurrentLossStateCollection.GetTotalSum.S;
                }
                else
                {
                    throw new InvalidOperationException("Ded TermValueType is not Known");
                }

                double ded = dedTot;
                for (int i = 0; i < NumBldgs; i++)
                {
                    if (AggType == Aggregation.PerBuilding)
                    {
                        ded = dedTot * multiArr[i];
                    }

                    if (dedObj.DedIsFranchise)
                    {
                        ded = (nodeloss[i] > ded) ? 0.0 : nodeloss[i];
                    }
                    else
                    {
                        ded = Math.Min(nodeloss[i], ded);
                    }

                    if (dedObj.DedInterType == DedInteractionType.SingleLargest)
                    {
                        nodeded[i] = LossFromBelow.GetLargestDed();
                    }
                    else if (dedObj.DedInterType == DedInteractionType.MAX)
                    {
                        nodeded[i] = Math.Min(nodeded[i], ded);
                    }
                    else if (dedObj.DedInterType == DedInteractionType.MIN)
                    {
                        nodeded[i] = Math.Max(nodeded[i], ded);
                    }
                    else if (dedObj.DedInterType == DedInteractionType.Absorbing)
                    {
                        nodeded[i] = Math.Max(nodeded[i], ded - nodeexcess[i]);
                    }
                    else
                    {
                        throw new InvalidOperationException("Interaction Type is not Known");
                    }
                }

                CurrNode.CurrentLossStateCollection.AdjustD();
            } //end: all deds


            //for (int i = 0; i < NumBldgs; i++)
            //{
            //    CurrNode.CurrentLossStateCollection.AdjustD();
            //}

            CurrNode.CurrentLossStateCollection.AdjustD();

            //then do all NetOfDed Sub-Limit
            foreach (Limit limObj in CurrNode.Limits)
            {
                if (limObj.LimitIsNetOfDed)
                {
                    double limitTot = 0;
                    if (limObj.LimType == TermValueType.Numeric)
                    {
                        limitTot = limObj.Amount;
                    }
                    else if (limObj.LimType == TermValueType.PercentCovered)
                    {
                        limitTot = limObj.Amount * CurrNode.GetTIV();
                    }
                    else if (limObj.LimType == TermValueType.PercentAffected)
                    {
                        limitTot = limObj.Amount * CurrNode.GetAffectedTIV();
                    }
                    else if (limObj.LimType == TermValueType.PercentLoss)
                    {
                        limitTot = limObj.Amount * CurrNode.CurrentLossStateCollection.GetTotalSum.S;
                    }
                    else
                    {
                        throw new InvalidOperationException("Lim TermValueType is not Known");
                    }

                    double limit = limitTot;
                    for (int i = 0; i < NumBldgs; i++)
                    {
                        if (AggType == Aggregation.PerBuilding)
                        {
                            limit = limitTot * multiArr[i];
                        }

                        nodeexcess[i] = Math.Max(nodeexcess[i], nodeloss[i] - nodeded[i] - limit);

                        //CurrNode.CurrentLossStateCollection.collection[i].AdjustX();
                    }

                    CurrNode.CurrentLossStateCollection.AdjustX();
                }
            } //end: NetOfDed sub-limit
        }