public void PickRandomAffordanceFromEquallyAttractiveOnesTest()
        {
            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) {
                CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults();
                calcParameters.AffordanceRepetitionCount = 0;
                wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
                wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
                using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger)) {
                    fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null);
                    //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory);
                    //DateStampCreator dsc = new DateStampCreator(calcParameters);
                    Random rnd = new Random();
                    //OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters);
                    using (var lf = new LogFile(calcParameters, fft)) {
                        CalcProfile            cp  = new CalcProfile("cp1", Guid.NewGuid().ToStrGuid(), TimeSpan.FromMinutes(1), ProfileType.Absolute, "bla");
                        CalcVariableRepository crv = new CalcVariableRepository();
                        BitArray isBusy            = new BitArray(calcParameters.InternalTimesteps, false);
                        using CalcRepo calcRepo = new CalcRepo(lf: lf, calcParameters: calcParameters, rnd: rnd);
                        CalcAffordance aff1 = new CalcAffordance("aff1", cp, null, false, new List <CalcDesire>(), 10, 20, PermittedGender.All, true,
                                                                 1, LPGColors.AliceBlue, null, false, false, null, null, ActionAfterInterruption.GoBackToOld, "", 900, false, "",
                                                                 Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low,
                                                                 calcRepo);
                        CalcAffordance aff2 = new CalcAffordance("aff2", cp, null, false, new List <CalcDesire>(), 10, 20, PermittedGender.All, true,
                                                                 1, LPGColors.AliceBlue, null, false, false, null, null, ActionAfterInterruption.GoBackToOld, "", 100, false, "",
                                                                 Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low,
                                                                 calcRepo);

                        List <ICalcAffordanceBase> affs = new List <ICalcAffordanceBase> {
                            aff1,
                            aff2
                        };
                        int           aff1C        = 0;
                        int           aff2C        = 0;
                        BitArray      isSick       = new BitArray(calcParameters.InternalTimesteps);
                        BitArray      isOnVacation = new BitArray(calcParameters.InternalTimesteps);
                        CalcPersonDto calcPerson   = CalcPersonDto.MakeExamplePerson();
                        CalcPerson    cperson      = new CalcPerson(calcPerson, null, isSick, isOnVacation, calcRepo);
                        TimeStep      ts           = new TimeStep(1, 0, true);
                        for (int i = 0; i < 1000; i++)
                        {
                            ICalcAffordanceBase cab = cperson.PickRandomAffordanceFromEquallyAttractiveOnes(affs, ts, null, new HouseholdKey("bla"));
                            if (cab == aff1)
                            {
                                aff1C++;
                            }

                            if (cab == aff2)
                            {
                                aff2C++;
                            }
                        }

                        aff1C.Should().BeApproximatelyWithinPercent(900, 0.1);
                        Logger.Info("Number of selections for 90%:" + aff1C + ", 10%:" + aff2C);
                    }
                }
                wd.CleanUp();
            }
        }
 public bool HasAtLeastOneDesireBelowThreshold([NotNull] ICalcAffordanceBase aff)
 {
     foreach (var desire in aff.Satisfactionvalues)
     {
         if (Desires.ContainsKey(desire.DesireID))
         {
             if (Desires[desire.DesireID].Value < Desires[desire.DesireID].Threshold)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 //[CanBeNull]
 //private CalcAffordanceBase _MainAffordance;
 public AffordanceBaseTransportDecorator([NotNull] ICalcAffordanceBase sourceAffordance,
                                         [NotNull] CalcSite site, [NotNull] TransportationHandler transportationHandler,
                                         [NotNull] string name, [NotNull] HouseholdKey householdkey,
                                         StrGuid guid, CalcRepo calcRepo)
     : base(name, guid)
 {
     if (!site.Locations.Contains(sourceAffordance.ParentLocation))
     {
         throw new LPGException("Wrong site. Bug. Please report.");
     }
     _householdkey = householdkey;
     _calcRepo     = calcRepo;
     _calcRepo.OnlineLoggingData.AddTransportationStatus(new TransportationStatus(new TimeStep(0, 0, false), householdkey, "Initializing affordance base transport decorator for " + name));
     Site = site;
     _transportationHandler = transportationHandler;
     _sourceAffordance      = sourceAffordance;
 }
Exemplo n.º 4
0
        public static void CheckConsistency([NotNull] CalcHousehold chh, [NotNull] CalcParameters calcParameters)
        {
            CheckTimeResolution(calcParameters);
            // check for the same device twice
            foreach (CalcLocation location in chh.Locations)
            {
                foreach (var calcAffordanceBase in location.Affordances)
                {
                    ICalcAffordanceBase affordance = calcAffordanceBase;
                    if (affordance.AreThereDuplicateEnergyProfiles())
                    {
                        throw new DataIntegrityException(
                                  "Same device twice in one Affordance: " + location.Name + " - " + affordance.Name);
                    }
                }
            }

            // check for timeprofiles without values
            foreach (CalcLocation calcLocation in chh.Locations)
            {
                foreach (var calcAffordanceBase in calcLocation.Affordances)
                {
                    ICalcAffordanceBase calcAffordance = calcAffordanceBase;
                    if (calcAffordance.AreDeviceProfilesEmpty() != null)
                    {
                        throw new DataIntegrityException("Timeprofile without values: " +
                                                         calcAffordance.AreDeviceProfilesEmpty());
                    }
                }
            }

            // persons  without desires
            foreach (CalcPerson calcPerson in chh.Persons)
            {
                if (calcPerson.DesireCount == 0)
                {
                    throw new DataIntegrityException("Person without desires: " + calcPerson.Name);
                }
            }

            if (calcParameters.InternalStepsize.TotalSeconds < 1)
            {
                throw new DataIntegrityException("Time resolution too small!");
            }
        }