Beispiel #1
0
 public AllocationEngine(IAllocatable _parent, List <IAllocatable> _childrenNodes, StateType _ParentType, StateType _ChildrenType)
 {
     parent        = _parent;
     childrenNodes = _childrenNodes;
     ParentType    = _ParentType;
     ChildrenType  = _ChildrenType;
 }
Beispiel #2
0
        public List <IAllocatable> GetIAChildrenForIAllocatable(IAllocatable parentIA)
        {
            GraphNode parentNode = parentIA as GraphNode;

            List <IAllocatable> nodeList = new List <IAllocatable>();

            if (GraphNodes.Contains(parentNode))
            {
                if (ParentToChildrenMap.ContainsKey(parentNode))
                {
                    nodeList = ParentToChildrenMap[parentNode].Cast <IAllocatable>().ToList();
                }
            }
            else
            {
                throw new InvalidOperationException("Graph does not contain node specified!");
            }

            //add  AtomicRITE
            List <IAllocatable> aRiteList = new List <IAllocatable>();

            foreach (AtomicRITE aR in parentNode.ResidualAtomicRITEs)
            {
                IAllocatable aIA = aR as IAllocatable;
                aRiteList.Add(aIA);
            }

            return(nodeList.Union(aRiteList).ToList());
        }
Beispiel #3
0
        private void AllocateRecoverable(IAllocatable currNode, List <IAllocatable> childrenNodes)
        {
            Double childrenDSum  = childrenNodes.Sum(item => item.GetLossState().GetTotalSum.D);
            Double childrenRSum  = childrenNodes.Sum(item => item.GetLossState().GetTotalSum.R);
            Double diffD         = currNode.GetAllocState().GetTotalSum.D - childrenDSum;
            int    numOfChildren = childrenNodes.Count;

            if (childrenRSum == 0)
            {
                Double childrenSSum = childrenNodes.Sum(item => item.GetLossState().GetTotalSum.S);
                foreach (IAllocatable childNode in childrenNodes)
                {
                    childNode.GetAllocState().collection[0].R = currNode.GetAllocState().collection[0].R * childNode.GetLossState().GetTotalSum.S / childrenSSum;
                }
            }
            else if (diffD >= 0)
            {
                foreach (IAllocatable childNode in childrenNodes)
                {
                    childNode.GetAllocState().collection[0].R = (childNode.GetLossState().GetTotalSum.R *(1 - diffD / childrenRSum));
                    childNode.GetAllocState().collection[0].D = (childNode.GetLossState().GetTotalSum.S - childNode.GetLossState().GetTotalSum.X - childNode.GetAllocState().collection[0].R);
                }
            }
            else
            {
                foreach (IAllocatable childNode in childrenNodes)
                {
                    childNode.GetAllocState().collection[0].D = childNode.GetLossState().GetTotalSum.D *(1 + diffD / childrenDSum);
                    childNode.GetAllocState().collection[0].R = childNode.GetLossState().GetTotalSum.S - childNode.GetLossState().GetTotalSum.X - childNode.GetAllocState().collection[0].D;
                }
            }

            Double childrenRaSum = childrenNodes.Sum(item => item.GetAllocState().GetTotalSum.R);

            if (diffD >= 0 && childrenRaSum == 0)
            {
                foreach (IAllocatable childNode in childrenNodes)
                {
                    childNode.GetAllocState().collection[0].R = childNode.GetLossState().GetTotalSum.R;
                    childrenRaSum += childNode.GetLossState().GetTotalSum.R;
                }
            }
            foreach (IAllocatable childNode in childrenNodes)
            {
                if (currNode.GetAllocState().collection[0].R == 0)
                {
                    childNode.GetAllocState().collection[0].R = 0;
                }
                else if (childrenRaSum > 0)
                {
                    childNode.GetAllocState().collection[0].R = (currNode.GetAllocState().collection[0].R * childNode.GetAllocState().collection[0].R / childrenRaSum);
                }
            }
        }
Beispiel #4
0
        } //AllocateGraph

        private void RecursiveAllocateIAllocatable(IAllocatable currNode)
        {
            List <IAllocatable> childrenAndRites = graph.GetIAChildrenForIAllocatable(currNode);

            AllocationEngine allocater = new AllocationEngine(currNode, childrenAndRites, StateType.AllocatedState, StateType.LossState);

            allocater.Run();

            //Allocate all children nodes
            List <IAllocatable> childNodes = graph.GetChildrenForNode((GraphNode)currNode).Cast <IAllocatable>().ToList();

            foreach (IAllocatable childnode in childNodes)
            {
                RecursiveAllocateIAllocatable(childnode);
            }
        }
