private static ICalcAbleObject MakeCalcHouseholdObject([NotNull] Simulator sim, [NotNull] CalcStartParameterSet csps, [NotNull] ICalcObject hh, [NotNull] ILifetimeScope scope, [NotNull] CalcVariableDtoFactory cvrdto, [NotNull] CalcVariableRepository variableRepository, out CalcObjectType cot, [NotNull] CalcRepo calcRepo) { var cmhdf = scope.Resolve <CalcModularHouseholdDtoFactory>(); HouseholdKey householdKey = new HouseholdKey("HH1"); CalcHouseholdDto dto = cmhdf.MakeCalcModularHouseholdDto(sim, (ModularHousehold)hh, csps.TemperatureProfile, householdKey, csps.GeographicLocation, out _, csps.TransportationDeviceSet, csps.TravelRouteSet, csps.EnergyIntensity, csps.ChargingStationSet); var cmhf = scope.Resolve <CalcModularHouseholdFactory>(); /*foreach (var v in dto.CalcVariables) * { * variableRepository.RegisterVariable(new CalcVariable(v.Name, v.Guid, v.Value, v.LocationName, v.LocationGuid, v.HouseholdKey)); * }*/ foreach (HouseholdKeyEntry entry in dto.GetHouseholdKeyEntries()) { calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, entry); } calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, dto); RegisterAllDtoVariables(cvrdto, variableRepository); ICalcAbleObject ch = cmhf.MakeCalcModularHousehold(dto, out _, null, null, calcRepo); cot = CalcObjectType.ModularHousehold; return(ch); }
public void MakeTransportation([NotNull] CalcHouseholdDto household, [NotNull] DtoCalcLocationDict locDict, [NotNull] CalcHousehold chh) { if (household.CalcTravelRoutes == null || household.CalcSites == null || household.CalcTransportationDevices == null) { Logger.Info("Missing something for the transportation"); if (household.CalcTravelRoutes == null) { Logger.Info("No travel routes are set"); } if (household.CalcSites == null) { Logger.Info("No sites are set"); } if (household.CalcTransportationDevices == null) { Logger.Info("No Transportation devices are set"); } return; } TransportationHandler th = new TransportationHandler(); chh.TransportationHandler = th; Logger.Info("Making Calc Sites"); var sites = MakeCalcSites(household, locDict, _loadTypeDict, th); foreach (var site in sites) { th.AddSite(site); } Logger.Info("Making travel routes"); MakeTravelRoutes(household.CalcTravelRoutes, chh, sites, th); Logger.Info("Making Transportation devices"); MakeTransportationDevice(chh, household.CalcTransportationDevices); Logger.Info("Setting affordances"); SetAffordances(chh); Logger.Info("Finished initalizing the transportation"); }
private List <CalcSite> MakeCalcSites([NotNull] CalcHouseholdDto household, [NotNull] DtoCalcLocationDict locDict, [NotNull] CalcLoadTypeDictionary ltDict, [NotNull] TransportationHandler th ) { List <CalcSite> sites = new List <CalcSite>(); //Dictionary<string, CalcSite> siteDictByGuid = new Dictionary<string, CalcSite>(); if (household.CalcSites == null) { throw new LPGException("CalcSites was null"); //for the bug in the null checking } foreach (var siteDto in household.CalcSites) { var calcSite = new CalcSite(siteDto.Name, siteDto.Guid, household.HouseholdKey); sites.Add(calcSite); //siteDictByGuid.Add(siteDto.Guid, calcSite); foreach (var locGuid in siteDto.LocationGuid) { CalcLocation calcLoc = locDict.GetCalcLocationByGuid(locGuid); calcLoc.CalcSite = calcSite; calcSite.Locations.Add(calcLoc); } foreach (var chargingStation in siteDto.ChargingStations) { var gridLt = ltDict.GetLoadtypeByGuid(chargingStation.GridChargingLoadType.Guid); var carLt = ltDict.GetLoadtypeByGuid(chargingStation.CarChargingLoadType.Guid); var cat = th.GetCategory(chargingStation.DeviceCategory); calcSite.AddChargingStation(gridLt, cat, chargingStation.MaxChargingPower, carLt, _calcRepo); } } return(sites); }
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); }
public CalcHousehold MakeCalcModularHousehold([NotNull] CalcHouseholdDto householdDto, [NotNull] out DtoCalcLocationDict dtoCalcLocationDict, [CanBeNull] string houseName, [CanBeNull] string houseDescription, [NotNull] CalcRepo calcRepo) { CalcHousehold chh = null; _calcRepo.FileFactoryAndTracker.RegisterHousehold(householdDto.HouseholdKey, householdDto.Name, HouseholdKeyType.Household, householdDto.Description, houseName, houseDescription); string name = householdDto.Name + " " + householdDto.HouseholdKey; try { dtoCalcLocationDict = new DtoCalcLocationDict(); var calcLocations = _clf.MakeCalcLocations(householdDto.LocationDtos, dtoCalcLocationDict, calcRepo); if (calcLocations.Count == 0) { throw new LPGException("Not a single location could be created. Something in this household is wrong. Please fix."); } // devices var calcDevices = new List <CalcDevice>(); _cdf.MakeCalcDevices(calcLocations, householdDto.DeviceDtos, calcDevices, householdDto.HouseholdKey, _ltDict, calcRepo); var autodevs = _cdf.MakeCalcAutoDevs(householdDto.AutoDevices, dtoCalcLocationDict); //affordances /*if (householdDto.Vacation == null) * { * throw new LPGException("Vacation was null"); * }*/ //_cdf.MakeCalcDevices(calcLocations, householdDto.DeviceDtos, calcDevices,householdDto.HouseholdKey, _ltDict); var calcpersons = _cpf.MakeCalcPersons(householdDto.Persons, calcLocations[0], householdDto.Name); chh = new CalcHousehold(name, householdDto.GeographicLocationName, householdDto.TemperatureprofileName, householdDto.HouseholdKey, householdDto.Guid, _calcVariableRepository, calcLocations, calcpersons, householdDto.Description, _calcRepo); HashSet <StrGuid> deviceGuids = new HashSet <StrGuid>(); foreach (CalcDevice device in calcDevices) { if (!deviceGuids.Add(device.Guid)) { throw new LPGException("Tried to add the same device guid twice"); } } chh.SetDevices(calcDevices); chh.SetAutoDevs(autodevs); //chh.BridgeDays = householdDto.BridgeDays; _caf.SetAllAffordaces(householdDto.Affordances, dtoCalcLocationDict, _calcVariableRepository, calcDevices); CheckCalcAffordancesForExecutability(chh); if (householdDto.CalcTravelRoutes != null) { Logger.Info("Starting to initialize transportation for household " + householdDto.Name + "..."); _ctf.MakeTransportation(householdDto, dtoCalcLocationDict, chh); } else { Logger.Info("No travel route was set for for household " + householdDto.Name + ", skipping transportation"); } return(chh); } catch { chh?.Dispose(); throw; } }
public CalcHouseDto MakeHouseDto([NotNull] Simulator sim, [NotNull] House house, [NotNull] TemperatureProfile temperatureProfile, [NotNull] GeographicLocation geographicLocation, //List<CalcDeviceTaggingSet> taggingSets, EnergyIntensityType energyIntensity) { if (house.HouseType == null) { throw new LPGException("Housetype was null"); } if (energyIntensity == EnergyIntensityType.AsOriginal) { energyIntensity = house.EnergyIntensityType; } if (energyIntensity == EnergyIntensityType.AsOriginal) { var calcObject = house.Households[0].CalcObject; if (calcObject == null) { throw new LPGException("House was null"); } energyIntensity = calcObject.EnergyIntensityType; } var houseLocations = new List <CalcLocationDto>(); HouseholdKey houseKey = Constants.HouseKey; List <DeviceCategoryDto> deviceCategoryDtos = new List <DeviceCategoryDto>(); foreach (var deviceCategory in sim.DeviceCategories.It) { deviceCategoryDtos.Add(new DeviceCategoryDto(deviceCategory.FullPath, Guid.NewGuid().ToStrGuid())); } HouseIntegrityChecker.Run(house, sim); var householdIndex = 1; var calcAbleObjects = new List <CalcHouseholdDto>(); var globalLocationDict = new Dictionary <Location, CalcLocationDto>(); foreach (var household in house.Households) { if (household.CalcObject == null) { throw new LPGException("Calcobject was null"); } if (household.CalcObject.CalcObjectType == CalcObjectType.ModularHousehold) { CalcHouseholdDto hhdto = _hhDtoFactory.MakeCalcModularHouseholdDto(sim, (ModularHousehold)household.CalcObject, temperatureProfile, new HouseholdKey("HH" + householdIndex), geographicLocation, out var locationDtoDict, household.TransportationDeviceSet, household.TravelRouteSet, energyIntensity, household.ChargingStationSet); calcAbleObjects.Add(hhdto); foreach (var pair in locationDtoDict.LocationDict) { if (!globalLocationDict.ContainsKey(pair.Key)) { globalLocationDict.Add(pair.Key, pair.Value); } } } else { throw new LPGException("Unknown Calc Object Type in the house! This is a bug."); } householdIndex++; } var spaceHeating = CreateSpaceHeatingObject(house, temperatureProfile, houseKey, out var heatingLocation, _calcParameters.InternalStartTime, _calcParameters.InternalEndTime , _ltDict); //, taggingSets); if (heatingLocation != null) { houseLocations.Add(heatingLocation); } var airconditioning = MakeAirConditioning(temperatureProfile, house.HouseType, houseKey, out var airconditioningLocation); if (airconditioningLocation != null) { houseLocations.Add(airconditioningLocation); } List <CalcAutoDevDto> autoDevs = new List <CalcAutoDevDto>(); var autodevs2 = MakeCalcAutoDevsFromHouse(temperatureProfile, geographicLocation, house.HouseType.HouseDevices, energyIntensity, houseKey, house.Name, sim.DeviceActions.It, house, out var devLocations, deviceCategoryDtos); houseLocations.AddRange(devLocations); autoDevs.AddRange(autodevs2); // energy Storage var calcEnergyStorages = MakeEnergyStorages(house, houseKey); //, taggingSets); // transformation devices var transformationDevices = MakeAllTransformationDevices(house.HouseType, houseKey); //taggingSets, // generators var generators = MakeGenerators(house.HouseType.HouseGenerators.Select(x => x.Generator).ToList(), houseKey); //taggingSets, var calchouse = new CalcHouseDto(house.Name, autoDevs, airconditioning, spaceHeating, calcEnergyStorages, generators, transformationDevices, calcAbleObjects, houseKey, houseLocations, house.Description); //check the calc variables return(calchouse); }