Esempio n. 1
0
        //public override ICalcProfile CollectPersonProfile() => _personProfile;

        public override List <CalcSubAffordance> CollectSubAffordances(TimeStep time,
                                                                       bool onlyInterrupting,
                                                                       CalcLocation srcLocation)
        {
            if (SubAffordances.Count == 0)
            {
                return(new List <CalcSubAffordance>());
            }

            if (RemainingActiveTime(time) < 1)
            {
                return(new List <CalcSubAffordance>());
            }

            // es gibt subaffs und diese aff ist aktiv
            var result = new List <CalcSubAffordance>();

            foreach (var calcSubAffordance in SubAffordances)
            {
                if (onlyInterrupting && calcSubAffordance.IsInterrupting || !onlyInterrupting)
                {
                    var delaytimesteps   = calcSubAffordance.Delaytimesteps;
                    var hasbeenactivefor = HasBeenActiveFor(time);
                    var issubaffbusy     = calcSubAffordance.IsBusy(time, srcLocation, "name");
                    if (delaytimesteps < hasbeenactivefor && !issubaffbusy)
                    {
                        calcSubAffordance.SetDurations(RemainingActiveTime(time));
                        result.Add(calcSubAffordance);
                    }
                }
            }

            return(result);
        }
        public override void Activate(TimeStep startTime, string activatorName, CalcLocation personSourceLocation,
                                      out ICalcProfile personTimeProfile)
        {
            for (var i = 0; i < PersonProfileDuration && i + startTime.InternalStep < IsBusyArray.Length; i++)
            {
                IsBusyArray[i + startTime.InternalStep] = true;
            }
            foreach (var op in _variableOps)
            {
                // figure out end time
                TimeStep time;
                switch (op.ExecutionTime)
                {
                case VariableExecutionTime.Beginning:
                    time = startTime;
                    break;

                case VariableExecutionTime.EndOfPerson:
                case VariableExecutionTime.EndofDevices:
                    time = startTime.AddSteps(PersonProfileDuration);
                    break;

                default:
                    throw new LPGException("Forgotten Variable Execution Time");
                }
                _repository.AddExecutionEntry(op.Name, op.Value, op.CalcLocation, op.VariableAction, time, op.VariableGuid);
            }
            personTimeProfile = new CalcSubAffTimeProfile(_durations,
                                                          _durations + " timesteps Person profile");
        }
Esempio n. 3
0
        public void AddEntry([NotNull] string name, double value, [NotNull] CalcLocation location, VariableAction variableAction,
                             [NotNull] TimeStep timeStep, StrGuid variableGuid)
        {
            var ee = new ExecutionEntry(name, value, location, variableAction,
                                        timeStep, variableGuid);

            _entries.Add(ee);
        }
 public override bool IsBusy(TimeStep time, CalcLocation srcLocation, string calcPersonName,
                             bool clearDictionaries = true)
 {
     if (IsBusyArray[time.InternalStep])
     {
         return(true);
     }
     return(false);
 }
 public CalcAffordanceVariableOp([NotNull] string name, double value, [NotNull] CalcLocation location, VariableAction variableAction,
                                 VariableExecutionTime executionTime, StrGuid variableGuid)
 {
     Name           = name;
     Value          = value;
     CalcLocation   = location;
     VariableAction = variableAction;
     ExecutionTime  = executionTime;
     VariableGuid   = variableGuid;
 }
Esempio n. 6
0
 public ExecutionEntry([NotNull] string name, double value, [NotNull] CalcLocation location, VariableAction variableAction,
                       [NotNull] TimeStep timeStep, StrGuid variableGuid)
 {
     _variableGuid  = variableGuid;
     Name           = name;
     Value          = value;
     CalcLocation   = location;
     VariableAction = variableAction;
     TimeStep       = timeStep;
 }
 public CalcAutoDev([NotNull] CalcProfile pCalcProfile, [NotNull] CalcLoadType loadType,
                    [NotNull][ItemNotNull] List <CalcDeviceLoad> loads, double timeStandardDeviation,
                    double multiplier,
                    [NotNull] CalcLocation calclocation,
                    [NotNull][ItemNotNull] List <VariableRequirement> requirements, [NotNull] CalcDeviceDto autoDevDto, [NotNull] CalcRepo calcRepo)
     : base(
         loads, calclocation, autoDevDto, calcRepo)
 {
     _earliestNextStart     = new TimeStep(-1, 0, true);
     _calcProfile           = pCalcProfile;
     LoadType               = loadType;
     _timeStandardDeviation = timeStandardDeviation;
     _multiplier            = multiplier;
     _calcLocation          = calclocation;
     if (requirements.Count > 0) // initialize the whole variable thing
     {
         _requirements.AddRange(requirements);
     }
 }
