Beispiel #1
0
        private List <GraphNode> GetTermNodes(PrimaryContractExtractor contract, List <PrimarySubject> graphSubs)
        {
            List <GraphNode> termNodes = new List <GraphNode>();

            foreach (PrimarySubject sub in graphSubs)
            {
                TermNode node = new TermNode(sub);

                DeductibleCollection Deds;
                if (contract.GetDeductiblesForSubject(sub, out Deds))
                {
                    node.Deductibles = Deds;
                }

                LimitCollection Lims;
                if (contract.GetLimitsForSubject(sub, out Lims))
                {
                    node.Limits = Lims;
                }

                termNodes.Add(node);
            }

            return(termNodes);
        }
Beispiel #2
0
        private InteractionObject[] GetInterObj(TermNode currNode, Aggregation aggType, List <TermNode> childrenNodes)
        {
            InteractionObject[] InterObj = new InteractionObject[currNode.CurrentLossStateCollection.NumBldgs];
            for (int i = 0; i < currNode.CurrentLossStateCollection.NumBldgs; i++)
            {
                InterObj[i] = new InteractionObject();
            }

            foreach (TermNode childNode in childrenNodes)
            {
                //if (currNode.TermIsPerRisk && currNode.CurrentLossStateCollection.NumBldgs > 1)
                if (aggType == Aggregation.PerBuilding)
                {
                    for (int i = 0; i < currNode.CurrentLossStateCollection.NumBldgs; i++)
                    {
                        InterObj[i].UpdateInterObjState(childNode.CurrentLossStateCollection.collection[i]);
                    }
                }
                else
                {
                    LossState childLossesState = new LossState(childNode.CurrentLossStateCollection.GetTotalSum);
                    InterObj[0].UpdateInterObjState(childLossesState);
                }
            }  //foreach child
            return(InterObj);
        }
Beispiel #3
0
        private void UpdateGraphWithLim(Dictionary <string, object> termDictionary, Graph graph)
        {
            bool    nodefound = false;
            Subject cdlSub    = GetSubjectForTerm(termDictionary);

            foreach (GraphNode node in graph.GraphNodes)
            {
                if (node is TermNode)
                {
                    TermNode termNode = node as TermNode;

                    if (termNode.Subject.Equals(cdlSub))
                    {
                        nodefound = true;
                        Limit limit = TermParser.GetLimitForTerm(termDictionary, graph.Declarations);
                        termNode.Limits.Add(limit);
                        break;
                    }
                }
            }
            if (!nodefound)
            {
                throw new InvalidOperationException("Cannot find Node in fixed graph, for JSON term with subject: (" + cdlSub.ToString() + ")");
            }
        }
Beispiel #4
0
        public override List <TermNode> GetTermNodes()
        {
            List <TermNode>       termNodes = new List <TermNode>();
            List <PrimarySubject> graphSubs = PrimaryContract.GetAllTermSubjects();

            foreach (PrimarySubject sub in graphSubs)
            {
                TermNode node = new TermNode(sub);

                DeductibleCollection Deds;
                if (PrimaryContract.GetDeductiblesForSubject(sub, out Deds))
                {
                    node.Deductibles = Deds;
                }

                LimitCollection Lims;
                if (PrimaryContract.GetLimitsForSubject(sub, out Lims))
                {
                    node.Limits = Lims;
                }

                termNodes.Add(node);
            }
            return(termNodes);
        }
Beispiel #5
0
        private void UpdateGraphWithDed(Dictionary <string, object> termDictionary, GraphOfNodes graph)
        {
            bool    nodefound = false;
            int     count     = 0;
            Subject cdlSub    = GetSubjectForTerm(termDictionary);

            foreach (GraphNode node in graph.GraphNodes)
            {
                count++;
                if (node is TermNode)
                {
                    TermNode termNode = node as TermNode;

                    if (termNode.Subject.Equals(cdlSub))
                    {
                        nodefound = true;
                        Deductible ded = TermParser.GetDedForTerm(termDictionary, graph.Declarations);
                        termNode.Deductibles.Add(ded);
                        break;
                    }
                }
            }
            if (!nodefound)
            {
                throw new InvalidOperationException("Cannot find Node in fixed graph, for JSON term with subject: (" + cdlSub.ToString() + ")");
            }
        }
Beispiel #6
0
        public TermNode(PrimarySubject _subject, TermNode tNode) : base(_subject)
        {
            CurrentAllocationState = new AllocationStateCollection2(_subject.Schedule.ActNumOfBldgs);

            //Deductibles = tNode.Deductibles;
            //Limits = tNode.Limits;
            //should do shallow copy, not copy whole object
            Deductibles = new DeductibleCollection(tNode.Deductibles);
            Limits      = new LimitCollection(tNode.Limits);
        }
Beispiel #7
0
        private InteractionObject[] GetInterObjForOverlap(TermNode currNode, List <GraphNode> childrenNodes, Aggregation aggType, HashSet <CoverageAtomicRITE> SubjectARites)
        {
            InteractionObject[] InterObj = new InteractionObject[currNode.CurrentLossStateCollection.NumBldgs];
            for (int i = 0; i < currNode.CurrentLossStateCollection.NumBldgs; i++)
            {
                InterObj[i] = new InteractionObject();
            }
            //Get Single largest Deductible, based on the children nodes, not AtomicRites

            foreach (CoverageAtomicRITE aRite in SubjectARites)
            {
                if (aggType == Aggregation.PerBuilding)
                {
                    if (currNode.CurrentLossStateCollection.NumBldgs != aRite.RITE.ActNumOfBldgs)
                    {
                        throw new InvalidOperationException("AtomicRite NumOfBuilding must be equal to its parent's numOfBuilding");
                    }

                    for (int i = 0; i < currNode.CurrentLossStateCollection.NumBldgs; i++)
                    {
                        InterObj[i].UpdateInterObjStateForARITE(aRite.GetLossState().collection[i]);
                    }
                }
                else
                {
                    //AllocationState aRiteAllocState = new AllocationState(aRite.CurrentAllocationState);
                    InterObj[0].UpdateInterObjStateForARITE(aRite.GetLossState().GetTotalSum);
                }
            }  //foreach child

            //update for SingleLargestDed
            foreach (GraphNode childNode in childrenNodes)
            {
                TermNode childTermNode = childNode as TermNode;
                if (aggType == Aggregation.PerBuilding)
                {
                    if (currNode.CurrentLossStateCollection.NumBldgs != currNode.CurrentLossStateCollection.NumBldgs)
                    {
                        throw new InvalidOperationException("child NumOfBuilding must be equal to its parent's numOfBuilding");
                    }

                    for (int i = 0; i < currNode.CurrentLossStateCollection.NumBldgs; i++)
                    {
                        InterObj[i].LargestDedFromChildren = Math.Max(InterObj[i].LargestDedFromChildren, childTermNode.CurrentLossStateCollection.collection[i].D); //UpdateInterObjStateForARITE(aRite.GetLossState().collection[i]);
                    }
                }
                else
                {
                    //AllocationState aRiteAllocState = new AllocationState(aRite.CurrentAllocationState);
                    InterObj[0].LargestDedFromChildren = Math.Max(InterObj[0].LargestDedFromChildren, childTermNode.CurrentLossStateCollection.GetTotalSum.D); //(aRite.GetLossState().GetTotalSum);
                }
            }
            return(InterObj);
        }
