예제 #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);
                }

                //}
            }
        }
 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();
     }
 }
        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);
                }
            }
        }