Ejemplo n.º 1
0
        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()))
                        )
                    );
            }
        }
Ejemplo n.º 2
0
        public Contract(Dictionary <string, object> IR,
                        Dictionary <string, HashSet <long> > resolvedSchedule,
                        Dictionary <long, RiskItemCharacteristicIDAttributes> CoverageIdAttrMap)
        {
            this.ResolvedSchedule  = resolvedSchedule;
            this.CoverageIdAttrMap = CoverageIdAttrMap;

            // Construct universal subject position
            HashSet <long> AllRITEIds = new HashSet <long>();

            if (resolvedSchedule != null)
            {
                AllRITEIds = resolvedSchedule.Aggregate(new HashSet <long>(), (a, b) => { a.UnionWith(b.Value); return(a); });
            }

            HashSet <long> AllRiskItemIds = new HashSet <long>();

            if (CoverageIdAttrMap != null)
            {
                AllRiskItemIds = new HashSet <long>(AllRITEIds.Where(x => CoverageIdAttrMap.ContainsKey(x)).Select(x => CoverageIdAttrMap[x].RITExposureId).Distinct());
            }

            UniversalSubject = new UniversalSubjectPosition(AllRITEIds, AllRiskItemIds);

            // Declarations
            Declarations = (Dictionary <string, object>)IR["Declarations"];

            // Claims Adjustment Settings
            if (!Declarations.ContainsKey("Claims Adjustment Options") ||
                Declarations["Claims Adjustment Options"] == null)
            {
                _AreSublimitsNetOfDeductible = false;
                _AreDeductiblesAbsorbable    = false;
            }
            else
            {
                if (!((Declarations["Claims Adjustment Options"] as Dictionary <string, object>).ContainsKey("Claims Adjustment Sublimits")) ||
                    (Declarations["Claims Adjustment Options"] as Dictionary <string, object>)["Claims Adjustment Sublimits"] == null)
                {
                    _AreSublimitsNetOfDeductible = false;
                }
                else
                {
                    _AreSublimitsNetOfDeductible = (Declarations["Claims Adjustment Options"] as Dictionary <string, object>)["Claims Adjustment Sublimits"].ToString().Equals("Net Of Deductible");
                }

                if (!((Declarations["Claims Adjustment Options"] as Dictionary <string, object>).ContainsKey("Claims Adjustment Deductibles")) ||
                    (Declarations["Claims Adjustment Options"] as Dictionary <string, object>)["Claims Adjustment Deductibles"] == null)
                {
                    _AreDeductiblesAbsorbable = false;
                }
                else
                {
                    _AreDeductiblesAbsorbable = (Declarations["Claims Adjustment Options"] as Dictionary <string, object>)["Claims Adjustment Deductibles"].ToString().Equals("Absorbable");
                }
            }


            object NameObject;

            if (Declarations.TryGetValue("Name", out NameObject))
            {
                this.Name = NameObject.ToString();
            }

            object CausesOfLossObject;

            Declarations.TryGetValue("CausesOfLoss", out CausesOfLossObject);

            object ScheduleObject;

            Declarations.TryGetValue("Schedule", out ScheduleObject);

            object ExposureTypesObject;

            Declarations.TryGetValue("ExposureTypes", out ExposureTypesObject);

            object GrossPositionObject;

            Declarations.TryGetValue("GrossPosition", out GrossPositionObject);

            object CededPositionObject;

            Declarations.TryGetValue("CededPosition", out CededPositionObject);

            if (GrossPositionObject != null)
            {
                if (CededPositionObject != null)
                {
                    this.ContractSubject = new NetPosition(ToHashSet(GrossPositionObject.ToString()), ToHashSet(CededPositionObject.ToString()));
                }
                else if (CausesOfLossObject != null)
                {
                    this.ContractSubject = new SubjectPosition(ToHashSet(GrossPositionObject.ToString()), ToHashSet(CausesOfLossObject.ToString()));
                }
                else
                {
                    this.ContractSubject = new SubjectPosition(ToHashSet(GrossPositionObject.ToString()));
                }
            }
            else if (CausesOfLossObject != null && ScheduleObject != null && ExposureTypesObject != null)
            {
                this.ContractSubject = new Subject(
                    UniversalSubject, new Schedule(ToHashSet(ScheduleObject.ToString())), ToHashSet(CausesOfLossObject.ToString()), ToHashSet(ExposureTypesObject.ToString()),
                    ResolvedSchedule, CoverageIdAttrMap);
            }

            // Covers

            object[] covers = (object[])IR["Covers"];

            Covers = new List <ICover <Value, Value, Value> >(covers.Length);

            foreach (object cover in covers)
            {
                Dictionary <string, object> coverData = (Dictionary <string, object>)cover;

                Covers.Add(ConstructCover(coverData));
            }

            // Sublimits

            object[] sublimits = (object[])IR["Sublimits"];

            Sublimits = new List <ITerm <Value> >(sublimits.Length);

            foreach (object sublimit in sublimits)
            {
                Sublimits.Add(ConstructSublimit((Dictionary <string, object>)sublimit, AreSublimitsNetOfDeductible()));
            }

            // Deductibles

            object[] deductibles = (object[])IR["Deductibles"];

            Deductibles = new List <ITerm <Value> >(deductibles.Length);

            foreach (object deductible in deductibles)
            {
                Deductibles.Add(ConstructDeductible((Dictionary <string, object>)deductible, AreDeductiblesAbsorbable()));
            }
        }
Ejemplo n.º 3
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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);
                }
            }
        }