Esempio n. 8
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
        }
 public CalcSubAffordance([NotNull] string pName, [NotNull] CalcLocation loc, [NotNull][ItemNotNull] List <CalcDesire> satisfactionvalues,
                          int miniumAge, int maximumAge, int delaytimesteps, PermittedGender permittedGender, [NotNull] string pAffCategory,
                          bool isInterruptable, bool isInterrupting, [NotNull] CalcAffordance parentAffordance,
                          [NotNull][ItemNotNull] List <CalcAffordanceVariableOp> variableOps, int weight,
                          [NotNull] string sourceTrait,
                          StrGuid guid, [ItemNotNull][NotNull] BitArray isBusy,
                          [NotNull] CalcVariableRepository repository, BodilyActivityLevel bodilyActivityLevel, [NotNull] CalcRepo calcRepo)
     : base(
         pName, loc, satisfactionvalues, miniumAge, maximumAge, permittedGender, false, false, pAffCategory,
         isInterruptable, isInterrupting, ActionAfterInterruption.GoBackToOld, weight, false,
         CalcAffordanceType.Subaffordance, guid, isBusy, bodilyActivityLevel, calcRepo)
 {
     Delaytimesteps   = delaytimesteps;
     _variableOps     = variableOps;
     _repository      = repository;
     SubAffordances   = new List <CalcSubAffordance>();
     Energyprofiles   = new List <CalcAffordance.DeviceEnergyProfileTuple>();
     AffordanceColor  = LPGColors.Black;
     SourceTrait      = sourceTrait;
     TimeLimitName    = null;
     ParentAffordance = parentAffordance;
 }
        public CalcDevice([NotNull][ItemNotNull] List <CalcDeviceLoad> powerUsage,
                          [NotNull] CalcLocation calcLocation,
                          [NotNull] CalcDeviceDto calcDeviceDto,
                          [NotNull] CalcRepo calcRepo) : base(calcDeviceDto.Name, calcDeviceDto.Guid)
        {
            _calcDeviceDto = calcDeviceDto;
            _calcRepo      = calcRepo;
            if (_calcDeviceDto.LocationGuid != calcLocation.Guid)
            {
                throw new LPGException("Inconsistent locations. This is a bug.");
            }
            _calcLocation = calcLocation;
            foreach (var load in powerUsage)
            {
                _deviceLoadsBy.Add(load.LoadType, load);
                Loads.Add(load);
            }

            /*foreach (var load in powerUsage) {
             *  if (Math.Abs(load.Value) < 0.0000001 && load.Name.ToLower(CultureInfo.InvariantCulture) != "none") {
             *      throw new LPGException("Trying to run the device " + calcDeviceDto.Name + " with a power load factor for " + load.LoadType.Name + " of 0. This is not going to work.");
             *  }
             * }*/
            if (calcRepo.CalcParameters.InternalTimesteps == 0)
            {
                throw new LPGException("Can't run with 0 timesteps");
            }
            _isBusyForLoadType = new Dictionary <CalcLoadType, BitArray>();
            foreach (var calcDeviceLoad in powerUsage)
            {
                _isBusyForLoadType.Add(calcDeviceLoad.LoadType,
                                       new BitArray(calcRepo.CalcParameters.InternalTimesteps));
                _isBusyForLoadType[calcDeviceLoad.LoadType].SetAll(false);
                //var key = new OefcKey(calcDeviceDto.HouseholdKey, calcDeviceDto.DeviceType,calcDeviceDto.Guid, calcDeviceDto.LocationGuid,calcDeviceLoad.LoadType.Guid, calcDeviceDto.DeviceCategoryName);
                var key = calcRepo.Odap.RegisterDevice(calcDeviceLoad.LoadType.ConvertToDto(), calcDeviceDto);
                _keyByLoad.Add(calcDeviceLoad.LoadType, key);
            }
        }
