public void CalcPersonDesiresTest() { CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); var r = new Random(1); using (CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, rnd: r)) { var cpd = new CalcPersonDesires(calcRepo); var cd1 = new CalcDesire("blub0", 1, 0.5m, 0.1m, 1, 1, 1, -1, null, "", ""); cpd.AddDesires(cd1); var cd2 = new CalcDesire("blub1", 2, 0.5m, 0.1m, 1, 1, 1, -1, null, "", ""); cpd.AddDesires(cd2); Logger.Info("CalcPersonDesiresTest:" + cd1.Value + " ; " + cd2.Value); // satisfaction var satis1 = new CalcDesire("blub", 1, 0.5m, 12, 1, 1, 60, -1, null, "", "") { Value = 1 }; var satisfactionValues = new List <CalcDesire> { satis1 }; Logger.Info(cd1.Value + " ; " + cd2.Value); for (var i = 0; i < 20; i++) { TimeStep ts = new TimeStep(i, 0, false); cpd.ApplyDecay(ts); cpd.ApplyAffordanceEffect(satisfactionValues, true, "blub"); Logger.Info(cd1.Value + " ; " + cd2.Value); } } }
private static List <CalcDesire> MakeCalcDesires([NotNull][ItemNotNull] List <CalcDesireDto> satisfactionValues) { List <CalcDesire> calcDesires = new List <CalcDesire>(); foreach (CalcDesireDto desireDto in satisfactionValues) { CalcDesire calcDesire = new CalcDesire(desireDto.Name, desireDto.DesireID, desireDto.Threshold, desireDto.DecayTime, desireDto.Value, desireDto.Weight, desireDto.TimestepsPerHour, desireDto.CriticalThreshold, null, desireDto.SourceTrait, desireDto.DesireCategory); calcDesires.Add(calcDesire); } return(calcDesires); }
public void TestBasics() { // needs major redesign of calcperson class using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) {// StreamFactory sf = new StreamFactory(); DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(100); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).EnableShowSettlingPeriod().SetSettlingDays(0); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "test1", wd.InputDataLogger)) { fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); CalculationProfiler profiler = new CalculationProfiler(); CalcRepo calcRepo = CalcRepo.Make(calcParameters, wd.InputDataLogger, wd.WorkingDirectory, "name", profiler); DesiresLogFile dlf = new DesiresLogFile(fft, calcParameters); CalcDesire cd1 = new CalcDesire("desire1", 1, 0.5m, 12, 1, 1, 60, -1, null, "", ""); //NormalRandom nr = new NormalRandom(0, 0.1, r); CalcLocation cloc = new CalcLocation("cloc", Guid.NewGuid().ToStrGuid()); BitArray isSick = new BitArray(calcParameters.InternalTimesteps); BitArray isOnVacation = new BitArray(calcParameters.InternalTimesteps); CalcPersonDto calcPerson = CalcPersonDto.MakeExamplePerson(); CalcPerson cp = new CalcPerson(calcPerson, cloc, isSick, isOnVacation, calcRepo); //"bla", 1, 5, r, 48, PermittedGender.Male, lf, "HH1", cloc, "traittag", "hhname0",calcParameters,isSick,Guid.NewGuid().ToStrGuid()); cp.PersonDesires.AddDesires(cd1); dlf.RegisterDesires(cp.PersonDesires.Desires.Values); TimeStep ts = new TimeStep(0, 0, true); DesireEntry de = new DesireEntry(cp, ts, cp.PersonDesires, dlf, calcParameters); fft.RegisterHousehold(new HouseholdKey("hh1"), "bla", HouseholdKeyType.Household, "desc", null, null); dlf.WriteEntry(de, new HouseholdKey("hh1")); dlf.Dispose(); } wd.CleanUp(); } }
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(); }
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); } } }