示例#1
0
        protected override void GetGUForAtomicRITEs(GUInputEngine guLossesEngine)
        {
            bool GotGUForAll = true;

            foreach (CoverageAtomicRITE aRITE in primaryGraph.GetCoverageRITEs())
            {
                guLossesEngine.GetGUForCoverageRITE(aRITE);
            }
        }
示例#2
0
        } //Execute

        private ExecutionOutput ExecuteWindow(TimeWindow timewindow, GUInputEngine guLossesEngine)
        {
            ApplyWindowToGU(timewindow);  //unrestricted, raintest

            List <CoverNode> TopCovers = graph.TopNodes.OfType <CoverNode>().ToList();

            ExecutionOutput totalExOutput = new ExecutionOutput();

            foreach (CoverNode coverNode in TopCovers)
            {
                totalExOutput += ExecuteCover(guLossesEngine, coverNode);
            }

            return(totalExOutput);
        }
示例#3
0
        public ExecutionOutput ExecuteCover(GUInputEngine guinputengine, CoverNode topCover)
        {
            if (graph.IsOverlapped == false)
            {
                RecursiveExecution(topCover, guinputengine);
                //Allocate Graph
                GraphAllocation Allocater = new GraphAllocation(graph);
                Allocater.AllocateGraph();
            }
            else
            {
                ExecuteOverlappedGraph(guinputengine);
            }

            graph.IsExecuted = true;
            graph.exResults  = new ExecutionOutput(topCover.Payout, graph.AtomicRites);
            return(graph.exResults);
        }
示例#4
0
        protected override void GetGUForAtomicRITEs(GUInputEngine guLossesEngine)
        {
            bool GotGUForAll = true;

            foreach (ContractAtomicRITE aRITE in treatyGraph.ContractRITEs)
            {
                if (!aRITE.contractGraph.IsExecuted)
                {
                    GraphExecuter executer;
                    if (aRITE.contractGraph is PrimaryGraph)
                    {
                        executer = new PrimaryGraphExecuter(aRITE.contractGraph as PrimaryGraph);
                    }
                    else
                    {
                        executer = new TreatyGraphExecuter(aRITE.contractGraph as TreatyGraph);
                    }

                    executer.Execute(guLossesEngine);
                }
            }
        }
示例#5
0
        } //Execute

        public double Execute(GUInputEngine guinputengine)
        {
            GetGUForAtomicRITEs(guinputengine);

            List <TimeWindow> timewindows;

            if (graph.Declarations.IsHoursClause)
            {
                timewindows = guinputengine.GenerateWindows(graph.Declarations.HoursClauses[0].Duration);
            }
            else
            {
                timewindows = new List <TimeWindow>()
                {
                    new TimeWindow()
                }
            };

            List <ExecutionOutput> lst_execoutputs = new List <ExecutionOutput>();

            foreach (TimeWindow tw in timewindows)
            {
                lst_execoutputs.Add(ExecuteWindow(tw, guinputengine));
            }

            //find the timewindow that has the maximum payout
            ExecutionOutput MaxPayout_ExecutionOutput = lst_execoutputs.First();

            foreach (ExecutionOutput exout in lst_execoutputs)
            {
                if (exout.Payout > MaxPayout_ExecutionOutput.Payout)
                {
                    MaxPayout_ExecutionOutput = exout;
                }
            }

            graph.exResults = MaxPayout_ExecutionOutput;
            return(MaxPayout_ExecutionOutput.Payout);
        } //Execute
示例#6
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
        }
示例#7
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();
            }
        }
示例#8
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);
            }
        }
示例#9
0
 protected abstract void GetGUForAtomicRITEs(GUInputEngine guLossesEngine);
示例#10
0
        public double Execute(Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > inputloss)
        {
            GUInputEngine guinputengine = new GUInputEngine(inputloss, graph);

            return(Execute(guinputengine));
        } //Execute