Esempio n. 11
0
        public override void Activate(TimeStep startTime,
                                      string activatorName,
                                      CalcLocation personSourceLocation,
                                      out ICalcProfile personTimeProfile)
        {
            TimeStep timeLastDeviceEnds = startTime.GetAbsoluteStep(0);

            foreach (var dpt in Energyprofiles)
            {
                if (dpt.Probability > _probabilitiesForTimes[startTime.InternalStep])
                {
                    //_calcDevice.SetTimeprofile(tbp, startidx + TimeOffsetInSteps, loadType, timeFactor, affordancename,activatorName, _multiplier);
                    CalcProfile adjustedProfile = dpt.TimeProfile.CompressExpandDoubleArray(_timeFactorsForTimes[startTime.InternalStep]);
                    var         endtime         = dpt.CalcDevice.SetTimeprofile(adjustedProfile,
                                                                                startTime.AddSteps(dpt.TimeOffsetInSteps),
                                                                                dpt.LoadType,
                                                                                Name,
                                                                                activatorName,
                                                                                dpt.Multiplier,
                                                                                false);
                    if (endtime > timeLastDeviceEnds)
                    {
                        timeLastDeviceEnds = endtime;
                    }
                }
            }

            var personsteps = CalcProfile.GetNewLengthAfterCompressExpand(_personProfile.StepValues.Count,
                                                                          _timeFactorsForTimes[startTime.InternalStep]);

            _startTimeStep = startTime;
            _endTimeStep   = startTime.AddSteps(personsteps);
            if (DoubleCheckBusyArray)
            {
                for (var i = 0; i < personsteps && i + startTime.InternalStep < CalcRepo.CalcParameters.InternalTimesteps; i++)
                {
                    if (IsBusyArray[i + startTime.InternalStep])
                    {
                        throw new LPGException("Affordance was already busy");
                    }
                }
            }

            for (var i = 0; i < personsteps && i + startTime.InternalStep < CalcRepo.CalcParameters.InternalTimesteps; i++)
            {
                IsBusyArray[i + startTime.InternalStep] = true;
            }

            if (_variableOps.Count > 0)
            {
                foreach (var op in _variableOps)
                {
                    // figure out end time
                    TimeStep time;
                    switch (op.ExecutionTime)
                    {
                    case VariableExecutionTime.Beginning:
                        time = startTime;
                        break;

                    case VariableExecutionTime.EndOfPerson:
                        time = _endTimeStep;
                        break;

                    case VariableExecutionTime.EndofDevices:
                        time = timeLastDeviceEnds;
                        break;

                    default:
                        throw new LPGException("Forgotten Variable Execution Time");
                    }

                    _variableRepository.AddExecutionEntry(op.Name, op.Value, op.CalcLocation,
                                                          op.VariableAction, time, op.VariableGuid);
                    _variableRepository.Execute(startTime);
                }
            }

            double tf = _timeFactorsForTimes[startTime.InternalStep];

            _probabilitiesForTimes.Clear();
            _timeFactorsForTimes.Clear();
            personTimeProfile = _personProfile.CompressExpandDoubleArray(tf);
            //return tf ;
        }
        //private static VacationAffordance _vacationAffordance;

        /* public VacationAffordance Get()
         * {
         *  if (_vacationAffordance == null) {
         *      _vacationAffordance = new VacationAffordance(_calcParameters);
         *  }
         *  return _vacationAffordance;
         * }*/

        public override void Activate(TimeStep startTime, string activatorName,
                                      CalcLocation personSourceLocation,
                                      out ICalcProfile personTimeProfile) =>
        throw new LPGException("This function should never be called");
 public override List <CalcSubAffordance> CollectSubAffordances(TimeStep time,
                                                                bool onlyInterrupting,
                                                                CalcLocation srcLocation) => throw new NotImplementedException();
 public override List <CalcSubAffordance> CollectSubAffordances(TimeStep time,
                                                                bool onlyInterrupting,
                                                                CalcLocation srcLocation) =>
 new List <CalcSubAffordance>();
        //public override ICalcProfile CollectPersonProfile() => throw new LPGException("This function should never be called");

        public override bool IsBusy(TimeStep time,
                                    CalcLocation srcLocation, string calcPersonName,
                                    bool clearDictionaries = true) =>
        throw new LPGException("This function should never be called");
 public void AddExecutionEntry([NotNull] string name, double value, [NotNull] CalcLocation location, VariableAction variableAction,
                               [NotNull] TimeStep timeStep, StrGuid variableGuid)
 {
     _variableOperator.AddEntry(name, value, location, variableAction,
                                timeStep, variableGuid);
 }
