public Subject(UniversalSubjectPosition universalSubject, Schedule Schedule, HashSet <SymbolicValue> CausesOfLoss, HashSet <SymbolicValue> ExposuresTypes, Dictionary <string, HashSet <long> > resolvedSchedule = null, Dictionary <long, RiskItemCharacteristicIDAttributes> CoverageIdAttrMap = null, bool Resolution = false) { SetID(); this.UniversalSubject = universalSubject; this.CoverageIdAttrMap = CoverageIdAttrMap; this.Schedule = Schedule; this.RITEIds = new HashSet <long>(); if (resolvedSchedule != null) { this.ResolvedSchedule = resolvedSchedule; foreach (SymbolicValue ScheduleSymbol in this.Schedule.ScheduleSymbols) { if (ResolvedSchedule != null) { if (ResolvedSchedule.ContainsKey(ScheduleSymbol.ToString())) { RITEIds.UnionWith(ResolvedSchedule[ScheduleSymbol.ToString()]); } } } } //this.RiskItemIds = new HashSet<long>(this.RITEIds.Select(x => CoverageIdAttrMap[x].RITExposureId).Distinct()); this.CausesOfLoss = CausesOfLoss; this.ExposureTypes = ExposuresTypes; this.ResolvedExposureTypes = new HashSet <int>(); foreach (SymbolicValue _ExposureType in ExposureTypes) { //ExposureType.ExposureTypeGroup ExposureTypeGroup = new ExposureType.ExposureTypeGroup(); //ExposureTypeGroup.Set((ExposureType.EExposureType)(Enum.Parse(typeof(ExposureType.EExposureType), _ExposureType.ToString()))); //ResolvedExposureTypes.UnionWith(ExposureTypeGroup.GetIndividualIntExposureTypes()); //TODO : Use the above approach (3 lines of code) when platform is fixed and ready ResolvedExposureTypes.UnionWith( ExposureType.GetIndividualIntExposureTypes( (ExposureType.EExposureType)(Enum.Parse(typeof(ExposureType.EExposureType), _ExposureType.ToString())) ) ); } // If all dimensions are empty, then subject is not constrained if ((this.ResolvedExposureTypes.Count == 0) && (this.CausesOfLoss.Count == 0) && (this.RITEIds.Count == 0)) { isNotConstrained = true; } // If any dimension is empty, set from universal subject if (UniversalSubject != null) { if (this.ResolvedExposureTypes.Count == 0) { this.ResolvedExposureTypes = UniversalSubject.ResolvedExposureTypes; } if (this.CausesOfLoss.Count == 0) { this.CausesOfLoss = UniversalSubjectPosition.CausesOfLoss; } if (this.RITEIds.Count == 0) { this.RITEIds = UniversalSubject.AllRITEIds; } } this.PerRisk = Resolution; // Build components //Components = new HashSet<Tuple<int, long, SymbolicValue>>(); Components = new Dictionary <SymbolicValue, Dictionary <int, Tuple <HashSet <long>, HashSet <long> > > >(); if (this.RITEIds == null) { throw new NullReferenceException("Universal Subject RITEs cannot be null (can be empty)!"); } if (this.RITEIds.Count != 0) { foreach (SymbolicValue CauseOfLoss in this.CausesOfLoss) { if (!Components.ContainsKey(CauseOfLoss)) { Components.Add(CauseOfLoss, new Dictionary <int, Tuple <HashSet <long>, HashSet <long> > >()); } foreach (int ResolvedExposureType in this.ResolvedExposureTypes) { if (!Components[CauseOfLoss].ContainsKey(ResolvedExposureType)) { Components[CauseOfLoss].Add(ResolvedExposureType, Tuple.Create(new HashSet <long>(), new HashSet <long>())); } foreach (long RITEId in this.RITEIds) { if (CoverageIdAttrMap.ContainsKey(RITEId) && CoverageIdAttrMap[RITEId].ExposureType.Equals(ResolvedExposureType)) { Components[CauseOfLoss][ResolvedExposureType].Item1.Add(RITEId); } else { Components[CauseOfLoss][ResolvedExposureType].Item2.Add(RITEId); } } if (Components[CauseOfLoss][ResolvedExposureType].Item1.Count == 0) { Components[CauseOfLoss].Remove(ResolvedExposureType); } } if (Components[CauseOfLoss].Count == 0) { Components.Remove(CauseOfLoss); } } } }
public void HardResetSchedule(HashSet <SymbolicValue> NewScheduleSymbols, Dictionary <string, HashSet <long> > resolvedSchedule) { Schedule.ScheduleSymbols = NewScheduleSymbols; this.RITEIds = new HashSet <long>(); if (resolvedSchedule != null) { this.ResolvedSchedule = resolvedSchedule; foreach (SymbolicValue ScheduleSymbol in this.Schedule.ScheduleSymbols) { if (ResolvedSchedule != null) { if (ResolvedSchedule.ContainsKey(ScheduleSymbol.ToString())) { RITEIds.UnionWith(ResolvedSchedule[ScheduleSymbol.ToString()]); } } } } // If all dimensions are empty, then subject is not constrained if ((this.ResolvedExposureTypes.Count == 0) && (this.CausesOfLoss.Count == 0) && (this.RITEIds.Count == 0)) { isNotConstrained = true; } // If any dimension is empty, set from universal subject if (UniversalSubject != null) { if (this.RITEIds.Count == 0) { if (this.RITEIds.Count == 0) { this.RITEIds = UniversalSubject.AllRITEIds; } } } // Rebuild components Components = new Dictionary <SymbolicValue, Dictionary <int, Tuple <HashSet <long>, HashSet <long> > > >(); foreach (SymbolicValue CauseOfLoss in this.CausesOfLoss) { if (!Components.ContainsKey(CauseOfLoss)) { Components.Add(CauseOfLoss, new Dictionary <int, Tuple <HashSet <long>, HashSet <long> > >()); } foreach (int ResolvedExposureType in this.ResolvedExposureTypes) { if (!Components[CauseOfLoss].ContainsKey(ResolvedExposureType)) { Components[CauseOfLoss].Add(ResolvedExposureType, Tuple.Create(new HashSet <long>(), new HashSet <long>())); } foreach (long RITEId in this.RITEIds) { if (CoverageIdAttrMap.ContainsKey(RITEId) && CoverageIdAttrMap[RITEId].ExposureType.Equals(ResolvedExposureType)) { Components[CauseOfLoss][ResolvedExposureType].Item1.Add(RITEId); } else { Components[CauseOfLoss][ResolvedExposureType].Item2.Add(RITEId); } } if (Components[CauseOfLoss][ResolvedExposureType].Item1.Count == 0) { Components[CauseOfLoss].Remove(ResolvedExposureType); } } if (Components[CauseOfLoss].Count == 0) { Components.Remove(CauseOfLoss); } } }