Beispiel #1
0
        //public double[] GetGUForNode(GraphNode node)
        //{
        //    PrimarySubject sub = (PrimarySubject)node.Subject;
        //    int numBldgs = sub.Schedule.ActNumOfBldgs;
        //    double[] subjectloss = new double[numBldgs];
        //    List<RITCharacteristic> LeftoverRiteChars = sub.Schedule.RITChars.ToList();

        //    foreach (GraphNode childnode in graph.GetChildrenForNode(node))
        //    {
        //        double[] nodeLosses = GetGUForNode(childnode);

        //        if (childnode is TermNode)
        //        {
        //            TermNode termNode = childnode as TermNode;
        //            if (numBldgs == 1)
        //            {
        //                subjectloss[0] += nodeLosses.Sum();
        //            }
        //            else if (numBldgs == nodeLosses.Count())
        //            {
        //                subjectloss.Zip(nodeLosses, (a, b) => a + b);
        //            }
        //        }
        //        else
        //        {
        //            CoverNode covNode = childnode as CoverNode;
        //            subjectloss[0] += covNode.Payout;
        //        }

        //        LeftoverRiteChars = LeftoverRiteChars.Except(childnode.Subject.Schedule.RITChars).ToList();
        //    }

        //    foreach (RITCharacteristic RITChar in LeftoverRiteChars)
        //    {
        //        foreach (string subperil in sub.CauseOfLossSet.GetSubperils())
        //        {
        //            if (sub.ExposureTypes.Contains(RITChar.ExpType))
        //            {
        //                double[] RITELoss;
        //                uint timestamp;
        //                string error;
        //                if (GetRITCharacteristicLoss(RITChar, subperil, out RITELoss, out timestamp, out error, numBldgs))
        //                    subjectloss = subjectloss.Zip(RITELoss, (x, y) => x + y).ToArray();
        //                else
        //                    throw new GUInputEngineException(error);
        //            }
        //        }
        //    }

        //    return subjectloss;
        //}

        private bool GetRITCharacteristicLoss(RITCharacteristic RITChar, string subperil, out double[] loss, out uint timestamp, out string error, int numBldgs)
        {
            bool success = true;

            error = "";
            long   CharId      = RITChar.ID;
            double BuildingTIV = RITChar.TIV / RITChar.ParentRITE.NumOfTrueBldgs;

            loss      = new double[1];
            loss[0]   = 0;
            timestamp = 0;

            Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > AfterCOL;

            if (GULosses.TryGetValue(subperil, out AfterCOL))
            {
                Dictionary <long, Tuple <double, uint, List <float> > > AfterSample;
                if (AfterCOL.TryGetValue(0, out AfterSample))
                {
                    Tuple <double, uint, List <float> > DamageRatio;
                    if (AfterSample.TryGetValue(CharId, out DamageRatio))
                    {
                        timestamp = DamageRatio.Item2;

                        if (DamageRatio.Item3.Count == numBldgs)
                        {
                            double[] multiplyArr = RITE.GenerateMultiplierArr(RITChar.ParentRITE.NumOfSampleBldgs);
                            loss = DamageRatio.Item3.Zip(multiplyArr, (d1, d2) => (double)d1 * d2).ToArray();
                            //loss = Array.ConvertAll(DamageRatio.Item2.ToArray(), x => (double)x);
                            success = true;
                        }
                        else if (numBldgs == 1)
                        {
                            double[] multiplyArr = RITE.GenerateMultiplierArr(RITChar.ParentRITE.NumOfSampleBldgs);
                            loss[0] = DamageRatio.Item3.Zip(multiplyArr, (d1, d2) => d1 * d2).Sum();
                            //loss[0] = DamageRatio.Item2.ToArray().Sum();
                            success = true;
                        }
                        else
                        {
                            success = false;
                            error   = "Error getting GU for RITE ID: " + RITChar.ID + ". GU losses specified not matching for NumBldgs...";
                        }
                    }
                    else
                    {
                        success = false;
                        error   = "Error getting GU for RITE ID: " + RITChar.ID + ". Cannot find RITE ID in GU Input Loss dictionary";
                    }
                }
                else
                {
                    success = false;
                    error   = "Error getting GU for RITE ID: " + RITChar.ID + ". Cannot find Sample 0 in GU Input Loss dictionary, currenlty hard-coded to take sample id = 0";
                }
            }

            return(success);
        }