Beispiel #8
0
 public bool IsOverlappedByTermNodes(Dictionary <TermNode, HashSet <TermNode> > CPMap)
 {
     foreach (TermNode node in CPMap.Keys)
     {
         List <TermNode> pList = CPMap[node].ToList();
         for (int i = 0; i < pList.Count(); i++)
         {
             TermNode node1 = pList[i];
             for (int j = i + 1; j < pList.Count(); j++)
             {
                 TermNode node2 = pList[j];
                 if (!CPMap[node1].Contains(node2) && !CPMap[node2].Contains(node1))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Beispiel #9
0
        public override void Initialize()
        {
            ////Build Graph here....
            //_graphNodes = new List<GraphNode>();
            //_parentToChildrenMap = new Dictionary<GraphNode, List<GraphNode>>();
            //_rites = new List<RITE>();
            //_schedules = new List<Schedule>();
            //_characteristics = new List<RITCharacteristic>();

            ////Add Contract Declarations
            //Declarations = new Declarations();

            ////Create RITECharacteristics
            //RITCharacteristic RITChar18 = new RITCharacteristic(19419518, ExposureType.Building, 100000);
            //RITCharacteristic RITChar19 = new RITCharacteristic(19419519, ExposureType.Contents, 10000);
            //RITCharacteristic RITChar20 = new RITCharacteristic(19419520, ExposureType.Building, 100000);
            //RITCharacteristic RITChar21 = new RITCharacteristic(19419521, ExposureType.Contents, 10000);
            //_characteristics.Add(RITChar18);
            //_characteristics.Add(RITChar19);
            //_characteristics.Add(RITChar20);
            //_characteristics.Add(RITChar21);

            ////Create RITEs
            //RITE rite57 = new RITE(11324657, 1);
            //rite57.AddCharacteristic(RITChar18);
            //rite57.AddCharacteristic(RITChar19);
            //RITE rite58 = new RITE(11324658, 1);
            //rite58.AddCharacteristic(RITChar20);
            //rite58.AddCharacteristic(RITChar21);
            //_rites.Add(rite57);
            //_rites.Add(rite58);

            ////Create Schedules
            //Schedule S2729_EQ = new Schedule("S2729.EQ");
            //S2729_EQ.AddRITE(rite57);
            //S2729_EQ.AddRITE(rite58);
            //_schedules.Add(S2729_EQ);

            //Schedule S2729_EQ_59491 = new Schedule("S2729.EQ.59491");
            //S2729_EQ_59491.AddRITE(rite57);
            //_schedules.Add(S2729_EQ_59491);

            //Schedule S2729_EQ_59492 = new Schedule("S2729.EQ.59492");
            //S2729_EQ_59492.AddRITE(rite58);
            //_schedules.Add(S2729_EQ_59492);

            //Create Schedules
            ScheduleOfRITEs S2729_EQ       = expdata.Schedules.ToList()[0];
            ScheduleOfRITEs S2729_EQ_59491 = expdata.Schedules.ToList()[1];
            ScheduleOfRITEs S2729_EQ_59492 = expdata.Schedules.ToList()[2];

            //Create Subjects
            PrimarySubject Node41Sub = new PrimarySubject(S2729_EQ_59491, Building, EQWS);
            PrimarySubject Node42Sub = new PrimarySubject(S2729_EQ_59491, Contents, EQWS);

            PrimarySubject Node31Sub = new PrimarySubject(S2729_EQ_59491, Loss, EQWS);
            PrimarySubject Node32Sub = new PrimarySubject(S2729_EQ_59492, Loss, EQWS);

            PrimarySubject Node21Sub = new PrimarySubject(S2729_EQ, Loss, EQWS);

            PrimarySubject Node01Sub = new PrimarySubject(null, null, null);

            Node01Sub.IsDerived = true;
            List <String> temp = new List <String>();

            temp.Add("Node11");
            Node01Sub.ChildrenCoverNodeList = temp;

            //TermNode Node41 = new TermNode(Node41Sub, false, false, 8000000, 10000000); //loccvg
            TermNode Node41 = new TermNode(Node41Sub); //loccvg

            graphNodes.Add(Node41);
            TermNode Node42 = new TermNode(Node42Sub);  //loccvg

            graphNodes.Add(Node42);

            //loc terms
            TermNode Node31 = new TermNode(Node31Sub); //loc

            graphNodes.Add(Node31);
            TermNode Node32 = new TermNode(Node32Sub); //loc

            graphNodes.Add(Node32);

            //policy term
            TermNode Node21 = new TermNode(Node21Sub);  //policy term, no limit term, so limit = 0?

            graphNodes.Add(Node21);

            //policy cover
            CoverNode Node11 = new CoverNode(Node21Sub, "L102_3222");  //policy layer

            graphNodes.Add(Node11);

            //treaty layer
            CoverNode Node01 = new CoverNode(Node01Sub, "OccLim");
            //_graphNodes.Add(Node01);

            //Build Parent to Child Mapping
            List <GraphNode> Node01Children = new List <GraphNode>()
            {
                Node11
            };

            parentToChildrenMap.Add(Node01, Node01Children);

            List <GraphNode> Node11Children = new List <GraphNode>()
            {
                Node21
            };

            parentToChildrenMap.Add(Node11, Node11Children);

            List <GraphNode> Node21Children = new List <GraphNode>()
            {
                Node31, Node32
            };

            parentToChildrenMap.Add(Node21, Node21Children);

            List <GraphNode> Node31Children = new List <GraphNode>()
            {
                Node41, Node42
            };

            parentToChildrenMap.Add(Node31, Node31Children);

            //raintest, add TopNode treaty term manually for now
            Cover topCover = new Cover("TreatyCover", false, new MonetaryValue(600.0), new MonetaryValue(1000000.0), new PercentValue(100), false, TimeBasis.Occurrence, TimeBasis.Occurrence, TermValueType.Numeric);

            Node01.Cover = topCover;
            //end of hack

            TopNodes = new List <GraphNode>()
            {
                Node01
            };
            GraphReady = true;
        } //end of Initialize
Beispiel #10
0
        public override void Initialize()
        {
            //Create Schedules
            ScheduleOfRITEs S16_EQ              = expdata.Schedules.ToList()[0]; //new Schedule("S16.EQ");
            ScheduleOfRITEs S16_EQ_5229         = expdata.Schedules.ToList()[1]; //new Schedule("S16.EQ.SubPolicy5229");
            ScheduleOfRITEs S16_EQ_5229_5228    = expdata.Schedules.ToList()[2]; //new Schedule("S16.EQ.SubPolicy5229.SubPolicy5228");
            ScheduleOfRITEs S16_EQ_5229_5228_46 = expdata.Schedules.ToList()[3]; //new Schedule("S16.EQ.SubPolicy5229.SubPolicy5228.46");
            ScheduleOfRITEs S16_EQ_5229_47      = expdata.Schedules.ToList()[4]; //new Schedule("S16.EQ.SubPolicy5229.47");
            ScheduleOfRITEs S16_EQ_48           = expdata.Schedules.ToList()[5]; //new Schedule("S16.EQ.48");

            //Create Subjects
            PrimarySubject Node53Sub = new PrimarySubject(S16_EQ_5229_5228_46, Building, EQ);
            PrimarySubject Node54Sub = new PrimarySubject(S16_EQ_5229_5228_46, Contents, EQ);
            PrimarySubject Node55Sub = new PrimarySubject(S16_EQ_5229_5228_46, BI, EQ);

            PrimarySubject Node56Sub = new PrimarySubject(S16_EQ_5229_47, Building, EQWS);
            PrimarySubject Node57Sub = new PrimarySubject(S16_EQ_5229_47, Contents, EQWS);
            PrimarySubject Node58Sub = new PrimarySubject(S16_EQ_5229_47, BI, EQWS);

            PrimarySubject Node59Sub = new PrimarySubject(S16_EQ_48, Building, EQWS);
            PrimarySubject Node60Sub = new PrimarySubject(S16_EQ_48, Contents, EQWS);
            PrimarySubject Node61Sub = new PrimarySubject(S16_EQ_48, BI, EQWS);

            PrimarySubject Node46Sub = new PrimarySubject(S16_EQ_5229_5228_46, Loss, EQ);
            PrimarySubject Node47Sub = new PrimarySubject(S16_EQ_5229_47, Loss, EQWS);
            PrimarySubject Node48Sub = new PrimarySubject(S16_EQ_48, Loss, EQWS);

            PrimarySubject NodeBSub = new PrimarySubject(S16_EQ, Building, EQWS);
            PrimarySubject NodeCSub = new PrimarySubject(S16_EQ, Contents, EQWS);

            PrimarySubject NodeBISub = new PrimarySubject(S16_EQ, BI, EQWS);

            PrimarySubject Node21Sub = new PrimarySubject(S16_EQ, Loss, EQWS);

            //Nodes
            TermNode Node53 = new TermNode(Node53Sub); //loccvg

            graphNodes.Add(Node53);
            TermNode Node54 = new TermNode(Node54Sub); //loccvg

            graphNodes.Add(Node54);
            TermNode Node55 = new TermNode(Node55Sub); //loccvg

            graphNodes.Add(Node55);

            TermNode Node56 = new TermNode(Node56Sub); //loccvg

            graphNodes.Add(Node56);
            TermNode Node57 = new TermNode(Node57Sub); //loccvg

            graphNodes.Add(Node57);
            TermNode Node58 = new TermNode(Node58Sub); //loccvg

            graphNodes.Add(Node58);

            TermNode Node59 = new TermNode(Node59Sub); //loccvg

            graphNodes.Add(Node59);
            TermNode Node60 = new TermNode(Node60Sub); //loccvg

            graphNodes.Add(Node60);
            TermNode Node61 = new TermNode(Node61Sub); //loccvg

            graphNodes.Add(Node61);

            //loc term
            TermNode Node46 = new TermNode(Node46Sub);  //loc

            graphNodes.Add(Node46);
            TermNode Node47 = new TermNode(Node47Sub);  //loc

            graphNodes.Add(Node47);
            TermNode Node48 = new TermNode(Node48Sub);  //loc

            graphNodes.Add(Node48);

            //policy coverage
            TermNode NodeB = new TermNode(NodeBSub);

            graphNodes.Add(NodeB);
            TermNode NodeC = new TermNode(NodeCSub);

            graphNodes.Add(NodeC);
            TermNode NodeBI = new TermNode(NodeBISub);

            graphNodes.Add(NodeBI);

            TermNode Node21 = new TermNode(Node21Sub);

            graphNodes.Add(Node21);

            //policy cover
            CoverNode Node11 = new CoverNode(Node21Sub, " L937_16");

            graphNodes.Add(Node11);

            //Build Parent to Child Mapping
            List <GraphNode> Node11Children = new List <GraphNode>()
            {
                Node21
            };

            parentToChildrenMap.Add(Node11, Node11Children);

            List <GraphNode> Node21Children = new List <GraphNode>()
            {
                Node46, Node47, Node48, NodeB, NodeC, NodeBI
            };

            parentToChildrenMap.Add(Node21, Node21Children);

            //List<GraphNode> Node32Children = new List<GraphNode>() { Node46, Node31, Node47 };
            //_parentToChildrenMap.Add(Node32, Node32Children);

            //List<GraphNode> Node31Children = new List<GraphNode>() { Node46 };
            //_parentToChildrenMap.Add(Node31, Node31Children);

            List <GraphNode> Node46Children = new List <GraphNode>()
            {
                Node53, Node54, Node55
            };

            parentToChildrenMap.Add(Node46, Node46Children);

            List <GraphNode> Node47Children = new List <GraphNode>()
            {
                Node56, Node57, Node58
            };

            parentToChildrenMap.Add(Node47, Node47Children);

            List <GraphNode> Node48Children = new List <GraphNode>()
            {
                Node59, Node60, Node61
            };

            parentToChildrenMap.Add(Node48, Node48Children);

            List <GraphNode> NodeBChildren = new List <GraphNode>()
            {
                Node53, Node56, Node59
            };

            parentToChildrenMap.Add(NodeB, NodeBChildren);

            List <GraphNode> NodeCChildren = new List <GraphNode>()
            {
                Node54, Node57, Node60
            };

            parentToChildrenMap.Add(NodeC, NodeCChildren);

            List <GraphNode> NodeBIChildren = new List <GraphNode>()
            {
                Node55, Node58, Node61
            };

            parentToChildrenMap.Add(NodeBI, NodeBIChildren);

            TopNodes = new List <GraphNode>()
            {
                Node11
            };
            AssignLevelToNode();
            BuildAtomicRITEs();
            GraphReady = true;
        } //end of Initialize
Beispiel #11
0
        private void AllocateOverlappedTermNode(TermNode currTermNode, HashSet <CoverageAtomicRITE> SubjectARITEs)
        {
            //find its AtomicRITEs
            //HashSet<AtomicRITE> SubjectARITEs = currTermNode.Subject.GetAtomicRites();
            Aggregation aggType = Aggregation.Summed;

            if (currTermNode.IsPerRisk && currTermNode.PrimarySubject.Schedule.ActNumOfBldgs > 1)
            {
                aggType = Aggregation.PerBuilding;
            }

            int numOfChildren = SubjectARITEs.Count;

            AllocationStateCollection[] MidAllocationStateCollection = new AllocationStateCollection[numOfChildren];

            int j = 0;

            foreach (CoverageAtomicRITE childNode in SubjectARITEs)
            {
                MidAllocationStateCollection[j] = new AllocationStateCollection(childNode.GetAllocState().NumBldgs);
                j++;
            }

            //Allocation has to co-op with multi-building
            //always allocate to per-building
            if (aggType == Aggregation.PerBuilding)
            {   // do it per-building
                foreach (CoverageAtomicRITE cRite in SubjectARITEs)
                {
                    if (cRite.GetLossState().NumBldgs != currTermNode.CurrentLossStateCollection.NumBldgs)
                    {
                        throw new InvalidOperationException("AtomicRite NumOfBuilding must be equal to its parent's numOfBuilding");
                    }
                }

                for (int i = 0; i < currTermNode.CurrentLossStateCollection.NumBldgs; i++)
                {
                    Double childrenDSum = SubjectARITEs.Sum(item => item.GetLossState().collection[i].D);
                    Double childrenRSum = SubjectARITEs.Sum(item => item.GetLossState().collection[i].R);
                    Double childrenSSum = SubjectARITEs.Sum(item => item.GetLossState().collection[i].S);
                    Double diffD        = currTermNode.CurrentLossStateCollection.collection[i].D - childrenDSum;

                    if (childrenRSum == 0)
                    {
                        j = 0;
                        foreach (AtomicRITE childNode in SubjectARITEs)
                        {
                            MidAllocationStateCollection[j].collection[i].R = currTermNode.CurrentLossStateCollection.collection[i].R * childNode.GetLossState().collection[i].S / childrenSSum;
                            j++;
                        }
                    }
                    else if (diffD >= 0)
                    {
                        j = 0;
                        foreach (AtomicRITE childNode in SubjectARITEs)
                        {
                            MidAllocationStateCollection[j].collection[i].R = childNode.GetLossState().collection[i].R * (1 - diffD / childrenRSum);
                            MidAllocationStateCollection[j].collection[i].D = childNode.GetLossState().collection[i].S - childNode.GetLossState().collection[i].X - MidAllocationStateCollection[j].collection[i].R;
                            j++;
                        }
                    }
                    else
                    {
                        j = 0;
                        foreach (AtomicRITE childNode in SubjectARITEs)
                        {
                            MidAllocationStateCollection[j].collection[i].D = childNode.GetLossState().collection[i].D * (1 + diffD / childrenDSum);
                            MidAllocationStateCollection[j].collection[i].R = childNode.GetLossState().collection[i].S - childNode.GetLossState().collection[i].X - MidAllocationStateCollection[j].collection[i].D;
                            j++;
                        }
                    }

                    Double childrenRaSum = MidAllocationStateCollection.Sum(item => item.collection[i].R);
                    int    jj            = 0;
                    if (diffD >= 0 && childrenRaSum == 0)
                    {
                        foreach (CoverageAtomicRITE childNode in SubjectARITEs)
                        {
                            MidAllocationStateCollection[jj].collection[i].R = childNode.GetLossState().collection[i].R;
                            jj++;
                        }
                        childrenRaSum = MidAllocationStateCollection.Sum(item => item.collection[i].R);
                    }

                    jj = 0;
                    foreach (CoverageAtomicRITE childNode in SubjectARITEs)
                    {
                        if (currTermNode.CurrentLossStateCollection.collection[i].R == 0)
                        {
                            MidAllocationStateCollection[jj].collection[i].R = 0;
                        }
                        else if (childrenRaSum > 0)
                        {
                            MidAllocationStateCollection[jj].collection[i].R = currTermNode.CurrentLossStateCollection.collection[i].R * MidAllocationStateCollection[jj].collection[i].R / childrenRaSum;
                        }

                        MidAllocationStateCollection[jj].collection[i].S = childNode.GetAllocState().collection[i].S;
                        //if (MidAllocationStateCollection[jj].collection[i].R > childNode.GetAllocState().collection[i].R ||
                        //      (MidAllocationStateCollection[jj].collection[i].R == childNode.GetAllocState().collection[i].R
                        //          && MidAllocationStateCollection[jj].collection[i].D > childNode.GetAllocState().collection[i].D))
                        //{
                        //    childNode.SetAllocState(MidAllocationStateCollection[jj]);
                        //    //childNode.GetAllocState().collection[i].R = MidAllocationStateCollection[jj].collection[i].R;
                        //    //childNode.GetAllocState().collection[i].D = MidAllocationStateCollection[jj].collection[i].D;
                        //}
                        jj++;
                    }
                }  //end of building i
                   //compare,always compare the summed, then pick the winner

                int ii = 0;
                foreach (CoverageAtomicRITE childNode in SubjectARITEs)
                {
                    if (MidAllocationStateCollection[ii].GetTotalSum.R > childNode.GetAllocState().GetTotalSum.R ||
                        (MidAllocationStateCollection[ii].GetTotalSum.R == childNode.GetAllocState().GetTotalSum.R &&
                         MidAllocationStateCollection[ii].GetTotalSum.D > childNode.GetAllocState().GetTotalSum.D))
                    {
                        childNode.SetAllocState(MidAllocationStateCollection[ii]);
                    }
                    ii++;
                }
            }
            else //not per-risk, but still allocate to per-building
            {
                AllocationStateCollection[] tempMid = new AllocationStateCollection[numOfChildren];
                j = 0;
                foreach (CoverageAtomicRITE childNode in SubjectARITEs)
                {
                    tempMid[j] = new AllocationStateCollection(1);
                    j++;
                }

                Double childrenDSum = SubjectARITEs.Sum(item => item.GetLossState().GetTotalSum.D);
                Double childrenRSum = SubjectARITEs.Sum(item => item.GetLossState().GetTotalSum.R);
                Double childrenSSum = SubjectARITEs.Sum(item => item.GetLossState().GetTotalSum.S);
                Double diffD        = currTermNode.GetLossState().GetTotalSum.D - childrenDSum;

                if (childrenRSum == 0)
                {
                    j = 0;
                    foreach (AtomicRITE childNode in SubjectARITEs)
                    {
                        tempMid[j].collection[0].R = currTermNode.GetLossState().GetTotalSum.R *childNode.GetLossState().GetTotalSum.S / childrenSSum;
                        j++;
                    }
                }
                else if (diffD >= 0)
                {
                    j = 0;
                    foreach (AtomicRITE childNode in SubjectARITEs)
                    {
                        tempMid[j].collection[0].R = childNode.GetLossState().GetTotalSum.R *(1 - diffD / childrenRSum);
                        tempMid[j].collection[0].D = childNode.GetLossState().GetTotalSum.S - childNode.GetLossState().GetTotalSum.X - tempMid[j].collection[0].R;
                        j++;
                    }
                }
                else
                {
                    j = 0;
                    foreach (AtomicRITE childNode in SubjectARITEs)
                    {
                        tempMid[j].collection[0].D = childNode.GetLossState().GetTotalSum.D *(1 + diffD / childrenDSum);
                        tempMid[j].collection[0].R = childNode.GetLossState().GetTotalSum.S - childNode.GetLossState().GetTotalSum.X - tempMid[j].collection[0].D;
                        j++;
                    }
                }

                Double childrenRaSum = tempMid.Sum(item => item.collection[0].R);
                int    k             = 0;

                if (diffD >= 0 && childrenRaSum == 0)
                {
                    foreach (CoverageAtomicRITE childNode in SubjectARITEs)
                    {
                        tempMid[k].collection[0].R = childNode.GetLossState().GetTotalSum.R;
                        k++;
                    }
                    childrenRaSum = tempMid.Sum(item => item.collection[0].R);
                }

                k = 0;
                foreach (CoverageAtomicRITE childNode in SubjectARITEs)
                {
                    if (currTermNode.GetLossState().GetTotalSum.R == 0)
                    {
                        tempMid[k].collection[0].R = 0;
                    }
                    else if (childrenRaSum > 0)
                    {
                        tempMid[k].collection[0].R = currTermNode.GetLossState().GetTotalSum.R *tempMid[k].collection[0].R / childrenRaSum;
                    }

                    if (tempMid[k].collection[0].R > childNode.GetAllocState().GetTotalSum.R ||
                        (tempMid[k].collection[0].R == childNode.GetAllocState().GetTotalSum.R&&
                         tempMid[k].collection[0].D > childNode.GetAllocState().GetTotalSum.D))
                    {
                        for (int i = 0; i < childNode.GetAllocState().NumBldgs; i++)
                        {
                            MidAllocationStateCollection[k].collection[i].D = tempMid[k].collection[0].D * childNode.GetAllocState().collection[i].S / childNode.GetAllocState().GetTotalSum.S;
                            MidAllocationStateCollection[k].collection[i].R = tempMid[k].collection[0].R * childNode.GetAllocState().collection[i].S / childNode.GetAllocState().GetTotalSum.S;
                            MidAllocationStateCollection[k].collection[i].S = childNode.GetAllocState().collection[i].S;
                        }
                        childNode.SetAllocState(MidAllocationStateCollection[k]);
                    }
                    k++;
                }
            }
        }
Beispiel #12
0
        protected Dictionary <TermNode, HashSet <TermNode> > FormGereralTermGraphNonOverlapped(NodeTree _completeGraph, out Dictionary <TermNode, HashSet <TermNode> > termGraphChildParentsMap)
        {
            Dictionary <TermNode, HashSet <TermNode> > TermCPMap = _completeGraph.TermChildParentsMap;
            Dictionary <TermNode, HashSet <TermNode> > TermPCMap = _completeGraph.TermParentChildrenMap;

            //TermNodes relationship after Transitive Reduction
            Dictionary <TermNode, HashSet <TermNode> > ReducedTermCPMap = new Dictionary <TermNode, HashSet <TermNode> >();
            Dictionary <TermNode, HashSet <TermNode> > ReducedTermPCMap = new Dictionary <TermNode, HashSet <TermNode> >();

            //form levels
            Dictionary <int, HashSet <TermNode> > nodesByLevel = new Dictionary <int, HashSet <TermNode> >();

            //find the levels
            int numOfNodeLevels = 0;

            nodesByLevel = SetLevels(TermCPMap, out numOfNodeLevels);

            HashSet <TermNode> cSet;
            HashSet <TermNode> pSet;

            //if there are no TermNodes, no transitive rduction, do nothing
            if (numOfNodeLevels == 0)
            {
            }

            for (int j = 0; j < numOfNodeLevels; j++)
            {
                foreach (TermNode node in nodesByLevel[j])
                {
                    TermNode tNode = node as TermNode;
                    cSet = new HashSet <TermNode>();
                    pSet = new HashSet <TermNode>();

                    if (TermPCMap.ContainsKey(tNode))
                    {
                        cSet.UnionWith(TermPCMap[tNode]);
                    }

                    if (TermCPMap.ContainsKey(tNode))
                    {
                        pSet.UnionWith(TermCPMap[tNode]);
                    }

                    if ((j + 1) < numOfNodeLevels)
                    {
                        cSet.IntersectWith(nodesByLevel[j + 1]);
                    }

                    if ((j - 1) > 0)
                    {
                        pSet.IntersectWith(nodesByLevel[j - 1]);
                    }

                    ReducedTermCPMap.Add(tNode, pSet);  //every node will be added to child-parents map

                    if (cSet.Count() > 0)
                    {
                        ReducedTermPCMap.Add(tNode, cSet); //only nodes with children will be added to PC map
                    }
                }
            }

            termGraphChildParentsMap = ReducedTermCPMap;
            return(ReducedTermPCMap);
        }
Beispiel #13
0
 public TermFunctionalEngine_2(TermNode _currNode, Aggregation _aggType)
 {
     CurrNode = _currNode;
     AggType  = _aggType;
 }
Beispiel #14
0
 public TermFunctionalEngine(TermNode _currNode, Aggregation _aggType)
 {
     CurrNode = _currNode;
     AggType  = _aggType;
     multiArr = CurrNode.PrimarySubject.Schedule.MultiplierArr;
 }
Beispiel #15
0
        public override void Initialize()
        {
            ////Build Graph here....
            //_graphNodes = new List<GraphNode>();
            //_parentToChildrenMap = new Dictionary<GraphNode, List<GraphNode>>();
            //_rites = new List<RITE>();
            //_schedules = new List<Schedule>();
            //_characteristics = new List<RITCharacteristic>();

            ////Add Contract Declarations
            //Declarations = new Declarations();

            ////Create RITECharacteristics
            //RITCharacteristic RITChar18 = new RITCharacteristic(19419518, ExposureType.Building, 100000);
            //RITCharacteristic RITChar19 = new RITCharacteristic(19419519, ExposureType.Contents, 10000);
            //RITCharacteristic RITChar20 = new RITCharacteristic(19419520, ExposureType.Building, 100000);
            //RITCharacteristic RITChar21 = new RITCharacteristic(19419521, ExposureType.Contents, 10000);
            //_characteristics.Add(RITChar18);
            //_characteristics.Add(RITChar19);
            //_characteristics.Add(RITChar20);
            //_characteristics.Add(RITChar21);

            ////Create RITEs
            //RITE rite57 = new RITE(11324657, 1);
            //rite57.AddCharacteristic(RITChar18);
            //rite57.AddCharacteristic(RITChar19);
            //RITE rite58 = new RITE(11324658, 1);
            //rite58.AddCharacteristic(RITChar20);
            //rite58.AddCharacteristic(RITChar21);
            //_rites.Add(rite57);
            //_rites.Add(rite58);

            ////Create Schedules
            //Schedule S2729_EQ = new Schedule("S2729.EQ");
            //S2729_EQ.AddRITE(rite57);
            //S2729_EQ.AddRITE(rite58);
            //_schedules.Add(S2729_EQ);

            //Schedule S2729_EQ_59491 = new Schedule("S2729.EQ.59491");
            //S2729_EQ_59491.AddRITE(rite57);
            //_schedules.Add(S2729_EQ_59491);

            //Schedule S2729_EQ_59492 = new Schedule("S2729.EQ.59492");
            //S2729_EQ_59492.AddRITE(rite58);
            //_schedules.Add(S2729_EQ_59492);

            //Create Schedules
            ScheduleOfRITEs S2729_EQ       = expdata.Schedules.ToList()[0];
            ScheduleOfRITEs S2729_EQ_59491 = expdata.Schedules.ToList()[1];
            ScheduleOfRITEs S2729_EQ_59492 = expdata.Schedules.ToList()[2];

            //Create Subjects
            PrimarySubject Node41Sub = new PrimarySubject(S2729_EQ_59491, Building, EQ);
            PrimarySubject Node42Sub = new PrimarySubject(S2729_EQ_59491, Contents, EQ);

            PrimarySubject Node31Sub = new PrimarySubject(S2729_EQ_59491, Loss, EQ);
            PrimarySubject Node32Sub = new PrimarySubject(S2729_EQ_59492, Loss, WS);

            PrimarySubject Node21Sub = new PrimarySubject(S2729_EQ, Loss, EQWS);

            //Create Nodes and Add to Node List
            //loccvg terms
            //TermNode Node41 = new TermNode(Node41Sub, false, false, 8000000, 10000000); //loccvg
            TermNode Node41 = new TermNode(Node41Sub); //loccvg

            graphNodes.Add(Node41);
            TermNode Node42 = new TermNode(Node42Sub);  //loccvg

            graphNodes.Add(Node42);

            //loc terms
            TermNode Node31 = new TermNode(Node31Sub); //loc

            graphNodes.Add(Node31);
            TermNode Node32 = new TermNode(Node32Sub); //loc

            graphNodes.Add(Node32);

            //policy term
            TermNode Node21 = new TermNode(Node21Sub);  //policy term, no limit term, so limit = 0?

            graphNodes.Add(Node21);

            //policy cover
            CoverNode Node11 = new CoverNode(Node21Sub, "L102_3222");  //policy layer

            graphNodes.Add(Node11);

            //Build Parent to Child Mapping
            List <GraphNode> Node11Children = new List <GraphNode>()
            {
                Node21
            };

            parentToChildrenMap.Add(Node11, Node11Children);

            List <GraphNode> Node21Children = new List <GraphNode>()
            {
                Node31, Node32
            };

            parentToChildrenMap.Add(Node21, Node21Children);

            List <GraphNode> Node31Children = new List <GraphNode>()
            {
                Node41, Node42
            };

            parentToChildrenMap.Add(Node31, Node31Children);

            TopNodes = new List <GraphNode>()
            {
                Node11
            };
            GraphReady = true;
        } //end of Initialize
Beispiel #16
0
        private void ExecuteOverlappedGraph(GUInputEngine guLossesEngine)
        {
            List <int> levelList = new List <int>();

            foreach (int aLevel in graph.LevelNodeDict.Keys)
            {
                levelList.Add(aLevel);
            }


            for (int i = levelList.Max(); i > 0; i--)
            {
                HashSet <CoverageAtomicRITE> wholeList = new HashSet <CoverageAtomicRITE>();
                foreach (GraphNode currNode in graph.LevelNodeDict[i])
                {
                    //they should be all TermNode
                    TermNode currTermNode = currNode as TermNode;

                    //find its AtomicRITEs
                    HashSet <AtomicRITE> SubjectARITEs = currTermNode.AllAtomicRITEs; //currTermNode.GetAtomicRites();

                    //HashSet<CoverageAtomicRITE> SubjectCRITEs = currTermNode.AllAtomicRITEs;
                    HashSet <CoverageAtomicRITE> SubjectCRITEs = new HashSet <CoverageAtomicRITE>();

                    foreach (AtomicRITE aRite in SubjectARITEs)
                    {
                        CoverageAtomicRITE cRite = aRite as CoverageAtomicRITE;
                        if (cRite == null)
                        {
                            throw new InvalidOperationException("Overlap AtomicRite has to be all CoverageAtomicRite");
                        }

                        SubjectCRITEs.Add(cRite);
                    }
                    List <GraphNode> childrenNodes = new List <GraphNode>();
                    childrenNodes = graph.GetChildrenForNode(currTermNode);

                    ExecuteOverlappedTermNode(currTermNode, childrenNodes, guLossesEngine, SubjectCRITEs);
                    currTermNode.Executed = true;
                    AllocateOverlappedTermNode(currTermNode, SubjectCRITEs);  //allocate back to the AtomicRites
                    wholeList.UnionWith(SubjectCRITEs);
                }

                //when this level is done, for each child AtomicRite
                //then copy the Allocated value to Loss value for next iteration
                foreach (CoverageAtomicRITE childNode in wholeList)
                {
                    //first compare AllocationState, Per-Building or Summed Wins
                    //if (childNode.GetAllocState().GetTotalSum.R > childNode.GetAllocationStateSummed().R ||
                    //    (childNode.GetAllocState().GetTotalSum.R == childNode.GetAllocationStateSummed().R &&
                    //    childNode.GetAllocState().GetTotalSum.D > childNode.GetAllocationStateSummed().D))
                    //{
                    for (int j = 0; j < childNode.RITE.ActNumOfBldgs; j++)
                    {
                        //childNode.GetLossState().collection[j].S = childNode.GetAllocationState().collection[j].S;
                        childNode.GetLossState().collection[j].R = childNode.GetAllocState().collection[j].R;
                        childNode.GetLossState().collection[j].D = childNode.GetAllocState().collection[j].D;
                        childNode.GetLossState().collection[j].X = childNode.GetLossState().collection[j].S - childNode.GetLossState().collection[j].R - childNode.GetLossState().collection[j].D;

                        childNode.GetAllocState().collection[j].R = 0;            //refresh to be compared
                    }
                    //}
                    //else
                    //{
                    //    double loss = childNode.GetLossState().GetTotalSum.S;
                    //    childNode.ResetLossState(1);
                    //    childNode.GetLossState().collection[0].S = loss;
                    //    childNode.GetLossState().collection[0].R = childNode.GetAllocationStateSummed().R;
                    //    childNode.GetLossState().collection[0].D = childNode.GetAllocationStateSummed().D;
                    //    childNode.GetLossState().collection[0].X = childNode.GetLossState().collection[0].S - childNode.GetLossState().collection[0].R - childNode.GetLossState().collection[0].D;

                    //    //reset R for next level comparison
                    //    childNode.GetAllocationStateSummed().R = 0;
                    //}
                }
            }
            //then lelve i = 0, all are bottom CoverNode's which are connected to TermNode
            foreach (CoverNode currCoverNode in graph.LevelNodeDict[0])
            {                                                                              //simple sum up all children's R
                HashSet <AtomicRITE>         SubjectARITEs = currCoverNode.AllAtomicRITEs; //currCoverNode.AllAtomicRITEs;
                HashSet <CoverageAtomicRITE> SubjectCRITEs = new HashSet <CoverageAtomicRITE>();
                foreach (AtomicRITE aRite in SubjectARITEs)
                {
                    CoverageAtomicRITE cRite = aRite as CoverageAtomicRITE;
                    SubjectCRITEs.Add(cRite);
                }
                //HashSet<CoverageAtomicRITE> SubjectCRITEs = currCoverNode.Subject.GetAtomicRites();
                currCoverNode.Payout = SubjectCRITEs.Sum(item => item.GetLossState().GetTotalSum.R);
                CoverNodeFunctionalEngine coverNodeFuncEng = new CoverNodeFunctionalEngine(currCoverNode);
                coverNodeFuncEng.CoverNodeFunction();
                currCoverNode.Executed = true;
                AllocateOverlappedCoverNode(currCoverNode, SubjectCRITEs);
            }
        }
Beispiel #17
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();
            }
        }
Beispiel #18
0
        public override void Initialize()
        {
            // //Create RITECharacteristics
            // RITCharacteristic RITChar18 = new RITCharacteristic(19419518, ExposureType.Building, 100000);
            // RITCharacteristic RITChar19 = new RITCharacteristic(19419519, ExposureType.Contents, 10000);
            // RITCharacteristic RITChar20 = new RITCharacteristic(19419520, ExposureType.Building, 100000);
            // RITCharacteristic RITChar21 = new RITCharacteristic(19419521, ExposureType.Contents, 10000);
            // _characteristics.Add(RITChar18);
            // _characteristics.Add(RITChar19);
            // _characteristics.Add(RITChar20);
            // _characteristics.Add(RITChar21);

            // //Create RITEs
            // RITE rite57 = new RITE(11324657, 1);
            // rite57.AddCharacteristic(RITChar18);
            // rite57.AddCharacteristic(RITChar19);
            // RITE rite58 = new RITE(11324658, 1);
            // rite58.AddCharacteristic(RITChar20);
            // rite58.AddCharacteristic(RITChar21);
            // _rites.Add(rite57);
            // _rites.Add(rite58);

            // //Create AtomicRITE
            //// AtomicRITE(string _subperil, ExposureType _expType, RITE _rite, long ID)
            // AtomicRITE aRite5718EQ = new AtomicRITE("EQ", ExposureType.Building, rite57, 19419518);
            // AtomicRITE aRite5718WS = new AtomicRITE("WS", ExposureType.Building, rite57, 19419518);
            // AtomicRITE aRite5719EQ = new AtomicRITE("EQ", ExposureType.Building, rite57, 19419519);
            // AtomicRITE aRite5719WS = new AtomicRITE("WS", ExposureType.Building, rite57, 19419519);
            // AtomicRITE aRite5820EQ = new AtomicRITE("EQ", ExposureType.Building, rite58, 19419520);
            // AtomicRITE aRite5820WS = new AtomicRITE("WS", ExposureType.Building, rite58, 19419520);
            // AtomicRITE aRite5821EQ = new AtomicRITE("EQ", ExposureType.Building, rite58, 19419521);
            // AtomicRITE aRite5821WS = new AtomicRITE("WS", ExposureType.Building, rite58, 19419521);

            // _atomicCoverageRITEs.Add(aRite5718EQ);
            // _atomicCoverageRITEs.Add(aRite5718WS);
            // _atomicCoverageRITEs.Add(aRite5719EQ);
            // _atomicCoverageRITEs.Add(aRite5719WS);
            // _atomicCoverageRITEs.Add(aRite5820EQ);
            // _atomicCoverageRITEs.Add(aRite5820WS);
            // _atomicCoverageRITEs.Add(aRite5821EQ);
            // _atomicCoverageRITEs.Add(aRite5821WS);

            //Create Schedules
            ScheduleOfRITEs S2729_EQ       = expdata.Schedules.ToList()[0];
            ScheduleOfRITEs S2729_EQ_59491 = expdata.Schedules.ToList()[1];
            ScheduleOfRITEs S2729_EQ_59492 = expdata.Schedules.ToList()[2];

            //Create Subjects
            PrimarySubject Node41Sub = new PrimarySubject(S2729_EQ_59491, Building, EQ);
            PrimarySubject Node42Sub = new PrimarySubject(S2729_EQ_59491, Contents, EQ);

            PrimarySubject Node31Sub = new PrimarySubject(S2729_EQ_59491, Loss, EQ);
            PrimarySubject Node32Sub = new PrimarySubject(S2729_EQ_59492, Loss, EQ);

            PrimarySubject Node21Sub = new PrimarySubject(S2729_EQ, Loss, EQ);

            ///////////// New Contructors for Node, for reading from JSON prototype///Sunny
            //Create Nodes and Add to Node List
            //loccvg terms
            //TermNode Node41 = new TermNode(Node41Sub, false, false, 8000000, 10000000); //loccvg
            TermNode Node41 = new TermNode(Node41Sub); //loccvg

            graphNodes.Add(Node41);
            TermNode Node42 = new TermNode(Node42Sub);  //loccvg

            graphNodes.Add(Node42);

            //loc terms
            TermNode Node31 = new TermNode(Node31Sub); //loc

            graphNodes.Add(Node31);
            TermNode Node32 = new TermNode(Node32Sub); //loc

            graphNodes.Add(Node32);

            //policy term
            TermNode Node21 = new TermNode(Node21Sub);  //policy term, no limit term, so limit = 0?

            graphNodes.Add(Node21);

            //policy cover
            CoverNode Node11 = new CoverNode(Node21Sub, "L102_3222");  //policy layer

            graphNodes.Add(Node11);

            //Build Parent to Child Mapping
            List <GraphNode> Node11Children = new List <GraphNode>()
            {
                Node21
            };

            parentToChildrenMap.Add(Node11, Node11Children);

            List <GraphNode> Node21Children = new List <GraphNode>()
            {
                Node31, Node32
            };

            parentToChildrenMap.Add(Node21, Node21Children);

            List <GraphNode> Node31Children = new List <GraphNode>()
            {
                Node41, Node42
            };

            parentToChildrenMap.Add(Node31, Node31Children);

            AssignLevelToNode();

            TopNodes = new List <GraphNode>()
            {
                Node11
            };

            BuildAtomicRITEs();

            GraphReady = true;
        } //end of Initialize
Beispiel #19
0
        private void RecursiveExecution(GraphNode currNode, GUInputEngine guLossesEngine)
        {
            Aggregation aggType = Aggregation.Summed;

            if (currNode is TermNode)
            {
                TermNode currTermNode = currNode as TermNode;

                //Execution for Term Node here...
                if (currTermNode.Executed == true)
                {
                    return;
                }

                //execute child node first
                List <GraphNode> childrenNodes     = graph.GetChildrenForNode(currTermNode);
                List <TermNode>  childrenTermNodes = new List <TermNode>();

                foreach (GraphNode childNode in childrenNodes)
                //Parallel.ForEach(childrenNodes, childNode =>
                {
                    TermNode childTermNode = childNode as TermNode;
                    if (childTermNode == null)
                    {
                        throw new InvalidOperationException("Term node's children must be Term node.");
                    }
                    childrenTermNodes.Add(childTermNode);

                    if (childNode.Executed == false)
                    {
                        RecursiveExecution(childTermNode, guLossesEngine);
                    }
                }
                //);
                //has not executed, get the GU loss first
                double[] inputlosses;

                //inputlosses = graph.GetNodeSubjectLoss(currTermNode).AllLoss().Zip(currTermNode.PrimarySubject.Schedule.MultiplierArr, (d1, d2) => d1 * d2).ToArray();
                inputlosses = graph.GetNodeSubjectLoss(currTermNode).AllLoss();
                currTermNode.CurrentLossStateCollection.SetSubjectLosses(inputlosses);

                if (currTermNode.IsPerRisk == true && 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 (childrenNodes.Count > 0)
                {
                    //initialize InterObj
                    InteractionObject[]  InterObj = GetInterObj(currTermNode, aggType, childrenTermNodes);
                    TermFunctionalEngine tFunEng  = new TermFunctionalEngine(currTermNode, aggType);
                    tFunEng.TermFunction(InterObj);

                    //Interaction
                    //InteractionEngine InterEng = new InteractionEngine(currTermNode, aggType, InterObj);
                    //InterEng.Interaction();
                }
                else
                {
                    TermFunctionalEngine tFunEng = new TermFunctionalEngine(currTermNode, aggType);
                    tFunEng.TermFunction(new InteractionObject[0]); //no interaction
                }

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

                currTermNode.Executed = true;
            }
            else  //currNode is Cover Node
            {
                CoverNode currCoverNode = currNode as CoverNode;

                //Execution for Cover Node here...
                if (currCoverNode.Executed == true)
                {
                    return;
                }

                foreach (AtomicRITE aRite in currCoverNode.ResidualAtomicRITEs)
                {
                    currCoverNode.Payout += aRite.GetLossState().GetTotalSum.R;
                }

                // Parallel.ForEach(graph.GetChildrenForNode(currCoverNode), childNode =>
                foreach (GraphNode childNode in graph.GetChildrenForNode(currCoverNode))
                {
                    RecursiveExecution(childNode, guLossesEngine);

                    if (childNode is TermNode)
                    {
                        TermNode childTermNode = childNode as TermNode;
                        //LossState currentLossState = new LossState(childTermNode.CurrentLossStateCollection.GetTotalSum);

                        //currCoverNode.Payout += currentLossState.R;
                        currCoverNode.Payout += childTermNode.CurrentLossStateCollection.GetTotalSum.R;
                    }
                    else
                    {
                        CoverNode childCoverNode = childNode as CoverNode;
                        currCoverNode.Payout += childCoverNode.Payout;
                    }
                }
                // );

                CoverNodeFunctionalEngine coverNodeFuncEng = new CoverNodeFunctionalEngine(currCoverNode);
                coverNodeFuncEng.CoverNodeFunction();
                currCoverNode.Executed = true;
            } //currNode is Cover Node
        }
Beispiel #20
0
        public override void Initialize()
        {
            ////Build Graph here....
            //_graphNodes = new List<GraphNode>();
            //_parentToChildrenMap = new Dictionary<GraphNode, List<GraphNode>>();
            //_rites = new List<RITE>();
            //_schedules = new List<Schedule>();
            //_characteristics = new List<RITCharacteristic>();
            //_atomicCoverageRITEs = new HashSet<AtomicRITE>();

            ////Add Contract Declarations
            //Declarations = new Declarations();

            ////Create RITECharacteristics
            ////Rite 11334
            //RITCharacteristic RITChar53 = new RITCharacteristic(3253, ExposureType.Building, 1000000);
            //RITCharacteristic RITChar54 = new RITCharacteristic(3254, ExposureType.Contents, 500000);
            //RITCharacteristic RITChar55 = new RITCharacteristic(3255, ExposureType.BI, 100000);

            ////Rite 11332
            //RITCharacteristic RITChar56 = new RITCharacteristic(3256, ExposureType.Building, 2000000);
            //RITCharacteristic RITChar57 = new RITCharacteristic(3257, ExposureType.Contents, 1000000);
            //RITCharacteristic RITChar58 = new RITCharacteristic(3258, ExposureType.BI, 500000);

            ////Rite 11333
            //RITCharacteristic RITChar59 = new RITCharacteristic(3259, ExposureType.Building, 500000);
            //RITCharacteristic RITChar60 = new RITCharacteristic(3260, ExposureType.Contents, 500000);
            //RITCharacteristic RITChar61 = new RITCharacteristic(3261, ExposureType.BI, 50000);

            //_characteristics.Add(RITChar53);
            //_characteristics.Add(RITChar54);
            //_characteristics.Add(RITChar55);
            //_characteristics.Add(RITChar56);
            //_characteristics.Add(RITChar57);
            //_characteristics.Add(RITChar58);
            //_characteristics.Add(RITChar59);
            //_characteristics.Add(RITChar60);
            //_characteristics.Add(RITChar61);

            ////Create RITEs
            //RITE rite34 = new RITE(11334, 1);
            //rite34.AddCharacteristic(RITChar53);
            //rite34.AddCharacteristic(RITChar54);
            //rite34.AddCharacteristic(RITChar55);

            //RITE rite32 = new RITE(11332, 1);
            //rite32.AddCharacteristic(RITChar56);
            //rite32.AddCharacteristic(RITChar57);
            //rite32.AddCharacteristic(RITChar58);

            //RITE rite33 = new RITE(11333, 1);
            //rite33.AddCharacteristic(RITChar59);
            //rite33.AddCharacteristic(RITChar60);
            //rite33.AddCharacteristic(RITChar61);

            //_rites.Add(rite32);
            //_rites.Add(rite33);
            //_rites.Add(rite34);

            ////Create AtomicRITE
            //// AtomicRITE(string _subperil, ExposureType _expType, RITE _rite, long ID)
            //AtomicRITE aRite3453EQ = new AtomicRITE("EQ", ExposureType.Building, rite34, 11334);
            //AtomicRITE aRite3454EQ = new AtomicRITE("EQ", ExposureType.Contents, rite34, 11334);
            //AtomicRITE aRite3455EQ = new AtomicRITE("EQ", ExposureType.BI, rite34, 11334);

            //AtomicRITE aRite3256EQ = new AtomicRITE("EQ", ExposureType.Building, rite32, 11332);
            //AtomicRITE aRite3257EQ = new AtomicRITE("EQ", ExposureType.Contents, rite32, 11332);
            //AtomicRITE aRite3258EQ = new AtomicRITE("EQ", ExposureType.BI, rite32, 11332);

            //AtomicRITE aRite3359EQ = new AtomicRITE("EQ", ExposureType.Building, rite33, 11333);
            //AtomicRITE aRite3360EQ = new AtomicRITE("EQ", ExposureType.Contents, rite33, 11333);
            //AtomicRITE aRite3361EQ = new AtomicRITE("EQ", ExposureType.BI, rite33, 11333);

            //_atomicCoverageRITEs.Add(aRite3453EQ);
            //_atomicCoverageRITEs.Add(aRite3454EQ);
            //_atomicCoverageRITEs.Add(aRite3455EQ);
            //_atomicCoverageRITEs.Add(aRite3256EQ);
            //_atomicCoverageRITEs.Add(aRite3257EQ);
            //_atomicCoverageRITEs.Add(aRite3258EQ);
            //_atomicCoverageRITEs.Add(aRite3359EQ);
            //_atomicCoverageRITEs.Add(aRite3360EQ);
            //_atomicCoverageRITEs.Add(aRite3361EQ);

            ////Create Schedules
            //Schedule S16_EQ = new Schedule("S16.EQ");
            //S16_EQ.AddRITE(rite32);
            //S16_EQ.AddRITE(rite33);
            //S16_EQ.AddRITE(rite34);
            //_schedules.Add(S16_EQ);

            //Schedule S16_EQ_5229 = new Schedule("S16.EQ.SubPolicy5229");
            //S16_EQ_5229.AddRITE(rite34);
            //S16_EQ_5229.AddRITE(rite32);
            //_schedules.Add(S16_EQ_5229);

            //Schedule S16_EQ_5229_5228 = new Schedule("S16.EQ.SubPolicy5229.SubPolicy5228");
            //S16_EQ_5229_5228.AddRITE(rite34);
            //_schedules.Add(S16_EQ_5229_5228);

            //Schedule S16_EQ_5229_5228_46 = new Schedule("S16.EQ.SubPolicy5229.SubPolicy5228.46");
            //S16_EQ_5229_5228.AddRITE(rite34);
            //_schedules.Add(S16_EQ_5229_5228_46);

            //Schedule S16_EQ_5229_47 = new Schedule("S16.EQ.SubPolicy5229.47");
            //S16_EQ_5229_5228.AddRITE(rite32);
            //_schedules.Add(S16_EQ_5229_47);

            //Schedule S16_EQ_48 = new Schedule("S16.EQ.48");
            //S16_EQ_48.AddRITE(rite33);
            //_schedules.Add(S16_EQ_48);

            //Create Schedules
            ScheduleOfRITEs S16_EQ              = expdata.Schedules.ToList()[0]; //new Schedule("S16.EQ");
            ScheduleOfRITEs S16_EQ_5229         = expdata.Schedules.ToList()[1]; //new Schedule("S16.EQ.SubPolicy5229");
            ScheduleOfRITEs S16_EQ_5229_5228    = expdata.Schedules.ToList()[2]; //new Schedule("S16.EQ.SubPolicy5229.SubPolicy5228");
            ScheduleOfRITEs S16_EQ_5229_5228_46 = expdata.Schedules.ToList()[3]; //new Schedule("S16.EQ.SubPolicy5229.SubPolicy5228.46");
            ScheduleOfRITEs S16_EQ_5229_47      = expdata.Schedules.ToList()[4]; //new Schedule("S16.EQ.SubPolicy5229.47");
            ScheduleOfRITEs S16_EQ_48           = expdata.Schedules.ToList()[5]; //new Schedule("S16.EQ.48");

            //Create Subjects
            PrimarySubject Node53Sub = new PrimarySubject(S16_EQ_5229_5228_46, Building, EQ);
            PrimarySubject Node54Sub = new PrimarySubject(S16_EQ_5229_5228_46, Contents, EQ);
            PrimarySubject Node55Sub = new PrimarySubject(S16_EQ_5229_5228_46, BI, EQ);

            PrimarySubject Node56Sub = new PrimarySubject(S16_EQ_5229_47, Building, EQ);
            PrimarySubject Node57Sub = new PrimarySubject(S16_EQ_5229_47, Contents, EQ);
            PrimarySubject Node58Sub = new PrimarySubject(S16_EQ_5229_47, BI, EQ);

            PrimarySubject Node59Sub = new PrimarySubject(S16_EQ_48, Building, EQ);
            PrimarySubject Node60Sub = new PrimarySubject(S16_EQ_48, Contents, EQ);
            PrimarySubject Node61Sub = new PrimarySubject(S16_EQ_48, BI, EQ);

            PrimarySubject Node46Sub = new PrimarySubject(S16_EQ_5229_5228_46, Loss, EQ);
            PrimarySubject Node47Sub = new PrimarySubject(S16_EQ_5229_47, Loss, EQ);
            PrimarySubject Node48Sub = new PrimarySubject(S16_EQ_48, Loss, EQ);

            PrimarySubject NodeBSub  = new PrimarySubject(S16_EQ, Building, EQ);
            PrimarySubject NodeCSub  = new PrimarySubject(S16_EQ, Contents, EQ);
            int            ii        = 4;
            PrimarySubject NodeBISub = new PrimarySubject(S16_EQ, BI, EQ);

            PrimarySubject Node21Sub = new PrimarySubject(S16_EQ, Loss, EQ);

            //Nodes
            TermNode Node53 = new TermNode(Node53Sub); //loccvg

            graphNodes.Add(Node53);
            TermNode Node54 = new TermNode(Node54Sub); //loccvg

            graphNodes.Add(Node54);
            TermNode Node55 = new TermNode(Node55Sub); //loccvg

            graphNodes.Add(Node55);

            TermNode Node56 = new TermNode(Node56Sub); //loccvg

            graphNodes.Add(Node56);
            TermNode Node57 = new TermNode(Node57Sub); //loccvg

            graphNodes.Add(Node57);
            TermNode Node58 = new TermNode(Node58Sub); //loccvg

            graphNodes.Add(Node58);

            TermNode Node59 = new TermNode(Node59Sub); //loccvg

            graphNodes.Add(Node59);
            TermNode Node60 = new TermNode(Node60Sub); //loccvg

            graphNodes.Add(Node60);
            TermNode Node61 = new TermNode(Node61Sub); //loccvg

            graphNodes.Add(Node61);

            //loc term
            TermNode Node46 = new TermNode(Node46Sub);  //loc

            graphNodes.Add(Node46);
            TermNode Node47 = new TermNode(Node47Sub);  //loc

            graphNodes.Add(Node47);
            TermNode Node48 = new TermNode(Node48Sub);  //loc

            graphNodes.Add(Node48);

            //policy coverage
            TermNode NodeB = new TermNode(NodeBSub);

            graphNodes.Add(NodeB);
            TermNode NodeC = new TermNode(NodeCSub);

            graphNodes.Add(NodeC);
            TermNode NodeBI = new TermNode(NodeBISub);

            graphNodes.Add(NodeBI);

            TermNode Node21 = new TermNode(Node21Sub);

            graphNodes.Add(Node21);

            //policy cover
            CoverNode Node11 = new CoverNode(Node21Sub, "L938_365");

            graphNodes.Add(Node11);

            //Build Parent to Child Mapping
            List <GraphNode> Node11Children = new List <GraphNode>()
            {
                Node21
            };

            parentToChildrenMap.Add(Node11, Node11Children);

            List <GraphNode> Node21Children = new List <GraphNode>()
            {
                Node46, Node47, Node48, NodeB, NodeC, NodeBI
            };

            parentToChildrenMap.Add(Node21, Node21Children);

            //List<GraphNode> Node32Children = new List<GraphNode>() { Node46, Node31, Node47 };
            //_parentToChildrenMap.Add(Node32, Node32Children);

            //List<GraphNode> Node31Children = new List<GraphNode>() { Node46 };
            //_parentToChildrenMap.Add(Node31, Node31Children);

            List <GraphNode> Node46Children = new List <GraphNode>()
            {
                Node53, Node54, Node55
            };

            parentToChildrenMap.Add(Node46, Node46Children);

            List <GraphNode> Node47Children = new List <GraphNode>()
            {
                Node56, Node57, Node58
            };

            parentToChildrenMap.Add(Node47, Node47Children);

            List <GraphNode> Node48Children = new List <GraphNode>()
            {
                Node59, Node60, Node61
            };

            parentToChildrenMap.Add(Node48, Node48Children);

            List <GraphNode> NodeBChildren = new List <GraphNode>()
            {
                Node53, Node56, Node59
            };

            parentToChildrenMap.Add(NodeB, NodeBChildren);

            List <GraphNode> NodeCChildren = new List <GraphNode>()
            {
                Node54, Node57, Node60
            };

            parentToChildrenMap.Add(NodeC, NodeCChildren);

            List <GraphNode> NodeBIChildren = new List <GraphNode>()
            {
                Node55, Node58, Node61
            };

            parentToChildrenMap.Add(NodeBI, NodeBIChildren);

            TopNodes = new List <GraphNode>()
            {
                Node11
            };
            AssignLevelToNode();
            BuildAtomicRITEs();
            GraphReady = true;
        } //end of Initialize