public CalcDeviceTaggingSets GetDeviceTaggingSets([NotNull] Simulator sim, int personCount)
        {
            CalcDeviceTaggingSets cs = new CalcDeviceTaggingSets
            {
                AllCalcDeviceTaggingSets = new List <DeviceTaggingSetInformation>()
            };

            foreach (var deviceTaggingSet in sim.DeviceTaggingSets.MyItems)
            {
                var calcset = new DeviceTaggingSetInformation(deviceTaggingSet.Name);
                foreach (var entry in deviceTaggingSet.Entries)
                {
                    if (entry.Device == null)
                    {
                        throw new LPGException("Device was null");
                    }

                    if (entry.Tag == null)
                    {
                        throw new LPGException("Tag was null");
                    }

                    var devname = entry.Device.Name;
                    //sim.MyGeneralConfig.CSVCharacter);
                    var tagname = CalcAffordanceFactory.FixAffordanceName(entry.Tag.Name,
                                                                          _calcParameters.CSVCharacter);
                    calcset.AddTag(devname, tagname);
                }

                foreach (var reference in
                         deviceTaggingSet.References.Where(x => x.PersonCount == personCount))
                {
                    if (reference.Tag == null)
                    {
                        throw new LPGException("Tag was null");
                    }

                    calcset.AddRefValue(reference.Tag.Name, reference.ReferenceValue, reference.LoadType.Name);
                }

                foreach (var loadType in deviceTaggingSet.LoadTypes)
                {
                    if (loadType.LoadType == null)
                    {
                        throw new LPGException("Loadtype was null");
                    }

                    if (_ltDict.SimulateLoadtype(loadType.LoadType))
                    {
                        var clt = _ltDict.GetLoadtypeDtoByLoadType(loadType.LoadType);
                        calcset.AddLoadType(clt.ConvertToLoadTypeInformation());
                    }
                }

                cs.AllCalcDeviceTaggingSets.Add(calcset);
            }

            return(cs);
        }