Beispiel #2
0
        private void ExecuteOverlappedTermNode(TermNode currTermNode, List <GraphNode> childrenNodes, GUInputEngine guLossesEngine, HashSet <CoverageAtomicRITE> SubjectCRITEs)
        {
            //find its AtomicRITEs
            // HashSet<AtomicRITE> SubjectARITEs = currTermNode.Subject.GetAtomicRites();

            //get the node's Subject loss
            double[] inputlosses;
            //inputlosses = guLossesEngine.GetGUForSubject(currTermNode.PrimarySubject).Zip(currTermNode.PrimarySubject.Schedule.MultiplierArr, (d1, d2) => d1 * d2).ToArray();
            //inputlosses = guLossesEngine.GetGUForSubject(currTermNode.PrimarySubject);
            inputlosses = graph.GetNodeSubjectLoss(currTermNode).AllLoss();
            if (currTermNode.IsPerRisk)
            {
                currTermNode.CurrentLossStateCollection.SetSubjectLosses(inputlosses);
            }
            else
            {
                currTermNode.CurrentLossStateCollection.SetSubjectLosses(new double[] { inputlosses.Sum() });
            }


            //if (isLowestLevel) //initialize to GU loss
            //{
            foreach (CoverageAtomicRITE cRite in SubjectCRITEs)
            {
                //double[] GULoss = guLossesEngine.GetGUForCoverageRITE(CoverageAtomicRITE cRITE);
                //if (cRite.GetLossState().collection[0].S == 0)  //if not assign the GU loss yet
                if (cRite.GetLossState().GetTotalSum.S == 0)      //if not assign the GU loss yet
                {
                    guLossesEngine.GetGUForCoverageRITE(cRite);
                    int[] multiArr = RITE.GenerateMultiplierArr(cRite.RITE.ActNumOfBldgs).ToArray();

                    for (int i = 0; i < cRite.RITE.ActNumOfBldgs; i++)
                    {
                        //cRite.GetLossState().collection[i].S = GULoss[i] * multiArr[i];
                        cRite.GetLossState().collection[i].S = cRite.GetLossState().collection[i].S * multiArr[i];
                        cRite.GetLossState().collection[i].R = cRite.GetLossState().collection[i].S;
                        cRite.GetLossState().collection[i].D = 0;
                        cRite.GetLossState().collection[i].X = 0;
                    }
                }

                for (int i = 0; i < cRite.RITE.ActNumOfBldgs; i++)
                {
                    //init the allocation state
                    cRite.GetAllocState().collection[i].S = cRite.GetLossState().collection[i].S;
                }
                //cRite.CurrentLossState = cRite.CurrentLossStateCollection.GetTotalSum;
            }
            //}

            Aggregation aggType = Aggregation.Summed;

            if (currTermNode.IsPerRisk && currTermNode.PrimarySubject.Schedule.ActNumOfBldgs > 1)
            {
                aggType = Aggregation.PerBuilding;
            }
            //else
            //{
            //need reset the lossState to act as only one building
            //LossStateCollection tempLossStateCollection = new LossStateCollection(1);
            //tempLossStateCollection.collection[0] = currTermNode.CurrentLossStateCollection.GetTotalSum;
            //currTermNode.CurrentLossStateCollection = tempLossStateCollection;
            //}

            //if no childrenNodes, nothing to do with the Interaction: the interaction terms are all zeros.
            if (SubjectCRITEs.Count > 0)
            {
                //initialize InterObj
                InteractionObject[]  InterObj = GetInterObjForOverlap(currTermNode, childrenNodes, aggType, SubjectCRITEs);
                TermFunctionalEngine tFunEng  = new TermFunctionalEngine(currTermNode, aggType);
                tFunEng.TermFunction(InterObj);
            }
            else
            {
                TermFunctionalEngine tFunEng = new TermFunctionalEngine(currTermNode, aggType);
                tFunEng.TermFunction(new InteractionObject[0]);
            }

            //Final Adjustment
            for (int i = 0; i < currTermNode.CurrentLossStateCollection.NumBldgs; i++)
            {
                currTermNode.CurrentLossStateCollection.collection[i].AdjustR();
            }
        }