public bool IsBusyDuringTimespan([NotNull] TimeStep startidx, int duration, double timefactor, [NotNull] CalcLoadType lt)
        {
            var dstduration = CalcProfile.GetNewLengthAfterCompressExpand(duration, timefactor);
            var lastbit     = startidx.InternalStep + dstduration;

            for (var i = startidx.InternalStep; i < lastbit && i < _isBusyForLoadType[lt].Length; i++)
            {
                if (_isBusyForLoadType[lt][i])
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
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 ;
        }