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
private void AllocateOverlappedCoverNode(CoverNode currCoverNode, HashSet <CoverageAtomicRITE> SubjectARITEs) { int numOfChildren = SubjectARITEs.Count; //for cover node, always allocate as summed Double childrenRSum = SubjectARITEs.Sum(item => item.GetLossState().GetTotalSum.R); Double childrenSSum = SubjectARITEs.Sum(item => item.GetLossState().GetTotalSum.S); AllocationStateCollection[] MidAllocationStateCollection = new AllocationStateCollection[numOfChildren]; int j = 0; foreach (CoverageAtomicRITE childNode in SubjectARITEs) { MidAllocationStateCollection[j] = new AllocationStateCollection(childNode.GetAllocState().NumBldgs); j++; } if (childrenRSum != 0) { j = 0; //child foreach (CoverageAtomicRITE childNode in SubjectARITEs) { //devided among children double temp = currCoverNode.GetPayout() * childNode.GetLossState().GetTotalSum.R / childrenRSum; for (int jj = 0; jj < childNode.GetAllocState().NumBldgs; jj++) { //divided among building if (childNode.GetLossState().GetTotalSum.S > 0) { MidAllocationStateCollection[j].collection[jj].P = temp * childNode.GetLossState().collection[jj].S / childNode.GetLossState().GetTotalSum.S; } else { MidAllocationStateCollection[j].collection[jj].P = temp / childNode.GetAllocState().NumBldgs; } } j++; } } else { j = 0; //child foreach (CoverageAtomicRITE childNode in SubjectARITEs) { //devided among children double temp = currCoverNode.GetPayout() * childNode.GetLossState().GetTotalSum.S / childrenSSum; for (int jj = 0; jj < childNode.GetAllocState().NumBldgs; jj++) { //divided among building if (childNode.GetLossState().GetTotalSum.S > 0) { MidAllocationStateCollection[j].collection[jj].P = temp * childNode.GetLossState().collection[jj].S / childNode.GetLossState().GetTotalSum.S; } else { MidAllocationStateCollection[j].collection[jj].P = temp / childNode.GetAllocState().NumBldgs; } } j++; } } j = 0; foreach (CoverageAtomicRITE childNode in SubjectARITEs) { for (int jj = 0; jj < childNode.GetAllocState().NumBldgs; jj++) { MidAllocationStateCollection[j].collection[jj].P += childNode.GetAllocState().collection[jj].P; MidAllocationStateCollection[j].collection[jj].S = childNode.GetAllocState().collection[jj].S; } childNode.SetAllocState(MidAllocationStateCollection[j]); j++; } }