Beispiel #5
0
        public void AllocateGraph()
        {
            CoverNode topCover = graph.TopNodes[0] as CoverNode;

            if (topCover == null)
            {
                throw new InvalidOperationException("Top node must be a cover node! Cannot execute graph...");
            }

            IAllocatable topIA = topCover as IAllocatable;

            //init the allocation state to be the lossState
            topCover.GetAllocState().collection[0].P = topCover.GetPayout();

            RecursiveAllocateIAllocatable(topIA);
        } //AllocateGraph
Beispiel #6
0
        private void AllocatePayout(IAllocatable currNode, List <IAllocatable> childrenNodes)
        {
            int numOfChildren = childrenNodes.Count;

            if (!parent.AllocateRecoverableFirst) //need copy LossState R, D, S, X to AllocationState
            {
                foreach (IAllocatable childNode in childrenNodes)
                {
                    if (childNode.AllocateByRecoverable)
                    {
                        childNode.GetAllocState().collection[0].R = childNode.GetLossState().GetTotalSum.R;
                        childNode.GetAllocState().collection[0].D = childNode.GetLossState().GetTotalSum.D;
                        childNode.GetAllocState().collection[0].X = childNode.GetLossState().GetTotalSum.X;
                        childNode.GetAllocState().collection[0].S = childNode.GetLossState().GetTotalSum.S;
                    }
                }
            }

            double childrenPSum = childrenNodes.Sum(item => item.GetAllocState().collection[0].P);
            double childrenRSum = childrenNodes.Sum(item => item.GetAllocState().collection[0].R);

            if ((childrenPSum == 0 && !currNode.AllocateByRecoverable) || (childrenRSum == 0 && currNode.AllocateByRecoverable))
            {
                double childrenSSum = childrenNodes.Sum(item => item.GetLossState().GetTotalSum.S);
                foreach (IAllocatable childNode in childrenNodes)
                {
                    childNode.GetAllocState().collection[0].P = currNode.GetAllocState().collection[0].P * childNode.GetLossState().GetTotalSum.S / childrenSSum;
                }
            }
            else
            {
                if (currNode.AllocateByRecoverable)
                {
                    foreach (IAllocatable childNode in childrenNodes)
                    {
                        childNode.GetAllocState().collection[0].P = currNode.GetAllocState().collection[0].P * childNode.GetAllocState().collection[0].R / childrenRSum;
                    }
                }
                else
                {
                    foreach (IAllocatable childNode in childrenNodes)
                    {
                        childNode.GetAllocState().collection[0].P = currNode.GetAllocState().collection[0].P * childNode.GetAllocState().collection[0].P / childrenPSum;
                    }
                }
            }
        }
Beispiel #7
0
        private void AllocatePayout(IAllocatable currNode, List <IAllocatable> childrenNodes)
        {
            int numOfChildren = childrenNodes.Count;

            if (!parent.AllocateRecoverableFirst) //need copy LossState R, D, S, X to AllocationState
            {
                foreach (IAllocatable childNode in childrenNodes)
                {
                    if (childNode.AllocateByRecoverable)
                    {
                        childNode.GetAllocState().Recoverable[0] = childNode.GetLossState().GetTotalSum.R;
                        childNode.GetAllocState().Deductible[0]  = childNode.GetLossState().GetTotalSum.D;
                        childNode.GetAllocState().Excess[0]      = childNode.GetLossState().GetTotalSum.X;
                        childNode.GetAllocState().SubjectLoss[0] = childNode.GetLossState().GetTotalSum.S;
                    }
                }
            }

            double childrenPSum = childrenNodes.Sum(item => item.GetAllocState().Payout[0]);
            double childrenRSum = childrenNodes.Sum(item => item.GetAllocState().Recoverable[0]);

            if ((childrenPSum == 0 && !currNode.AllocateByRecoverable) || (childrenRSum == 0 && currNode.AllocateByRecoverable))
            {
                double childrenSSum = childrenNodes.Sum(item => item.GetLossState().GetTotalSum.S);
                foreach (IAllocatable childNode in childrenNodes)
                {
                    childNode.GetAllocState().Payout[0] = currNode.GetAllocState().Payout[0] * childNode.GetLossState().GetTotalSum.S / childrenSSum;
                }
            }
            else
            {
                if (currNode.AllocateByRecoverable)
                {
                    foreach (IAllocatable childNode in childrenNodes)
                    {
                        childNode.GetAllocState().Payout[0] = currNode.GetAllocState().Payout[0] * childNode.GetAllocState().Recoverable[0] / childrenRSum;
                    }
                }
                else
                {
                    foreach (IAllocatable childNode in childrenNodes)
                    {
                        childNode.GetAllocState().Payout[0] = currNode.GetAllocState().Payout[0] * childNode.GetAllocState().Payout[0] / childrenPSum;
                    }
                }
            }
        }