Esempio n. 1
0
        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 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);
                }
            }
        }