コード例 #1
0
        private void MakeTravelRoutes([NotNull][ItemNotNull] List <CalcTravelRouteDto> travelRouteDtos,
                                      [NotNull] CalcHousehold chh, [NotNull][ItemNotNull] List <CalcSite> sites, [NotNull] TransportationHandler th)
        {
            foreach (CalcTravelRouteDto travelRouteDto in travelRouteDtos)
            {
                CalcSite siteA = sites.Single(x => x.Guid == travelRouteDto.SiteAGuid);
                CalcSite siteB = sites.Single(x => x.Guid == travelRouteDto.SiteBGuid);

                //if (siteA != null && siteB != null) {
                //if either site is null, the travel route is not usable for this household
                CalcTravelRoute travelRoute = new CalcTravelRoute(travelRouteDto.Name,
                                                                  siteA, siteB, th.VehicleDepot, th.LocationUnlimitedDevices, chh.HouseholdKey,
                                                                  travelRouteDto.Guid, _calcRepo);
                foreach (var step in travelRouteDto.Steps)
                {
                    CalcTransportationDeviceCategory category = th.GetCategory(step.TransportationDeviceCategory);
                    travelRoute.AddTravelRouteStep(step.Name, category, step.StepNumber, step.DistanceInM,
                                                   step.Guid);
                }
                if (siteA != siteB)
                {
                    th.TravelRoutes.Add(travelRoute);
                }
                else
                {
                    th.SameSiteRoutes.Add(siteA, travelRoute);
                }

                //}
            }
        }
