public TermExecutionPosition_ObsoleteV1(TermExecutionPosition_ObsoleteV1 CopyFromThis) { components = new List <Component>(CopyFromThis.components.Count); foreach (Component __component in CopyFromThis.components) { components.Add(new Component(__component)); } NumBuildings = CopyFromThis.NumBuildings; }
public TermExecutionPosition_ObsoleteV1 Execute(List <TermExecutionPosition_ObsoleteV1> _SubjectPositions, Dictionary <SimpleExpression <SymbolicValue>, double> Bindings) { #region IF per-risk, multi-building if (IsMultiBuildingPerRisk()) { // Compute aggregate subject position TermExecutionPosition_ObsoleteV1 ExecutionPosition = _SubjectPositions.Aggregate(new TermExecutionPosition_ObsoleteV1(), (accumulator, it) => accumulator + it); List <TermExecutionPosition_ObsoleteV1.Component> SampledMultiBuildingOutputPositionComponents = new List <TermExecutionPosition_ObsoleteV1.Component>(); foreach (TermExecutionPosition_ObsoleteV1.Component SampledMultiBuildingExecutionPositionComponent in ExecutionPosition.components) { TermExecutionPosition_ObsoleteV1.Component SampledMultiBuildingOutputPositionComponent = new TermExecutionPosition_ObsoleteV1.Component(SampledMultiBuildingExecutionPositionComponent); Bindings.Remove(new SymbolicExpression("Subject")); Bindings.Add(new SymbolicExpression("Subject"), SampledMultiBuildingOutputPositionComponent.S); // Iterate over terms in this collection, in order foreach (IGenericTerm term in this.GetContent()) { double A = term.GetEvaluatedExpression(Bindings); if (term is ISublimit) { // Functional Form double X_ = 0.0; if (!(term as ISublimit).IsNetOfDeductible()) { // 1. Ground-up Sublimit X_ = Math.Max(SampledMultiBuildingOutputPositionComponent.S - A, 0.0); } else { // 5. Net of Deductible Sublimit X_ = Math.Max(SampledMultiBuildingOutputPositionComponent.S - SampledMultiBuildingOutputPositionComponent.D - A, 0.0); } // Interaction double X__ = Math.Max(SampledMultiBuildingOutputPositionComponent.X, X_); // Final Adjustment SampledMultiBuildingOutputPositionComponent.X = Math.Min(X__, SampledMultiBuildingOutputPositionComponent.S - SampledMultiBuildingOutputPositionComponent.D); } else // if (term is IDeductible) { // Functional Form double D_ = 0.0; if (!(term as IDeductible).IsFranchise()) { D_ = Math.Min(SampledMultiBuildingOutputPositionComponent.S, A); } else { D_ = (SampledMultiBuildingOutputPositionComponent.S > A) ? 0.0 : SampledMultiBuildingOutputPositionComponent.S; } // Interaction double D__ = 0.0; switch ((term as IDeductible).GetInteraction()) { case Interaction.SINGLELARGEST: D__ = _SubjectPositions.Select(s => s.components.Select(c => c.D).Max()).Max(); break; case Interaction.MIN: if (!(term as IDeductible).IsAbsorbable()) { D__ = Math.Max(SampledMultiBuildingOutputPositionComponent.D, D_); } else { D__ = Math.Max(SampledMultiBuildingOutputPositionComponent.D, D_ - SampledMultiBuildingOutputPositionComponent.X); } break; case Interaction.MAX: D__ = Math.Min(ExecutionPosition.D, D_); break; } // Final Adjustment SampledMultiBuildingOutputPositionComponent.D = Math.Min(D__, SampledMultiBuildingOutputPositionComponent.S - SampledMultiBuildingOutputPositionComponent.X); } } SampledMultiBuildingOutputPositionComponents.Add(SampledMultiBuildingOutputPositionComponent); } // Calculate number of buildings int NumBuildings = 1; Subject _TermNodeSubject = this.GetSubject(); if (_TermNodeSubject.PerRisk) { NumBuildings = _TermNodeSubject.NumBuildings; } return(new TermExecutionPosition_ObsoleteV1(SampledMultiBuildingOutputPositionComponents, NumBuildings)); } #endregion IF per-risk, multi-building #region Single-building OR Summed else { // Compute aggregate subject position & coalesce _SubjectPositions.ForEach(x => x.Coalesce()); TermExecutionPosition_ObsoleteV1 ExecutionPosition = _SubjectPositions.Aggregate(new TermExecutionPosition_ObsoleteV1(), (accumulator, it) => accumulator + it); ExecutionPosition.Coalesce(1); Bindings.Remove(new SymbolicExpression("Subject")); Bindings.Add(new SymbolicExpression("Subject"), ExecutionPosition.S); // Iterate over terms in this collection, in order foreach (IGenericTerm term in this.GetContent()) { double A = term.GetEvaluatedExpression(Bindings); if (term is ISublimit) { // Functional Form double X_ = 0.0; if (!(term as ISublimit).IsNetOfDeductible()) { // 1. Ground-up Sublimit X_ = Math.Max(ExecutionPosition.S - A, 0.0); } else { // 5. Net of Deductible Sublimit X_ = Math.Max(ExecutionPosition.S - ExecutionPosition.D - A, 0.0); } // Interaction double X__ = Math.Max(ExecutionPosition.X, X_); // Final Adjustment ExecutionPosition.X = Math.Min(X__, ExecutionPosition.S - ExecutionPosition.D); } else // if (term is IDeductible) { // Functional Form double D_ = 0.0; if (!(term as IDeductible).IsFranchise()) { D_ = Math.Min(ExecutionPosition.S, A); } else { D_ = (ExecutionPosition.S > A) ? 0.0 : ExecutionPosition.S; } // Interaction double D__ = 0.0; switch ((term as IDeductible).GetInteraction()) { case Interaction.SINGLELARGEST: D__ = _SubjectPositions.Select(s => s.D).Max(); break; case Interaction.MIN: if (!(term as IDeductible).IsAbsorbable()) { D__ = Math.Max(ExecutionPosition.D, D_); } else { D__ = Math.Max(ExecutionPosition.D, D_ - ExecutionPosition.X); } break; case Interaction.MAX: D__ = Math.Min(ExecutionPosition.D, D_); break; } // Final Adjustment ExecutionPosition.D = Math.Min(D__, ExecutionPosition.S - ExecutionPosition.X); } } return(ExecutionPosition); } #endregion Single-building OR Summed }