Esempio n. 1
0
        private void SetAffordances([NotNull] CalcHousehold chh)
        {
            foreach (CalcLocation location in chh.Locations)
            {
                foreach (var aff in location.PureAffordances)
                {
                    //replace with affordance decorator
                    if (chh.TransportationHandler == null)
                    {
                        throw new LPGException("no transportation handler");
                    }

                    var sites = chh.TransportationHandler.CalcSites.Where(x => x.Locations.Contains(location)).ToList();
                    if (sites.Count == 0)
                    {
                        throw new DataIntegrityException("No calc site has the location " + location.Name + ". To make the transportation work, every site needs one location.");
                    }

                    if (sites.Count > 1)
                    {
                        throw new DataIntegrityException("More than one calc site has the location " + location.Name);
                    }

                    AffordanceBaseTransportDecorator abtd = new AffordanceBaseTransportDecorator(
                        aff, sites[0], chh.TransportationHandler, aff.Name,
                        chh.HouseholdKey, Guid.NewGuid().ToStrGuid(), _calcRepo);
                    location.AddTransportationAffordance(abtd);
                }
            }
        }
        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);
                }
            }
        }