コード例 #2
0
        public List <CalcLocationDto> MakeCalcLocations([NotNull][ItemNotNull] List <Location> locations,
                                                        [NotNull] HouseholdKey householdKey, EnergyIntensityType et,
                                                        [NotNull] Dictionary <CalcLocationDto, List <IAssignableDevice> > deviceLocationDict,
                                                        [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions,
                                                        [NotNull] LocationDtoDict locdict,
                                                        [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            var locs = new List <CalcLocationDto>();

            foreach (var t in locations)
            {
                // loc anlegen
                var cloc = new CalcLocationDto(t.Name, t.IntID, Guid.NewGuid().ToStrGuid());
                foreach (var locdev in t.LocationDevices)
                {
                    RealDevice rd;
                    if (locdev.Device == null)
                    {
                        throw new LPGException("Device was null");
                    }
                    if (locdev.Device.AssignableDeviceType == AssignableDeviceType.DeviceCategory)
                    {
                        rd = _picker.PickDeviceFromCategory((DeviceCategory)locdev.Device, et,
                                                            deviceActions);
                    }
                    else
                    {
                        rd = (RealDevice)locdev.Device;
                    }

                    var deviceName = CalcAffordanceFactory.FixAffordanceName(rd.Name, _calcParameters.CSVCharacter);
                    if (rd.DeviceCategory == null)
                    {
                        throw new LPGException("Device Category was null");
                    }

                    var devcatdto    = deviceCategoryDtos.Single(x => x.FullCategoryName == rd.DeviceCategory.FullPath);
                    var clightdevice = new CalcDeviceDto(deviceName, devcatdto.Guid,
                                                         householdKey, OefcDeviceType.Light, rd.DeviceCategory.FullPath,
                                                         string.Empty, Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name);
                    clightdevice.AddLoads(CalcDeviceDtoFactory.MakeCalcDeviceLoads(rd, _calcLoadTypeDict));
                    cloc.AddLightDevice(clightdevice);
                }
                deviceLocationDict.Add(cloc, new List <IAssignableDevice>());
                locs.Add(cloc);
                locdict.LocationDict.Add(t, cloc);
            }
            return(locs);
        }
        public CalcHouseholdDto MakeCalcModularHouseholdDto([NotNull] Simulator sim, [NotNull] ModularHousehold mhh,
                                                            [NotNull] TemperatureProfile temperatureProfile, [NotNull] HouseholdKey householdKey, [NotNull] GeographicLocation geographicLocation,
                                                            [NotNull] out LocationDtoDict locationDict,
                                                            [CanBeNull] TransportationDeviceSet transportationDeviceSet,
                                                            [CanBeNull] TravelRouteSet travelRouteSet, EnergyIntensityType energyIntensity,
                                                            [CanBeNull] ChargingStationSet chargingStationSet)
        {
            //  _lf.RegisterKey(householdKey, mhh.PrettyName);
            var name = CalcAffordanceFactory.FixAffordanceName(mhh.Name, sim.MyGeneralConfig.CSVCharacter);

            if (geographicLocation == null)
            {
                throw new DataIntegrityException("no geographic Location was set");
            }
            var et = energyIntensity;

            if (et == EnergyIntensityType.AsOriginal)
            {
                et = mhh.EnergyIntensityType;
            }
            name = name + " " + householdKey.Key;
            var locations = mhh.CollectLocations();
            //var deviceLocationDict = new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var deviceLocationDtoDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();

            locationDict = new LocationDtoDict();
            List <DeviceCategoryDto> deviceCategoryDtos = new List <DeviceCategoryDto>();

            foreach (var deviceCategory in sim.DeviceCategories.It)
            {
                deviceCategoryDtos.Add(new DeviceCategoryDto(deviceCategory.FullPath, Guid.NewGuid().ToStrGuid()));
            }
            var locationDtos = _calcLocationDtoFactory.MakeCalcLocations(locations,
                                                                         householdKey,
                                                                         et, deviceLocationDtoDict, sim.DeviceActions.It, locationDict, deviceCategoryDtos);

            // persons

            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            var personDtos = _calcPersonDtoFactory.MakePersonDtos(mhh.Persons.ToList(), householdKey,
                                                                  mhh.Vacation.VacationTimeframes(), mhh.CollectTraitDesires(), mhh.Name);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(personDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //mhh.Persons.ToList(),mhh.Vacation.VacationTimeframes(),  sim.MyGeneralConfig.RepetitionCount,householdKey, locs[0],name);
            //CalcPersonFactory.AddTraitDesires(mhh.CollectTraitDesires(), calcpersons,sim.MyGeneralConfig.TimeStepsPerHour, chh.Name, new Dictionary<Desire, SharedDesireValue>());
            //check if unhungry and unhungry join only have been added both
            //can't check it in the integrity checker, because that would mean having to duplicate the entire
            // desire collection logic

            /*  foreach (CalcPerson person in calcpersons) {
             *    var desires =
             *        person.PersonDesires.Desires.Values.Where(x => x.Name.ToLower().Contains("unhungry") || x.Name.ToLower().Contains("un-hungry")).ToList();
             *    if (desires.Count > 1) {
             *        throw new DataIntegrityException("More than one unhungry desire for the person " + person.Name, mhh);
             *    }
             * }*/

            // devices

            var deviceLocations = new List <DeviceLocationTuple>();

            foreach (var modularHouseholdTrait in mhh.Traits)
            {
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (modularHouseholdTrait.HouseholdTrait != null)
                {
                    CollectDevicesFromTrait(modularHouseholdTrait.HouseholdTrait, deviceLocations);
                }
            }

            var deviceDtos = _calcDeviceDtoFactory.MakeCalcDevices(locationDtos,
                                                                   deviceLocations, et, householdKey, deviceLocationDtoDict, sim.DeviceActions.It, _ltDict, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(deviceDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //autodevs
            var autonomousDevices = mhh.CollectAutonomousDevices();

            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            var autoDevDtos = _calcDeviceDtoFactory.MakeCalcAutoDevDtos(autonomousDevices,
                                                                        energyIntensity, householdKey, mhh.Vacation.VacationTimeframes(),
                                                                        mhh.Name + "###" + householdKey,
                                                                        sim.DeviceActions.It, locationDict,
                                                                        temperatureProfile, geographicLocation, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(autoDevDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //affordances
            var affordancesAtLoc =
                new Dictionary <CalcLocationDto, List <AffordanceWithTimeLimit> >();

            foreach (var location in locations)
            {
                affordancesAtLoc.Add(locationDict.GetDtoForLocation(location), mhh.GetAllAffordancesForLocation(location));
            }
            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            List <CalcAffordanceDto> allAffordances = _calcAffordanceDtoFactory.SetCalcAffordances(locationDtos, temperatureProfile,
                                                                                                   _ltDict,
                                                                                                   geographicLocation, _random, sim.MyGeneralConfig.TimeStepsPerHour,
                                                                                                   sim.MyGeneralConfig.InternalStepSize, mhh.Vacation.VacationTimeframes(),
                                                                                                   mhh.Name + "###" + householdKey, sim.DeviceActions.MyItems, affordancesAtLoc, locationDict,
                                                                                                   out List <DateTime> bridgeDays, householdKey, deviceDtos, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(allAffordances.ConvertAll(x => (IHouseholdKey)x));
                _calcRepo.InputDataLogger.SaveList(_calcVariableRepositoryDtoFactory.GetAllVariableDtos()
                                                   .ConvertAll(x => (IHouseholdKey)x));
            }

            //                SaveVariableDefinitionsDtos(_calcVariableRepositoryDtoFactory.GetAllVariableDtos());
            //CalcVariableRepository variableRepository = _calcVariableRepositoryDtoFactory.GetRepository(householdKey);
            List <CalcSiteDto> sites = null;
            List <CalcTransportationDeviceDto> transportationDevices = null;
            List <CalcTravelRouteDto>          routes = null;

            if (_calcRepo.CalcParameters.TransportationEnabled)
            {
                _transportationDtoFactory.MakeTransportationDtos(sim, mhh, transportationDeviceSet,
                                                                 travelRouteSet, chargingStationSet,
                                                                 out sites, out transportationDevices,
                                                                 out routes, locationDtos, householdKey);
                if (_calcRepo.CalcParameters.IsSet(CalcOption.TransportationStatistics))
                {
                    _calcRepo.InputDataLogger.SaveList(sites.ConvertAll(x => (IHouseholdKey)x));
                    _calcRepo.InputDataLogger.SaveList(transportationDevices.ConvertAll(x => (IHouseholdKey)x));
                    _calcRepo.InputDataLogger.SaveList(routes.ConvertAll(x => (IHouseholdKey)x));
                }
            }
            var chh = new CalcHouseholdDto(name, mhh.IntID, temperatureProfile.Name, householdKey, Guid.NewGuid().ToStrGuid(),
                                           geographicLocation.Name,
                                           bridgeDays, autoDevDtos, locationDtos, personDtos, deviceDtos,
                                           allAffordances, mhh.Vacation.VacationTimeframes(),
                                           sites, routes, transportationDevices,
                                           mhh.Description);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.Save(householdKey, chh);
            }

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                BridgeDayEntries bdes = new BridgeDayEntries(householdKey, chh.BridgeDays);
                _calcRepo.InputDataLogger.Save(householdKey, bdes);
            }

            return(chh);
        }
コード例 #4
0
        private List <CalcAffordanceDto> GetCalcAffordancesAtLocation([NotNull] CalcLocationDto calcloc,
                                                                      [NotNull] List <AffordanceWithTimeLimit> affordancesAtLocation,
                                                                      TimeSpan internalStepSize, int timeStepsPerHour,
                                                                      [NotNull] TemperatureProfile temperatureProfile,
                                                                      [NotNull] CalcLoadTypeDtoDictionary ltdict,
                                                                      [NotNull] GeographicLocation geographicLocation, [NotNull] Random rnd,
                                                                      [NotNull][ItemNotNull] List <VacationTimeframe> vacationTimeframes,
                                                                      [NotNull] string holidayKey,
                                                                      [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions,
                                                                      [NotNull]
                                                                      LocationDtoDict locDict,
                                                                      [NotNull] out List <DateTime> bridgeDays, [NotNull] HouseholdKey householdKey,
                                                                      [NotNull][ItemNotNull] List <CalcDeviceDto> deviceDtosAtLocation,
                                                                      [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            List <CalcAffordanceDto> createdAffordances = new List <CalcAffordanceDto>();

            bridgeDays = new List <DateTime>();
            foreach (AffordanceWithTimeLimit aff in affordancesAtLocation)
            {
                var affordanceName = CalcAffordanceFactory.FixAffordanceName(aff.Affordance.Name, _cp.CSVCharacter);
                if (aff.Affordance.PersonProfile == null)
                {
                    throw new DataIntegrityException("Person profile on " + aff.Affordance.PrettyName + " was null. Please fix.");
                }

                var cp1 = CalcDeviceDtoFactory.GetCalcProfileDto(aff.Affordance.PersonProfile);
                List <CalcDesireDto> calcDesires = MakeCalcDesires(timeStepsPerHour, aff, affordanceName);
                List <CalcAffordanceVariableOpDto> variableOps          = MakeVariableOps(calcloc, locDict, householdKey, aff);
                List <VariableRequirementDto>      variableRequirements =
                    MakeVariableRequirements(calcloc, locDict, householdKey, aff);

                MakeAffordanceTimelimit(temperatureProfile, geographicLocation, rnd, vacationTimeframes,
                                        holidayKey, bridgeDays, aff, out var availabilityDataReference);

                //make the affordance
                Logger.Debug("Converting the time limit to a bitarray for the affordance " + aff.Affordance.Name);
                //caff.IsBusyArray = tmparr;
                string timeLimitName = "";

                if (aff.TimeLimit != null)
                {
                    timeLimitName = aff.TimeLimit.Name;
                }

                var caff = new CalcAffordanceDto(affordanceName, aff.Affordance.IntID, cp1, calcloc.Name, calcloc.Guid,
                                                 aff.Affordance.RandomDesireResults, calcDesires, aff.Affordance.MinimumAge,
                                                 aff.Affordance.MaximumAge,
                                                 aff.Affordance.PermittedGender,
                                                 aff.Affordance.NeedsLight, (double)aff.Affordance.TimeStandardDeviation,
                                                 aff.Affordance.CarpetPlotColor.R, aff.Affordance.CarpetPlotColor.G, aff.Affordance.CarpetPlotColor.B,
                                                 aff.Affordance.AffCategory,
                                                 aff.Affordance.IsInterruptable, aff.Affordance.IsInterrupting, variableOps, variableRequirements,
                                                 aff.Affordance.ActionAfterInterruption, timeLimitName, aff.Weight,
                                                 aff.Affordance.RequireAllDesires, aff.SrcTraitName,
                                                 Guid.NewGuid().ToStrGuid(), availabilityDataReference, householdKey, aff.Affordance.BodilyActivityLevel);
                foreach (var devtup in aff.Affordance.AffordanceDevices)
                {
                    MakeAffordanceDevices(calcloc, internalStepSize, ltdict, allDeviceActions, aff, caff, devtup, deviceDtosAtLocation,
                                          deviceCategoryDtos);
                }

                MakeSubAffordances(caff, aff.Affordance, timeStepsPerHour, internalStepSize, calcloc,
                                   locDict, _cp.CSVCharacter, aff.Weight, aff.SrcTraitName, householdKey);
                createdAffordances.Add(caff);
            }
            return(createdAffordances);
        }
コード例 #5
0
        private void MakeSubAffordances([NotNull] CalcAffordanceDto caff, [NotNull] Affordance aff, int timeStepsPerHour,
                                        TimeSpan internalStepSize, [NotNull] CalcLocationDto calcloc,
                                        [NotNull] LocationDtoDict locDict,
                                        [NotNull] string csvCharacter, int weight, [NotNull] string srcTrait,
                                        [NotNull] HouseholdKey householdKey)
        {
            // Subaffordanzen durchgehen
            foreach (var affsubaff in aff.SubAffordances)
            {
                var calcDesires = new List <CalcDesireDto>();
                if (affsubaff.SubAffordance == null)
                {
                    throw new LPGException("SubAffordance was null");
                }

                var name = CalcAffordanceFactory.FixAffordanceName(affsubaff.SubAffordance.Name, csvCharacter);
                // f�r alle desires calcdesires anlegen
                foreach (var subaffDesire in affsubaff.SubAffordance.SubAffordanceDesires)
                {
                    if (subaffDesire.Desire == null)
                    {
                        throw new LPGException("Desire was null");
                    }

                    var cd = new CalcDesireDto(name + " - " + subaffDesire.Name, subaffDesire.Desire.IntID, 0, 0,
                                               subaffDesire.SatisfactionValue, 0, timeStepsPerHour, subaffDesire.Desire.CriticalThreshold,
                                               null, srcTrait, "");
                    calcDesires.Add(cd);
                }

                var minutesperstep   = (decimal)internalStepSize.TotalMinutes;
                var delayTimeInSteps = (int)(affsubaff.DelayTime / minutesperstep);
                // variables
                var calcAffordanceVariableOps = new List <CalcAffordanceVariableOpDto>();
                foreach (var affVariableOp in affsubaff.SubAffordance.SubAffordanceVariableOps)
                {
                    CalcLocationDto loc = null;
                    if (affVariableOp.LocationMode == VariableLocationMode.OtherLocation)
                    {
                        if (affVariableOp.Location != null && locDict.SimulateLocation(affVariableOp.Location))
                        {
                            loc = locDict.GetDtoForLocation(affVariableOp.Location);
                        }
                    }
                    else
                    {
                        loc = calcloc;
                    }

                    if (loc != null && affVariableOp.Variable != null)
                    {
                        if (affVariableOp.Location == null)
                        {
                            throw new LPGException("Variable Location was null");
                        }
                        var variable =
                            _variableRepository.RegisterVariableIfNotRegistered(affVariableOp.Variable,
                                                                                affVariableOp.Location, householdKey, locDict);
                        calcAffordanceVariableOps.Add(new CalcAffordanceVariableOpDto(affVariableOp.Variable.Name,
                                                                                      affVariableOp.Value, loc.Name, loc.Guid, affVariableOp.VariableAction, affVariableOp.ExecutionTime,
                                                                                      variable.Guid));
                    }
                }

                // CalcSubaffordanz anlegen
                var affName = CalcAffordanceFactory.FixAffordanceName(aff.Name, csvCharacter);
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                var csubaff = new CalcSubAffordanceDto(name + " (" + affName + ")", affsubaff.IntID, calcloc.Name, calcloc.Guid,
                                                       calcDesires, affsubaff.SubAffordance.MinimumAge, affsubaff.SubAffordance.MaximumAge,
                                                       delayTimeInSteps, affsubaff.SubAffordance.PermittedGender, aff.AffCategory,
                                                       affsubaff.SubAffordance.IsInterruptable, affsubaff.SubAffordance.IsInterrupting,
                                                       calcAffordanceVariableOps, weight, srcTrait, Guid.NewGuid().ToStrGuid());
                caff.SubAffordance.Add(csubaff);
            }
        }
コード例 #6
0
        public List <CalcAffordanceTaggingSetDto> GetAffordanceTaggingSets([NotNull] Simulator sim)
        {
            var calcSets = new List <CalcAffordanceTaggingSetDto>();

            foreach (var affordanceTaggingSet in sim.AffordanceTaggingSets.MyItems)
            {
                var calcset = new CalcAffordanceTaggingSetDto(affordanceTaggingSet.Name,
                                                              affordanceTaggingSet.MakeCharts);
                foreach (var entry in affordanceTaggingSet.Entries)
                {
                    if (entry.Affordance == null)
                    {
                        throw new LPGException("Affordance was null");
                    }
                    var affName = CalcAffordanceFactory.FixAffordanceName(entry.Affordance.Name,
                                                                          sim.MyGeneralConfig.CSVCharacter);
                    if (entry.Tag == null)
                    {
                        throw new LPGException("Tag was null");
                    }
                    var tagname = CalcAffordanceFactory.FixAffordanceName(entry.Tag.Name,
                                                                          sim.MyGeneralConfig.CSVCharacter);
                    calcset.AddTag(affName, tagname);

                    foreach (var affordanceSubAffordance in entry.Affordance.SubAffordances)
                    {
                        if (affordanceSubAffordance.SubAffordance == null)
                        {
                            throw new LPGException("Subaffordance was null");
                        }

                        var subname = CalcAffordanceFactory.FixAffordanceName(
                            affordanceSubAffordance.SubAffordance.Name,
                            sim.MyGeneralConfig.CSVCharacter) + " (" + affName + ")";
                        if (!calcset.AffordanceToTagDict.ContainsKey(subname))
                        {
                            calcset.AddTag(subname, tagname);
                        }
                    }
                }

                foreach (var reference in affordanceTaggingSet.TagReferences)
                {
                    calcset.AddReference(reference.Tag.Name, reference.Gender, reference.MinAge, reference.MaxAge,
                                         reference.Percentage);
                }

                foreach (var tag in affordanceTaggingSet.Tags)
                {
                    calcset.Colors.Add(tag.Name, tag.CarpetPlotColor);
                }

                calcset.AddTag("taking a vacation", "vacation");
                foreach (var affordanceTaggingSetLoadType in affordanceTaggingSet.LoadTypes)
                {
                    if (affordanceTaggingSetLoadType.LoadType == null)
                    {
                        throw new LPGException("Load type was null");
                    }
                    if (_ltDict.SimulateLoadtype(affordanceTaggingSetLoadType.LoadType))
                    {
                        calcset.AddLoadType(_ltDict.Ltdtodict[affordanceTaggingSetLoadType.LoadType]);
                    }
                }

                calcSets.Add(calcset);
            }

            return(calcSets);
        }