Esempio n. 17
0
        public CalcAffordance([NotNull] string pName,
                              [NotNull] CalcProfile personProfile,
                              [NotNull] CalcLocation loc,
                              bool randomEffect,
                              [NotNull][ItemNotNull] List <CalcDesire> satisfactionvalues,
                              int miniumAge,
                              int maximumAge,
                              PermittedGender permittedGender,
                              bool needsLight,
                              double timeStandardDeviation,
                              ColorRGB affordanceColor,
                              [NotNull] string pAffCategory,
                              bool isInterruptable,
                              bool isInterrupting,
                              [NotNull][ItemNotNull] List <CalcAffordanceVariableOp> variableOps,
                              [NotNull][ItemNotNull] List <VariableRequirement> variableRequirements,
                              ActionAfterInterruption actionAfterInterruption,
                              [NotNull] string timeLimitName,
                              int weight,
                              bool requireAllDesires,
                              [NotNull] string srcTrait,
                              StrGuid guid,
                              [NotNull] CalcVariableRepository variableRepository,
                              [NotNull][ItemNotNull] List <DeviceEnergyProfileTuple> energyprofiles,
                              [ItemNotNull][NotNull] BitArray isBusy, BodilyActivityLevel bodilyActivityLevel,
                              [NotNull] CalcRepo calcRepo) : base(pName,
                                                                  loc,
                                                                  satisfactionvalues,
                                                                  miniumAge,
                                                                  maximumAge,
                                                                  permittedGender,
                                                                  needsLight,
                                                                  randomEffect,
                                                                  pAffCategory,
                                                                  isInterruptable,
                                                                  isInterrupting,
                                                                  actionAfterInterruption,
                                                                  weight,
                                                                  requireAllDesires,
                                                                  CalcAffordanceType.Affordance,
                                                                  guid,
                                                                  isBusy, bodilyActivityLevel, calcRepo)
        {
            _variableOps          = variableOps;
            _variableRequirements = variableRequirements;
            _variableRepository   = variableRepository;
            Energyprofiles        = energyprofiles;
            SourceTrait           = srcTrait;
            if (personProfile == null)
            {
#pragma warning disable IDE0016 // Use 'throw' expression
                throw new DataIntegrityException("The affordance " + Name + " has no person profile!");
#pragma warning restore IDE0016 // Use 'throw' expression
            }

            _timeStandardDeviation = timeStandardDeviation;
            SubAffordances         = new List <CalcSubAffordance>();
            _personProfile         = personProfile;
            AffordanceColor        = affordanceColor;
            TimeLimitName          = timeLimitName;
        }
Esempio n. 18
0
        public override bool IsBusy(TimeStep time,
                                    CalcLocation srcLocation,
                                    string calcPersonName,
                                    bool clearDictionaries = true)
        {
            if (!_timeFactorsForTimes.ContainsKey(time.InternalStep))
            {
                if (clearDictionaries)
                {
                    //        _timeFactorsForTimes.Clear();
                }

                _timeFactorsForTimes[time.InternalStep] = CalcRepo.NormalRandom.NextDouble(1, _timeStandardDeviation);
                if (_timeFactorsForTimes[time.InternalStep] < 0)
                {
                    throw new DataIntegrityException("The duration standard deviation on " + Name + " is too large: a negative value of " +
                                                     _timeFactorsForTimes[time.InternalStep] + " came up. The standard deviation is " +
                                                     _timeStandardDeviation);
                }
            }

            if (!_probabilitiesForTimes.ContainsKey(time.InternalStep))
            {
                if (clearDictionaries)
                {
                    //      _probabilitiesForTimes.Clear();
                }

                _probabilitiesForTimes[time.InternalStep] = CalcRepo.Rnd.NextDouble();
            }

            if (_variableRequirements.Count > 0)
            {
                foreach (var requirement in _variableRequirements)
                {
                    if (!requirement.IsMet())
                    {
                        return(true); // return is busy right now and not available.
                    }
                }
            }

            if (time.InternalStep >= IsBusyArray.Length)
            {
                return(false);
            }

            if (IsBusyArray[time.InternalStep])
            {
                return(true);
            }

            foreach (var dpt in Energyprofiles)
            {
                if (dpt.Probability > _probabilitiesForTimes[time.InternalStep])
                {
                    if (dpt.CalcDevice.IsBusyDuringTimespan(time.AddSteps(dpt.TimeOffsetInSteps),
                                                            dpt.TimeProfile.StepValues.Count,
                                                            _timeFactorsForTimes[time.InternalStep],
                                                            dpt.LoadType))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 19
0
 public abstract void Activate(TimeStep startTime, string activatorName,
                               CalcLocation personSourceLocation,
                               out ICalcProfile personTimeProfile);
Esempio n. 20
0
 public abstract List <CalcSubAffordance> CollectSubAffordances(TimeStep time,
                                                                bool onlyInterrupting,
                                                                CalcLocation srcLocation);
Esempio n. 21
0
 public abstract bool IsBusy(TimeStep time,
                             CalcLocation srcLocation, string calcPersonName,
                             bool clearDictionaries = true);