public Subject(UniversalSubjectPosition universalSubject, Dictionary <SymbolicValue, Dictionary <int, Tuple <HashSet <long>, HashSet <long> > > > Components2Difference, Dictionary <string, HashSet <long> > resolvedSchedule = null, bool _Resolution = false, bool _isNotConstrained = false) { SetID(); this.UniversalSubject = universalSubject; this.Schedule = new Schedule(new HashSet <SymbolicValue>() { "Residual" }); this.PerRisk = _Resolution; this.isNotConstrained = _isNotConstrained; if (resolvedSchedule != null) { this.ResolvedSchedule = resolvedSchedule; } this.ExposureTypes = new HashSet <SymbolicValue>(); this.CausesOfLoss = new HashSet <SymbolicValue>(); this.RITEIds = new HashSet <long>(); this.Components = Components2Difference; foreach (SymbolicValue COL in Components.Keys) { CausesOfLoss.Add(COL); foreach (int ResolvedExposureType in Components[COL].Keys) { ExposureTypes.Add(new SymbolicValue(((ExposureType.EExposureType)ResolvedExposureType).ToString())); HashSet <long> Components_COL_ResolvedExposureType = Components[COL][ResolvedExposureType].Item1; foreach (long RITEId in Components_COL_ResolvedExposureType) { this.RITEIds.Add(RITEId); } } } 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())) ) ); } }
public UniversalSubjectPosition(HashSet <long> allRITEIds, HashSet <long> allRiskItemIds) { AllRITEIds = allRITEIds; AllRiskItemIds = allRiskItemIds; CausesOfLoss = new HashSet <SymbolicValue>() { "EQ", "WS", "CS", "FL", "WT", "FR", "TR", "SH", "FF", "SL", "WI", "WA", "SU", "HA", "TO", "SW", "FZ", "IC", "SN", "WF", "TS" }; ResolvedExposureTypes = new HashSet <int>(ExposureType.GetIndividualIntExposureTypes(ExposureType.EExposureType.Loss)); }
public UniversalSubjectPosition2(SortedSet <long> allRITEIds) { CausesOfLoss = new HashSet <SymbolicValue>() { "EQ", "WS", "CS", "FL", "WT", "FR", "TR", "SH", "FF", "SL", "WI", "SU", "HA", "TO", "SW", "FZ", "IC", "SN", "WF", "TS" }; ResolvedExposureTypes = new HashSet <int>(ExposureType.GetIndividualIntExposureTypes(ExposureType.EExposureType.Loss)); AllRITEIds = new EwahCompressedBitArray(); OffsetForAllRITEIds = allRITEIds.First(); foreach (long RITEId in allRITEIds) { AllRITEIds.Set((int)(RITEId - OffsetForAllRITEIds)); } }
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); } } }