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); } } }
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; } } } }
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; } } } }