public override int GetHashCode() { int hash = 23; if (ScheduleSymbols != null && ScheduleSymbols.Count != 0) { foreach (SymbolicValue ScheduleSymbol in ScheduleSymbols) { hash = hash * 37 + ScheduleSymbol.GetHashCode(); } } return(hash); }
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); } } }
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 Subject(UniversalSubjectPosition universalSubject, Schedule Schedule, HashSet <SymbolicValue> CausesOfLoss, HashSet <SymbolicValue> ExposuresTypes, Dictionary <string, HashSet <long> > resolvedSchedule = null, Dictionary <long, int> coverageIdExposureTypeMap = null, bool Resolution = false) { this.UniversalSubject = universalSubject; this.CoverageIdExposureTypeMap = coverageIdExposureTypeMap; 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.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.GetResolvedExposureTypes(); } if (this.CausesOfLoss.Count == 0) { this.CausesOfLoss = UniversalSubjectPosition.GetCausesOfLoss(); } if (this.RITEIds.Count == 0) { this.RITEIds = UniversalSubject.GetAllRITEIds(); } } this.PerRisk = Resolution; // Build components //Components = new HashSet<Tuple<int, long, SymbolicValue>>(); Components = new Dictionary <SymbolicValue, Dictionary <int, HashSet <long> > >(); foreach (SymbolicValue CauseOfLoss in this.CausesOfLoss) { if (!Components.ContainsKey(CauseOfLoss)) { Components.Add(CauseOfLoss, new Dictionary <int, HashSet <long> >()); } foreach (int ResolvedExposureType in this.ResolvedExposureTypes) { if (!Components[CauseOfLoss].ContainsKey(ResolvedExposureType)) { Components[CauseOfLoss].Add(ResolvedExposureType, new HashSet <long>()); } foreach (long RITEId in this.RITEIds) { if (CoverageIdExposureTypeMap.ContainsKey(RITEId) && CoverageIdExposureTypeMap[RITEId].Equals(ResolvedExposureType)) { //Components.Add(new Tuple<int, long, SymbolicValue>(ResolvedExposureType, RITEId, CauseOfLoss)); Components[CauseOfLoss][ResolvedExposureType].Add(RITEId); } } if (Components[CauseOfLoss][ResolvedExposureType].Count == 0) { Components[CauseOfLoss].Remove(ResolvedExposureType); } } if (Components[CauseOfLoss].Count == 0) { Components.Remove(CauseOfLoss); } } }