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");
        }
Beispiel #2
0
 public void AppendProfile([NotNull] ICalcProfile sourcePersonProfile)
 {
     StepValues.AddRange(sourcePersonProfile.StepValues);
 }
Beispiel #3
0
        //BitArray ICalcAffordanceBase.IsBusyArray { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

        public void Activate(TimeStep startTime, string activatorName, CalcLocation personSourceLocation,
                             out ICalcProfile personTimeProfile)
        {
            if (_myLastTimeEntry.TimeOfLastEvalulation != startTime)
            {
                throw new LPGException("trying to activate without first checking if the affordance is busy is a bug. Please report.");
            }

            CalcTravelRoute route         = _myLastTimeEntry.PreviouslySelectedRoutes[personSourceLocation];
            int             routeduration = route.Activate(startTime, activatorName, out var usedDevices);

            if (routeduration == 0)
            {
                _calcRepo.OnlineLoggingData.AddTransportationStatus(
                    new TransportationStatus(startTime, _householdkey,
                                             "\tActivating " + Name + " at " + startTime + " with no transportation and moving from " + personSourceLocation + " to " + _sourceAffordance.ParentLocation.Name + " for affordance " + _sourceAffordance.Name));
            }
            else
            {
                _calcRepo.OnlineLoggingData.AddTransportationStatus(new TransportationStatus(
                                                                        startTime,
                                                                        _householdkey,
                                                                        "\tActivating " + Name + " at " + startTime + " with a transportation duration of " + routeduration + " for moving from " + personSourceLocation + " to " + _sourceAffordance.ParentLocation.Name));
            }

            TimeStep affordanceStartTime = startTime.AddSteps(routeduration);

            if (affordanceStartTime.InternalStep < _calcRepo.CalcParameters.InternalTimesteps)
            {
                _sourceAffordance.Activate(affordanceStartTime, activatorName, personSourceLocation,
                                           out var sourcePersonProfile);
                CalcProfile newPersonProfile = new CalcProfile(
                    "Travel Profile for Route " + route.Name + " to affordance " + _sourceAffordance.Name,
                    System.Guid.NewGuid().ToStrGuid(),
                    CalcProfile.MakeListwithValue1AndCustomDuration(routeduration), ProfileType.Absolute,
                    sourcePersonProfile.DataSource);
                newPersonProfile.AppendProfile(sourcePersonProfile);
                personTimeProfile = newPersonProfile;
                string usedDeviceNames = String.Join(", ", usedDevices.Select(x => x.Device.Name + "(" + x.DurationInSteps + ")"));
                _calcRepo.OnlineLoggingData.AddTransportationEvent(_householdkey, activatorName, startTime, personSourceLocation.CalcSite?.Name ?? "",
                                                                   Site.Name,
                                                                   route.Name, usedDeviceNames, routeduration, sourcePersonProfile.StepValues.Count,
                                                                   _sourceAffordance.Name, usedDevices);
            }
            else
            {
                //this is if the simulation ends during a transport
                CalcProfile newPersonProfile = new CalcProfile(
                    "Travel Profile for Route " + route.Name + " to affordance " + _sourceAffordance.Name,
                    System.Guid.NewGuid().ToStrGuid(),
                    CalcProfile.MakeListwithValue1AndCustomDuration(routeduration), ProfileType.Absolute,
                    _sourceAffordance.Name);
                personTimeProfile = newPersonProfile;
                string usedDeviceNames = String.Join(", ", usedDevices.Select(x => x.Device.Name + "(" + x.DurationInSteps + ")"));
                _calcRepo.OnlineLoggingData.AddTransportationEvent(_householdkey, activatorName, startTime,
                                                                   personSourceLocation.CalcSite?.Name ?? "",
                                                                   Site.Name,
                                                                   route.Name, usedDeviceNames, routeduration, newPersonProfile.StepValues.Count,
                                                                   _sourceAffordance.Name, usedDevices);
            }
        }
Beispiel #4
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 ;
        }
Beispiel #5
0
 public abstract void Activate(TimeStep startTime, string activatorName,
                               CalcLocation personSourceLocation,
                               out ICalcProfile personTimeProfile);
        //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");