private void MakeSubAffordances([NotNull] DtoCalcLocationDict locations, [NotNull] CalcVariableRepository variableRepository, [NotNull] CalcAffordanceDto affordancedto, [NotNull] CalcAffordance caff) { foreach (CalcSubAffordanceDto sdto in affordancedto.SubAffordance) { CalcLocation subaffLocation = locations.GetCalcLocationByGuid(sdto.LocGuid); List <CalcDesire> satisfactionValues = MakeCalcDesires(sdto.Satisfactionvalues); var varOps = MakeVariableOps(locations, sdto.VariableOps, variableRepository); //subaffordances have no time limits BitArray isBusySub = new BitArray(_calcRepo.CalcParameters.InternalTimesteps, false); CalcSubAffordance csuf = new CalcSubAffordance(sdto.Name, subaffLocation, satisfactionValues, sdto.MiniumAge, sdto.MaximumAge, sdto.Delaytimesteps, sdto.PermittedGender, sdto.AffCategory, sdto.IsInterruptable, sdto.IsInterrupting, caff, varOps, sdto.Weight, sdto.SourceTrait, sdto.Guid, isBusySub, variableRepository, caff.BodilyActivityLevel, _calcRepo); caff.SubAffordances.Add(csuf); } }
private static CalcRepo PrepareCalculation([NotNull] Simulator sim, [NotNull] CalcStartParameterSet csps, [NotNull] ILifetimeScope scope, [NotNull] out CalcLoadTypeDtoDictionary dtoltdict, [NotNull] out DayLightStatus dls, [NotNull] out CalcVariableRepository variableRepository ) { CalcRepo calcRepo = scope.Resolve <CalcRepo>(); var inputDataLogger = scope.Resolve <IInputDataLogger>(); inputDataLogger.Save(Constants.GeneralHouseholdKey, calcRepo.CalcParameters); inputDataLogger.Save(Constants.GeneralHouseholdKey, csps.TemperatureProfile); dtoltdict = scope.Resolve <CalcLoadTypeDtoDictionary>(); var affordanceTaggingSetFactory = scope.Resolve <AffordanceTaggingSetFactory>(); var affordanceTaggingSets = affordanceTaggingSetFactory.GetAffordanceTaggingSets(sim); if (calcRepo.CalcParameters.Options.Contains(CalcOption.AffordanceTaggingSets)) { inputDataLogger.Save(affordanceTaggingSets); } calcRepo.FileFactoryAndTracker.RegisterGeneralHouse(); dls = scope.Resolve <DayLightStatus>(); if (calcRepo.CalcParameters.Options.Contains(CalcOption.DaylightTimesList)) { inputDataLogger.Save(Constants.GeneralHouseholdKey, dls); } variableRepository = scope.Resolve <CalcVariableRepository>(); return(calcRepo); }
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 CalcAffordanceVariableTestSet() { var deviceCategoryGuid = Guid.NewGuid().ToStrGuid(); //var r = new Random(0); //var nr = new NormalRandom(0, 0.1, r); const int stepcount = 150; Config.IsInUnitTesting = true; DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(stepcount); //_calcParameters.InitializeTimeSteps(startdate, enddate, new TimeSpan(0, 1, 0), 3, false); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); var timeStep = new TimeSpan(0, 1, 0); var cp = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), timeStep, ProfileType.Absolute, "blub"); cp.AddNewTimepoint(new TimeSpan(0), 100); cp.AddNewTimepoint(new TimeSpan(0, 10, 0), 0); cp.ConvertToTimesteps(); var variables = new List <CalcAffordanceVariableOp>(); var variableReqs = new List <VariableRequirement>(); var loc = new CalcLocation("loc", Guid.NewGuid().ToStrGuid()); CalcVariableRepository calcVariableRepository = new CalcVariableRepository(); var variableGuid = Guid.NewGuid().ToStrGuid(); HouseholdKey key = new HouseholdKey("hh1"); CalcVariable cv = new CalcVariable("varname", variableGuid, 0, loc.Name, loc.Guid, key); calcVariableRepository.RegisterVariable(cv); variables.Add(new CalcAffordanceVariableOp(cv.Name, 1, loc, VariableAction.SetTo, VariableExecutionTime.Beginning, variableGuid)); BitArray isBusy = new BitArray(100, false); Random rnd = new Random(); NormalRandom nr = new NormalRandom(0, 1, rnd); using CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, odap: new Mock <IOnlineDeviceActivationProcessor>().Object, normalRandom: nr, rnd: rnd); var aff = new CalcAffordance("bla", cp, loc, false, new List <CalcDesire>(), 0, 99, PermittedGender.All, false, 0.1, new ColorRGB(0, 0, 0), "bla", false, false, variables, variableReqs, ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), calcVariableRepository, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); var lt = new CalcLoadType("load", "unit1", "unit2", 1, true, Guid.NewGuid().ToStrGuid()); var cdl = new CalcDeviceLoad("cdl", 1, lt, 1, 0.1); var devloads = new List <CalcDeviceLoad> { cdl }; CalcDeviceDto cdd = new CalcDeviceDto("device", deviceCategoryGuid, key, OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), loc.Guid, loc.Name); var cd = new CalcDevice(devloads, loc, cdd, calcRepo); //loc.Variables.Add("Variable1", 0); aff.AddDeviceTuple(cd, cp, lt, 0, timeStep, 10, 1); TimeStep ts = new TimeStep(0, 0, false); aff.IsBusy(ts, loc, "name"); //var variableOperator = new VariableOperator(); aff.Activate(ts, "blub", loc, out var _); calcVariableRepository.GetValueByGuid(variableGuid).Should().Be(1); }
public void PickRandomAffordanceFromEquallyAttractiveOnesTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); calcParameters.AffordanceRepetitionCount = 0; wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger)) { fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); //DateStampCreator dsc = new DateStampCreator(calcParameters); Random rnd = new Random(); //OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters); using (var lf = new LogFile(calcParameters, fft)) { CalcProfile cp = new CalcProfile("cp1", Guid.NewGuid().ToStrGuid(), TimeSpan.FromMinutes(1), ProfileType.Absolute, "bla"); CalcVariableRepository crv = new CalcVariableRepository(); BitArray isBusy = new BitArray(calcParameters.InternalTimesteps, false); using CalcRepo calcRepo = new CalcRepo(lf: lf, calcParameters: calcParameters, rnd: rnd); CalcAffordance aff1 = new CalcAffordance("aff1", cp, null, false, new List <CalcDesire>(), 10, 20, PermittedGender.All, true, 1, LPGColors.AliceBlue, null, false, false, null, null, ActionAfterInterruption.GoBackToOld, "", 900, false, "", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); CalcAffordance aff2 = new CalcAffordance("aff2", cp, null, false, new List <CalcDesire>(), 10, 20, PermittedGender.All, true, 1, LPGColors.AliceBlue, null, false, false, null, null, ActionAfterInterruption.GoBackToOld, "", 100, false, "", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); List <ICalcAffordanceBase> affs = new List <ICalcAffordanceBase> { aff1, aff2 }; int aff1C = 0; int aff2C = 0; BitArray isSick = new BitArray(calcParameters.InternalTimesteps); BitArray isOnVacation = new BitArray(calcParameters.InternalTimesteps); CalcPersonDto calcPerson = CalcPersonDto.MakeExamplePerson(); CalcPerson cperson = new CalcPerson(calcPerson, null, isSick, isOnVacation, calcRepo); TimeStep ts = new TimeStep(1, 0, true); for (int i = 0; i < 1000; i++) { ICalcAffordanceBase cab = cperson.PickRandomAffordanceFromEquallyAttractiveOnes(affs, ts, null, new HouseholdKey("bla")); if (cab == aff1) { aff1C++; } if (cab == aff2) { aff2C++; } } aff1C.Should().BeApproximatelyWithinPercent(900, 0.1); Logger.Info("Number of selections for 90%:" + aff1C + ", 10%:" + aff2C); } } wd.CleanUp(); } }
public void SetAllAffordaces([NotNull][ItemNotNull] List <CalcAffordanceDto> affordances, [NotNull] DtoCalcLocationDict locations, [NotNull] CalcVariableRepository variableRepository, [ItemNotNull][NotNull] List <CalcDevice> devices) { if (affordances.Count == 0) { throw new LPGException("No Affordances found."); } foreach (CalcAffordanceDto affordancedto in affordances) { CalcProfile personProfile = CalcDeviceFactory.MakeCalcProfile(affordancedto.PersonProfile, _calcRepo.CalcParameters); CalcLocation calcLocation = locations.GetCalcLocationByGuid(affordancedto.CalcLocationGuid); var calcDesires = MakeCalcDesires(affordancedto.Satisfactionvalues); var color = new ColorRGB(affordancedto.ColorR, affordancedto.ColorG, affordancedto.ColorB); var variableOps = MakeVariableOps(locations, affordancedto.VariableOps, variableRepository); List <VariableRequirement> requirements = new List <VariableRequirement>(); foreach (VariableRequirementDto requirementDto in affordancedto.VariableRequirements) { VariableRequirement vrq = new VariableRequirement(requirementDto.Name, requirementDto.Value, requirementDto.CalcLocationName, requirementDto.LocationGuid, requirementDto.VariableCondition, variableRepository, requirementDto.VariableGuid); requirements.Add(vrq); } var deviceEnergyProfiles = MakeDeviceEnergyProfileTuples(devices, affordancedto); var busyarr = _availabilityDtoRepository.GetByGuid(affordancedto.IsBusyArray.Guid); CalcAffordance caff = new CalcAffordance( affordancedto.Name, personProfile, calcLocation, affordancedto.RandomEffect, calcDesires, affordancedto.MiniumAge, affordancedto.MaximumAge, affordancedto.PermittedGender, affordancedto.NeedsLight, affordancedto.TimeStandardDeviation, color, affordancedto.AffCategory, affordancedto.IsInterruptable, affordancedto.IsInterrupting, variableOps, requirements, affordancedto.ActionAfterInterruption, affordancedto.TimeLimitName, affordancedto.Weight, affordancedto.RequireAllDesires, affordancedto.SrcTrait, affordancedto.Guid, variableRepository, deviceEnergyProfiles, busyarr, affordancedto.BodilyActivityLevel, _calcRepo); MakeSubAffordances(locations, variableRepository, affordancedto, caff); calcLocation.AddAffordance(caff); } }
public CalcDeviceFactory([NotNull] CalcLoadTypeDictionary loadTypeDictionary, [NotNull] AvailabilityDtoRepository availabilityDtoRepository, [NotNull] CalcVariableRepository calcVariableRepository, CalcRepo calcRepo) { _loadTypeDictionary = loadTypeDictionary; _availabilityDtoRepository = availabilityDtoRepository; _calcVariableRepository = calcVariableRepository; _calcRepo = calcRepo; }
public void VariableLogfileTests1() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new VariableEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().EnableShowSettlingPeriod(); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger)) { HouseholdKey key = new HouseholdKey("hh1"); fft.RegisterGeneralHouse(); fft.RegisterHousehold(key, "householdname", HouseholdKeyType.Household, "desc", null, null); DateStampCreator dsc = new DateStampCreator(calcParameters); using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { CalcVariableRepository cvr = new CalcVariableRepository(); //using (LogFile lf = new LogFile(calcParameters,fft, old,wd.SqlResultLoggingService, true)) CalcLocation cloc = new CalcLocation("loc1", Guid.NewGuid().ToStrGuid()); CalcVariable cv = new CalcVariable("mycalcvar", Guid.NewGuid().ToStrGuid(), 0, cloc.Name, cloc.Guid, key); cvr.RegisterVariable(cv); TimeStep ts = new TimeStep(0, calcParameters); old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 1, cv.LocationName, cv.LocationGuid, cv.HouseholdKey, ts)); old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 2, cv.LocationName, cv.LocationGuid, cv.HouseholdKey, ts)); old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 3, cv.LocationName, cv.LocationGuid, cv.HouseholdKey, ts)); old.FinalSaveToDatabase(); } VariableEntryLogger vel = new VariableEntryLogger(wd.SqlResultLoggingService); var varEntries = vel.Read(key); foreach (CalcVariableEntry entry in varEntries) { Logger.Info(entry.Value.ToString(CultureInfo.InvariantCulture)); } varEntries[0].Value.Should().Be(1); varEntries[1].Value.Should().Be(2); varEntries[2].Value.Should().Be(3); } /*old. * cloc.Add(); * cloc[0].Variables.Add("trig1", 1.0); * tlf.WriteLine(0, cloc); * cloc[0].Variables["trig1"] = 2.0; * tlf.WriteLine(1, cloc); * lf.Close(null);*/ wd.CleanUp(); } }
private void SetEnergyStoragesOnHouse([NotNull][ItemNotNull] List <CalcEnergyStorageDto> energyStorages, [NotNull] HouseholdKey householdKey, [NotNull] CalcHouse calchouse, CalcVariableRepository calcVariableRepository ) //, List<CalcDeviceTaggingSet> deviceTaggingSets) { var cess = new List <CalcEnergyStorage>(); var esCategoryGuid = Guid.NewGuid().ToStrGuid(); var esLocGuid = Guid.NewGuid().ToStrGuid(); foreach (var es in energyStorages) { //foreach (DeviceTaggingSet set in deviceTaggingSets) { //set.AddTag(es.Name,"House Device"); //} var lti = _ltDict.GetCalcLoadTypeByLoadtype(es.InputLoadType).ConvertToDto(); CalcDeviceDto deviceDto = new CalcDeviceDto(es.Name, esCategoryGuid, householdKey, OefcDeviceType.Storage, "Energy Storage", "", es.Guid, esLocGuid, "Energy Storages"); var ces = new CalcEnergyStorage(_calcRepo.Odap, lti, es.MaximumStorageRate, es.MaximumWithdrawRate, es.MinimumStorageRate, es.MinimumWithdrawRate, es.InitialFill, es.StorageCapacity, _calcRepo.Logfile.EnergyStorageLogfile, deviceDto ); foreach (var signal in es.Signals) { CalcVariable cv = calcVariableRepository.GetVariableByGuid(signal.CalcVariableDto.Guid); var cessig = new CalcEnergyStorageSignal(signal.Name, signal.TriggerOffPercent, signal.TriggerOnPercent, signal.Value, cv, signal.Guid); ces.AddSignal(cessig); } cess.Add(ces); if (ces.Signals.Count != es.Signals.Count) { throw new LPGException("Signal not initialized correctly"); } } var calcEnergyStorages = cess; //,deviceTaggingSets); calchouse.SetStorages(calcEnergyStorages); //return calcEnergyStorages; }
public CalcHouseFactory([NotNull] CalcLoadTypeDictionary ltDict, [NotNull] CalcModularHouseholdFactory cmhf, [NotNull] AvailabilityDtoRepository availabilityDtoRepository, [NotNull] CalcVariableRepository variableRepository, [NotNull] CalcDeviceTaggingSets calcDeviceTaggingSets, CalcRepo calcRepo) { _ltDict = ltDict; _cmhf = cmhf; _availabilityDtoRepository = availabilityDtoRepository; _variableRepository = variableRepository; _calcDeviceTaggingSets = calcDeviceTaggingSets; _calcRepo = calcRepo; }
public CalcManager([NotNull] string resultPath, int randomSeed, [NotNull] DayLightStatus lightNeededArray, [NotNull] CalcVariableRepository variableRepository, CalcRepo calcRepo) { _lightNeededArray = lightNeededArray; //_srls = srls; _randomSeed = randomSeed; //_fileVersion = fileVersion; //_calcHouseholdPlans = calcHouseholdPlans; //_affordanceTaggingSets = affordanceTaggingSets; //_deviceTaggingSets = deviceTaggingSets; _resultPath = resultPath; //_name = pName; _variableRepository = variableRepository; CalcRepo = calcRepo; }
//private readonly CalcVariableDtoFactory _variableDtoFactory; public CalcModularHouseholdFactory([NotNull] CalcLoadTypeDictionary ltDict, [NotNull] CalcLocationFactory clf, [NotNull] CalcPersonFactory cpf, [NotNull] CalcDeviceFactory cdf, [NotNull] CalcAffordanceFactory caf, [NotNull] CalcTransportationFactory ctf, [NotNull] CalcVariableRepository variableRepository, CalcRepo calcRepo ) { _ltDict = ltDict; _clf = clf; _cpf = cpf; _cdf = cdf; _caf = caf; _ctf = ctf; _calcVariableRepository = variableRepository; _calcRepo = calcRepo; }
private static List <CalcAffordanceVariableOp> MakeVariableOps([NotNull] DtoCalcLocationDict locations, [NotNull][ItemNotNull] List <CalcAffordanceVariableOpDto> affordancedto, [NotNull] CalcVariableRepository repository) { List <CalcAffordanceVariableOp> variableOps = new List <CalcAffordanceVariableOp>(); foreach (CalcAffordanceVariableOpDto variableOpDto in affordancedto) { if (!repository.IsVariableRegistered(variableOpDto.VariableGuid)) { throw new LPGException("Variable " + variableOpDto.Name + " was not registered."); } CalcLocation variableLocation = locations.GetCalcLocationByGuid(variableOpDto.LocationGuid); var variableOp = new CalcAffordanceVariableOp(variableOpDto.Name, variableOpDto.Value, variableLocation, variableOpDto.VariableAction, variableOpDto.ExecutionTime, variableOpDto.VariableGuid); variableOps.Add(variableOp); } return(variableOps); }
private static void RegisterAllDtoVariables([NotNull] CalcVariableDtoFactory cvrdto, [NotNull] CalcVariableRepository variableRepository) { foreach (var v in cvrdto.GetAllVariableDtos()) { variableRepository.RegisterVariable(new CalcVariable(v.Name, v.Guid, v.Value, v.LocationName, v.LocationGuid, v.HouseholdKey)); } }
public void RunDeviceOffsetTest() { //var r = new Random(0); //var nr = new NormalRandom(0, 0.1, r); const int stepcount = 150; var devCategoryGuid = Guid.NewGuid().ToStrGuid(); Config.IsInUnitTesting = true; DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(stepcount); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); var timeStep = new TimeSpan(0, 1, 0); var cp = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), timeStep, ProfileType.Absolute, "blub"); cp.AddNewTimepoint(new TimeSpan(0), 100); cp.AddNewTimepoint(new TimeSpan(0, 10, 0), 0); cp.ConvertToTimesteps(); var loc = new CalcLocation(Utili.GetCurrentMethodAndClass(), Guid.NewGuid().ToStrGuid()); CalcVariableRepository crv = new CalcVariableRepository(); BitArray isBusy = new BitArray(calcParameters.InternalTimesteps, false); Random rnd = new Random(); NormalRandom nr = new NormalRandom(0, 1, rnd); using CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, odap: new Mock <IOnlineDeviceActivationProcessor>().Object, rnd: rnd, normalRandom: nr); var aff = new CalcAffordance("bla", cp, loc, false, new List <CalcDesire>(), 0, 99, PermittedGender.All, false, 0, new ColorRGB(0, 0, 0), "bla", false, false, new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(), ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); var lt = new CalcLoadType("load", "unit1", "unit2", 1, true, Guid.NewGuid().ToStrGuid()); var cdl = new CalcDeviceLoad("cdl", 1, lt, 1, 0.1); //var variableOperator = new VariableOperator(); var devloads = new List <CalcDeviceLoad> { cdl }; HouseholdKey key = new HouseholdKey("HH1"); CalcDeviceDto cdd = new CalcDeviceDto("device", devCategoryGuid, key, OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), loc.Guid, loc.Name); var cd = new CalcDevice(devloads, loc, cdd, calcRepo); aff.AddDeviceTuple(cd, cp, lt, 20, timeStep, 10, 1); //bool result = aff.IsBusy(0, nr, r, loc); //(result).Should().BeFalse(); CheckForBusyness(loc, aff, cd, lt); TimeStep ts = new TimeStep(0, 0, false); aff.Activate(ts.AddSteps(10), "blub", loc, out var _); CheckForBusyness(loc, aff, cd, lt); aff.IsBusy(ts.AddSteps(1), loc, "name", false).Should().BeTrue(); aff.IsBusy(ts.AddSteps(19), loc, "name", false).Should().BeTrue(); aff.IsBusy(ts, loc, "name", false).Should().BeFalse(); aff.IsBusy(ts.AddSteps(20), loc, "name", false).Should().BeFalse(); }
private static ICalcAbleObject MakeCalcHouseObject([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 house = (House)hh; calcRepo.FileFactoryAndTracker.RegisterHousehold(Constants.HouseKey, "House Infrastructure", HouseholdKeyType.House, "House Infrastructure", house.Name, house.Description); var housedtoFac = scope.Resolve <CalcHouseDtoFactory>(); var housedto = housedtoFac.MakeHouseDto(sim, house, csps.TemperatureProfile, csps.GeographicLocation, csps.EnergyIntensity); foreach (HouseholdKeyEntry entry in housedto.GetHouseholdKeyEntries()) { calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, entry); } var convertedAutoDevList = housedto.AutoDevs.ConvertAll(x => (IHouseholdKey)x).ToList(); if (calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents)) { calcRepo.InputDataLogger.SaveList(convertedAutoDevList); calcRepo.InputDataLogger.Save(Constants.GeneralHouseholdKey, housedto); } var chf = scope.Resolve <CalcHouseFactory>(); RegisterAllDtoVariables(cvrdto, variableRepository); ICalcAbleObject ch = chf.MakeCalcHouse(housedto, calcRepo); cot = CalcObjectType.House; return(ch); }
public void CheckResultingProfile() { using var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()); wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(100); CalcParameters calculationParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).EnableShowSettlingPeriod(); var profile = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), new TimeSpan(0, 1, 0), ProfileType.Relative, "blub"); profile.AddNewTimepoint(new TimeSpan(0), 0.01); profile.AddNewTimepoint(new TimeSpan(1, 0, 0), 0.01); profile.ConvertToTimesteps(); var cloadtype = new CalcLoadType("loadtype", "power", "sum", 1, true, Guid.NewGuid().ToStrGuid()); var loads = new List <CalcDeviceLoad>(); var cdl = new CalcDeviceLoad("cdevload", 100, cloadtype, 100, 0.1); loads.Add(cdl); var r = new Random(5); HouseholdKey key = new HouseholdKey("hh1"); var nr = new NormalRandom(0, 1, r); using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "householdname", wd.InputDataLogger); fft.RegisterHousehold(key, "hh1", HouseholdKeyType.Household, "desc", null, null); fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); DateStampCreator dsc = new DateStampCreator(calculationParameters); using OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calculationParameters); var odap = new OnlineDeviceActivationProcessor(old, calculationParameters, fft); using CalcRepo calcRepo = new CalcRepo(odap: odap, normalRandom: nr, calcParameters: calculationParameters); var location = new CalcLocation("calcloc", Guid.NewGuid().ToStrGuid()); CalcVariableRepository crv = new CalcVariableRepository(); var variableGuid = Guid.NewGuid().ToStrGuid(); CalcVariable cv = new CalcVariable("varname", variableGuid, 0, location.Name, location.Guid, key); crv.RegisterVariable(cv); VariableRequirement vreq = new VariableRequirement(cv.Name, 0, location.Name, location.Guid, VariableCondition.Equal, crv, variableGuid); List <VariableRequirement> requirements = new List <VariableRequirement> { vreq }; var deviceCategoryGuid = Guid.NewGuid().ToStrGuid(); CalcDeviceDto cdd = new CalcDeviceDto("autodevnamename", deviceCategoryGuid, key, OefcDeviceType.AutonomousDevice, "device category", "", Guid.NewGuid().ToStrGuid(), location.Guid, location.Name); var cad = new CalcAutoDev(profile, cloadtype, loads, 0.8, 1, location, requirements, cdd, calcRepo); for (var i = 0; i < 100; i++) { TimeStep ts = new TimeStep(i, calculationParameters); if (!cad.IsBusyDuringTimespan(ts, 1, 0.7, cloadtype)) { cad.Activate(ts); } var rows = odap.ProcessOneTimestep(ts); foreach (var energyFileRow in rows) { foreach (var energyEntry in energyFileRow.EnergyEntries) { Logger.Info(energyEntry.ToString(CultureInfo.CurrentCulture)); } } } }
private static CalcRepo SetupFullWorkingTransportationExample([NotNull] WorkingDir wd, [NotNull] Random rnd, [NotNull] out NormalRandom nr, [NotNull] out CalcLocation srcloc, [NotNull] out CalcLocation dstloc, [NotNull] out CalcSite dstSite, [NotNull] out TransportationHandler transportationHandler, [NotNull] out AffordanceBaseTransportDecorator abt, [NotNull] CalcParameters calcParameters, [NotNull] HouseholdKey key) { Config.IsInUnitTesting = true; CalcAffordance.DoubleCheckBusyArray = true; nr = new NormalRandom(0, 0.1, rnd); var calcprofilevalues = new List <double> { 10, 20, 30 }; var cp = new CalcProfile("calcprofile", Guid.NewGuid().ToStrGuid(), calcprofilevalues, ProfileType.Absolute, "syn"); srcloc = new CalcLocation("srclocation", Guid.NewGuid().ToStrGuid()); dstloc = new CalcLocation("dstlocation", Guid.NewGuid().ToStrGuid()); var calcdesire = new CalcDesire("calcdesire", 1, 0.5m, 10, 1, 1, 60, 0.1m, null, "sourcetrait", "desirecat"); var calcdesires = new List <CalcDesire> { calcdesire }; CalcVariableRepository crv = new CalcVariableRepository(); Mock <IOnlineDeviceActivationProcessor> iodap = new Mock <IOnlineDeviceActivationProcessor>(); var old = new Mock <IOnlineLoggingData>(); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hh0", wd.InputDataLogger)) { using (var lf = new LogFile(calcParameters, fft, true)) { var calcRepo = new CalcRepo(odap: iodap.Object, calcParameters: calcParameters, rnd: rnd, normalRandom: nr, onlineLoggingData: old.Object, lf: lf); BitArray isBusy = new BitArray(calcParameters.InternalTimesteps, false); var ca = new CalcAffordance("calcaffordance", cp, dstloc, false, calcdesires, 18, 50, PermittedGender.All, false, 0.1, LPGColors.Blue, "affordance category", false, false, new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(), ActionAfterInterruption.GoBackToOld, "timelimitname", 1, false, "srctrait", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); var srcSite = new CalcSite("srcsite", Guid.NewGuid().ToStrGuid(), key); srcSite.Locations.Add(srcloc); dstSite = new CalcSite("dstSite", Guid.NewGuid().ToStrGuid(), key); dstSite.Locations.Add(dstloc); fft.RegisterHousehold(new HouseholdKey("hh0"), "hh0-prettyname", HouseholdKeyType.Household, "Desc", null, null); transportationHandler = new TransportationHandler(); transportationHandler.AddSite(srcSite); abt = new AffordanceBaseTransportDecorator(ca, dstSite, transportationHandler, "travel to dstsite", new HouseholdKey("hh0"), Guid.NewGuid().ToStrGuid(), calcRepo); dstloc.AddTransportationAffordance(abt); var ctr = new CalcTravelRoute("myRoute1", srcSite, dstSite, transportationHandler.VehicleDepot, transportationHandler.LocationUnlimitedDevices, new HouseholdKey("hh0"), Guid.NewGuid().ToStrGuid(), calcRepo); var myCategory = new CalcTransportationDeviceCategory("mycategory", false, Guid.NewGuid().ToStrGuid()); ctr.AddTravelRouteStep("driving", myCategory, 1, 36000, Guid.NewGuid().ToStrGuid()); transportationHandler.TravelRoutes.Add(ctr); CalcLoadType chargingloadtype = new CalcLoadType("chargingloadtype", "W", "kwh", 1, true, Guid.NewGuid().ToStrGuid()); List <CalcSite> calcSites = new List <CalcSite> { srcSite, dstSite }; var list = new List <CalcDeviceLoad>(); CalcDeviceLoad cdl = new CalcDeviceLoad("bla", 1, chargingloadtype, 1, 1); list.Add(cdl); CalcDeviceDto cdd = new CalcDeviceDto("bus", myCategory.Guid, new HouseholdKey("hh1"), OefcDeviceType.Transportation, myCategory.Name, string.Empty, Guid.NewGuid().ToStrGuid(), string.Empty.ToStrGuid(), string.Empty); var transportationDevice = new CalcTransportationDevice(myCategory, 1, list, 100, 10, 1000, chargingloadtype, calcSites, cdd, calcRepo); transportationHandler.LocationUnlimitedDevices.Add(transportationDevice); return(calcRepo); } } }
private static void SetupProbabilityTest([NotNull] out CalcAffordance aff, [NotNull] out CalcLoadType lt, [NotNull] out CalcDevice cd, [NotNull] out CalcLocation loc, int stepcount, double probability) { Config.IsInUnitTesting = true; DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(stepcount); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); var timeStep = new TimeSpan(0, 1, 0); var cp = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), timeStep, ProfileType.Absolute, "blub"); cp.AddNewTimepoint(new TimeSpan(0), 100); cp.AddNewTimepoint(new TimeSpan(0, 10, 0), 0); cp.ConvertToTimesteps(); loc = new CalcLocation(Utili.GetCurrentMethodAndClass(), Guid.NewGuid().ToStrGuid()); CalcVariableRepository cvr = new CalcVariableRepository(); BitArray isBusy = new BitArray(100, false); var r = new Random(0); var nr = new NormalRandom(0, 0.1, r); IMock <IOnlineDeviceActivationProcessor> iodap = new Mock <IOnlineDeviceActivationProcessor>(); using CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, normalRandom: nr, rnd: r, odap: iodap.Object); aff = new CalcAffordance("bla", cp, loc, false, new List <CalcDesire>(), 0, 99, PermittedGender.All, false, 0.1, new ColorRGB(0, 0, 0), "bla", false, false, new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(), ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), cvr, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); lt = new CalcLoadType("load", "unit1", "unit2", 1, true, Guid.NewGuid().ToStrGuid()); var cdl = new CalcDeviceLoad("cdl", 1, lt, 1, 0.1); var devloads = new List <CalcDeviceLoad> { cdl }; CalcDeviceDto cdd = new CalcDeviceDto("device", "devcategoryguid".ToStrGuid(), new HouseholdKey("HH1"), OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), loc.Guid, loc.Name); cd = new CalcDevice(devloads, loc, cdd, calcRepo); aff.AddDeviceTuple(cd, cp, lt, 0, timeStep, 10, probability); }
public void TestInterruptionTest() { using var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()); DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(100); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod().DisableShowSettlingPeriod().SetAffordanceRepetitionCount(1); //var r = new Random(1); //var nr = new NormalRandom(0, 1, r); var desire1 = new CalcDesire("desire1", 1, 0.5m, 4, 1, 1, 60, -1, null, "", ""); var lt = new CalcLoadType("calcLoadtype1", "kwh", "W", 1, true, Guid.NewGuid().ToStrGuid()); //var variableOperator = new VariableOperator(); using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger); var key = new HouseholdKey("HH1"); wd.InputDataLogger.AddSaver(new ActionEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new LocationEntryLogger(wd.SqlResultLoggingService)); fft.RegisterHousehold(key, "hh1", HouseholdKeyType.Household, "desc", null, null); fft.RegisterHousehold(Constants.GeneralHouseholdKey, "General", HouseholdKeyType.General, "Desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); DateStampCreator dsc = new DateStampCreator(calcParameters); using OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters); using var lf = new LogFile(calcParameters, fft); var cloc = new CalcLocation("loc1", Guid.NewGuid().ToStrGuid()); BitArray isSick = new BitArray(calcParameters.InternalTimesteps); BitArray isOnVacation = new BitArray(calcParameters.InternalTimesteps); CalcPersonDto calcPerson = CalcPersonDto.MakeExamplePerson(); var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); Random rnd = new Random(); NormalRandom nr = new NormalRandom(0, 1, rnd); using CalcRepo calcRepo = new CalcRepo(lf: lf, odap: odap, calcParameters: calcParameters, rnd: rnd, normalRandom: nr, onlineLoggingData: old); var cp = new CalcPerson(calcPerson, cloc, isSick, isOnVacation, calcRepo); //"blub", 1, 1, r,20, PermittedGender.Male, lf, "HH1", cloc,"traittag","hhname0", calcParameters,isSick, Guid.NewGuid().ToStrGuid()); cp.PersonDesires.AddDesires(desire1); cp.SicknessDesires.AddDesires(desire1); var deviceLoads = new List <CalcDeviceLoad> { new CalcDeviceLoad("devload1", 1, lt, 100, 1) }; var devCategoryGuid = Guid.NewGuid().ToStrGuid(); CalcDeviceDto cdd1 = new CalcDeviceDto("cdevice1", devCategoryGuid, key, OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var cdev1 = new CalcDevice(deviceLoads, cloc, cdd1, calcRepo); CalcDeviceDto cdd2 = new CalcDeviceDto("cdevice2", devCategoryGuid, key, OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var cdev2 = new CalcDevice(deviceLoads, cloc, cdd2, calcRepo); CalcDeviceDto cdd3 = new CalcDeviceDto("cdevice3", devCategoryGuid, key, OefcDeviceType.Device, "category", "", Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); var cdev3 = new CalcDevice(deviceLoads, cloc, cdd3, calcRepo); cloc.Devices.Add(cdev1); cloc.Devices.Add(cdev2); cloc.Devices.Add(cdev3); var daylight = new BitArray(100); daylight.SetAll(true); DayLightStatus dls = new DayLightStatus(daylight); double[] newValues = { 1, 1, 1.0, 1, 1, 1, 1, 1 }; var newList = new List <double>(newValues); var cprof = new CalcProfile("cp1", Guid.NewGuid().ToStrGuid(), newList, ProfileType.Relative, "bla"); var desires = new List <CalcDesire> { desire1 }; var color = new ColorRGB(255, 0, 0); CalcVariableRepository crv = new CalcVariableRepository(); BitArray isBusy = new BitArray(calcParameters.InternalTimesteps, false); var aff1 = new CalcAffordance("aff1", cprof, cloc, false, desires, 1, 100, PermittedGender.All, false, 0, color, "aff category", true, false, new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(), ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), crv , new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); aff1.AddDeviceTuple(cdev1, cprof, lt, 0, calcParameters.InternalStepsize, 1, 1); cloc.AddAffordance(aff1); var aff2 = new CalcAffordance("aff2", cprof, cloc, false, desires, 1, 100, PermittedGender.All, false, 0, color, "aff category", false, false, new List <CalcAffordanceVariableOp>(), new List <VariableRequirement>(), ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(), crv , new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); aff2.AddDeviceTuple(cdev2, cprof, lt, 0, calcParameters.InternalStepsize, 1, 1); cloc.AddAffordance(aff2); var clocs = new List <CalcLocation> { cloc }; BitArray isBusySub = new BitArray(calcParameters.InternalTimesteps, false); var calcSubAffordance = new CalcSubAffordance("subaffname", cloc, desires, 0, 100, 1, PermittedGender.All, "subaff", false, true, aff1, new List <CalcAffordanceVariableOp>(), 100, "testing", Guid.NewGuid().ToStrGuid(), isBusySub, crv, BodilyActivityLevel.Low, calcRepo); aff2.SubAffordances.Add(calcSubAffordance); calcSubAffordance.SetDurations(2); var persons = new List <CalcPerson> { cp }; for (var i = 0; i < 100; i++) { TimeStep ts = new TimeStep(i, 0, true); cp.NextStep(ts, clocs, dls, new HouseholdKey("hh1"), persons, 1); } //wd.CleanUp(); }