コード例 #2
0
        protected CalcAffordanceBase([NotNull] string pName, [NotNull] CalcLocation loc,
                                     [NotNull][ItemNotNull] List <CalcDesire> satisfactionvalues,
                                     int miniumAge, int maximumAge, PermittedGender permittedGender, bool needsLight,
                                     bool randomEffect,
                                     [NotNull] string pAffCategory, bool isInterruptable, bool isInterrupting,
                                     ActionAfterInterruption actionAfterInterruption, int weight,
                                     bool requireAllAffordances,
                                     CalcAffordanceType calcAffordanceType,
                                     StrGuid guid,
                                     [ItemNotNull][NotNull] BitArray isBusyArray,
                                     BodilyActivityLevel bodilyActivityLevel, [NotNull] CalcRepo calcRepo,
                                     [CanBeNull] CalcSite site = null) : base(pName, guid)
        {
            CalcAffordanceType  = calcAffordanceType;
            BodilyActivityLevel = bodilyActivityLevel;
            CalcRepo            = calcRepo;
            Site               = site;
            ParentLocation     = loc;
            Satisfactionvalues = satisfactionvalues;
            _isBusyArray       = new BitArray(calcRepo.CalcParameters.InternalTimesteps);
            //copy to make sure that it is a separate instance
            for (var i = 0; i < isBusyArray.Length; i++)
            {
                _isBusyArray[i] = isBusyArray[i];
            }
            Weight = weight;
            RequireAllAffordances    = requireAllAffordances;
            MiniumAge                = miniumAge;
            MaximumAge               = maximumAge;
            PermittedGender          = permittedGender;
            NeedsLight               = needsLight;
            RandomEffect             = randomEffect;
            AffCategory              = pAffCategory;
            IsInterruptable          = isInterruptable;
            IsInterrupting           = isInterrupting;
            _actionAfterInterruption = actionAfterInterruption;
            CalcAffordanceSerial     = _calcAffordanceBaseSerialTracker;
#pragma warning disable S3010 // Static fields should not be updated in constructors
            _calcAffordanceBaseSerialTracker++;
#pragma warning restore S3010 // Static fields should not be updated in constructors
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public void TestCalcSite()
 {
     using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
     {
         wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
         wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
         CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(2018, 1, 1).SetEndDate(2018, 2, 1).SetSettlingDays(0).EnableShowSettlingPeriod();
         HouseholdKey   hhkey          = new HouseholdKey("hh0");
         using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hhname0", wd.InputDataLogger))
         {
             fft.RegisterHousehold(hhkey, "hhname0", HouseholdKeyType.Household, "desc", null, null);
             fft.RegisterGeneralHouse();
             OnlineLoggingData old = new OnlineLoggingData(new DateStampCreator(calcParameters), wd.InputDataLogger, calcParameters);
             using (LogFile lf = new LogFile(calcParameters,
                                             fft, true))
             {
                 Random   r               = new Random(1);
                 CalcSite src             = new CalcSite("src", Guid.NewGuid().ToStrGuid(), hhkey);
                 CalcSite dst             = new CalcSite("dst", Guid.NewGuid().ToStrGuid(), hhkey);
                 TransportationHandler th = new TransportationHandler();
                 //List<CalcTravelRoute> routes = src.GetViableTrafficRoutes(dst);
                 //Assert.That(routes.Count,Is.EqualTo( 0));
                 var iodap = new Mock <IOnlineDeviceActivationProcessor>();
                 using (CalcRepo calcRepo = new CalcRepo(odap: iodap.Object, lf: lf, rnd: r, calcParameters: calcParameters, onlineLoggingData: old))
                 {
                     CalcTravelRoute firstRoute = new CalcTravelRoute("route1", src, dst, th.VehicleDepot,
                                                                      th.LocationUnlimitedDevices, hhkey, Guid.NewGuid().ToStrGuid(), calcRepo);
                     CalcTransportationDeviceCategory transcategory =
                         new CalcTransportationDeviceCategory("car-category", true, Guid.NewGuid().ToStrGuid());
                     firstRoute.AddTravelRouteStep("step1", transcategory, 1, 3600, Guid.NewGuid().ToStrGuid());
                     src.AddRoute(firstRoute);
                     //List<CalcTravelRoute> routes2 = src.GetViableTrafficRoutes(dst);
                     //Assert.That(routes2.Count,Is.EqualTo(0));
                     const double    distanceToEnergyFactor = 1;
                     List <CalcSite> calcSites = new List <CalcSite>
                     {
                         src,
                         dst
                     };
                     CalcLoadType   chargingLoadType = new CalcLoadType("chargingloadtype", "w", "kwh", 1, false, Guid.NewGuid().ToStrGuid());
                     var            cdls             = new List <CalcDeviceLoad>();
                     CalcDeviceLoad cdl = new CalcDeviceLoad("name", 1, chargingLoadType, 1, 1);
                     cdls.Add(cdl);
                     CalcDeviceDto dto = new CalcDeviceDto("car-device", transcategory.Guid,
                                                           hhkey, OefcDeviceType.Transportation, transcategory.Name, string.Empty,
                                                           Guid.NewGuid().ToStrGuid(), StrGuid.Empty, string.Empty);
                     CalcTransportationDevice ctd = new CalcTransportationDevice(transcategory, 1,
                                                                                 cdls, 100, distanceToEnergyFactor,
                                                                                 1000, chargingLoadType,
                                                                                 calcSites, dto, calcRepo);
                     th.VehicleDepot.Add(ctd);
                     //List<CalcTravelRoute> routes3 = src.GetViableTrafficRoutes(dst);
                     //(1).Should().Be(routes3.Count);
                     TimeStep ts       = new TimeStep(1, 0, false);
                     int?     duration = firstRoute.GetDuration(ts, "name", new List <CalcTransportationDevice>());
                     Logger.Info("Duration: " + duration);
                     duration.Should().Be(60);        // 3600 m bei 1 m/s
                     int?duration2 = firstRoute.GetDuration(ts, "name", new List <CalcTransportationDevice>());
                     duration.Should().Be(duration2); // 3600 m bei 1 m/s*/
                 }
             }
         }
         wd.CleanUp();
     }
 }
        public void CalcTransportationDeviceDriveTest()
        {
            using var wd  = new WorkingDir(Utili.GetCurrentMethodAndClass());
            using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger);
            wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
            wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService));
            wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
            //_calcParameters.CSVCharacter = ";";_calcParameters.InitializeTimeSteps(new DateTime(2018,1,1),new DateTime(2018,1,31),new TimeSpan(0,1,0),3,true  );
            var calcParameters = CalcParametersFactory.MakeGoodDefaults();

            var category = new CalcTransportationDeviceCategory("category", true, Guid.NewGuid().ToStrGuid());
            var lt2      = new CalcLoadType("driving load", "km/h", "km", 10000, false, Guid.NewGuid().ToStrGuid());
            var rnd      = new Random(1);
            var nr       = new NormalRandom(0, 0.1, rnd);
            //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory);
            var dsc = new DateStampCreator(calcParameters);

            using var old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters);
            using var lf  = new LogFile(calcParameters, fft, true);
            var key = new HouseholdKey("hh1");

            fft.RegisterHousehold(key, "Household", HouseholdKeyType.Household, "Description", null, null);
            fft.RegisterGeneralHouse();
            var chargingCalcLoadType = new CalcLoadType("charging load", "W", "kWh", 0.50, false, Guid.NewGuid().ToStrGuid());
            var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft);

            using var calcRepo = new CalcRepo(rnd: rnd, normalRandom: nr, lf: lf, calcParameters: calcParameters, odap: odap,
                                              onlineLoggingData: old);
            var srcSite = new CalcSite("srcsite", Guid.NewGuid().ToStrGuid(), key);
            var dstSite = new CalcSite("dstSite", Guid.NewGuid().ToStrGuid(), key);
            var station = new CalcChargingStation(category, chargingCalcLoadType, 500, "stationname", "stationguid".ToStrGuid(),
                                                  key, chargingCalcLoadType, calcRepo);

            dstSite.ChargingDevices.Add(station);
            var calcSites = new List <CalcSite> {
                srcSite,
                dstSite
            };
            var cdd = new CalcDeviceDto("transport device", category.Guid, key, OefcDeviceType.Transportation, category.Name,
                                        string.Empty, Guid.NewGuid().ToStrGuid(), StrGuid.Empty, string.Empty);
            var loads = new List <CalcDeviceLoad> {
                new CalcDeviceLoad("load1", 10, lt2, 10000, 0)
            };
            var ctd = new CalcTransportationDevice(category, 10, loads, 10000, 1, 1000, chargingCalcLoadType, calcSites, cdd,
                                                   calcRepo);
            var start = new TimeStep(1, 0, false);
            var end   = new TimeStep(11, 0, false);

            ctd.Activate(start, 10, srcSite, dstSite, "myroute", "myperson", start, end);

            ctd.AvailableRangeInMeters.Should().Be(10000);
            //TODO: fix this and comment out
            //station.IsAvailable = false;
            double prevrange = 0;

            for (var i = 1; i < 11; i++)
            {
                var ts = new TimeStep(i, 0, false);
                ctd.DriveAndCharge(ts);
                odap.ProcessOneTimestep(ts);
                var diffRange = prevrange - ctd.AvailableRangeInMeters;
                Logger.Info("timestep: " + i + " Range: " + ctd.AvailableRangeInMeters + " diff:" + diffRange);
                prevrange = ctd.AvailableRangeInMeters;
                ctd.Currentsite.Should().BeNull();
            }

            //no charging
            ctd.AvailableRangeInMeters.Should().Be(10000 - 10 * 60 * 10); //10m/s = 600m/minute
            Logger.Info("currentSite:" + ctd.Currentsite?.Name);

            //station.IsAvailable = true;
            for (var i = 11; i < 50; i++)
            {
                var ts = new TimeStep(i, 0, false);
                ctd.DriveAndCharge(ts);
                odap.ProcessOneTimestep(ts);
                Logger.Info("timestep: " + i + " Range: " + ctd.AvailableRangeInMeters);
            }

            ctd.Currentsite.Should().Be(dstSite);

            //  wd.CleanUp(1);
        }
        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);
                }
            }
        }