/*        private static int BusyEntryComparer(BusyEntry e1, BusyEntry e2)
 *      {
 *          int result = e1.Start.CompareTo(e2.Start);
 *          if (result != 0)
 *              return result;
 *          return e1.End.CompareTo(e2.End);
 *      }*/

        private void SetBusy([NotNull] TimeStep startIndex, int duration, [NotNull] CalcLoadType loadType, bool activateDespiteBeingBusy)
        {
            /*if (UseRanges)
             * {
             *  BusyEntry be = new BusyEntry(startidx, startidx + duration - 1);
             *  _busyEntries.Add(be);
             *  _busyEntries.Sort(BusyEntryComparer);
             * }*/
            // if (Name == "Cell Phone Samsung Charging") {Logger.Info("Setting Busy at " + startIndex + " for a duration of " + duration + " until " +(startIndex + duration));}
            var endidx = Math.Min(startIndex.InternalStep + duration, _isBusyForLoadType[loadType].Length);

            for (var i = startIndex.InternalStep; i < endidx; i++)
            {
                // if (!UseRanges)
                //   _isBusy.Set(startidx + i, true);
                if (!activateDespiteBeingBusy && _isBusyForLoadType[loadType][i])
                {
                    throw new LPGException("The device " + Name +
                                           " was somehow activated, even though it was already active." +
                                           " This points towards something being quite wrong. Timestep: " +
                                           i);
                }
                _isBusyForLoadType[loadType].Set(i, true);
            }
        }
 //function only used for testing
 public void SetIsBusyForTesting([NotNull] TimeStep i, bool value, [NotNull] CalcLoadType lt)
 {
     _isBusyForLoadType[lt][i.InternalStep] = value;
     foreach (var pair in _isBusyForLoadType)
     {
         pair.Value[i.InternalStep] = value;
     }
 }
Exemple #3
0
 public CalcDeviceLoad([NotNull] string pName, double value, [NotNull] CalcLoadType loadType,
                       double averageYearlyConsumption, double powerStandardDeviation) : base(pName, StrGuid.Empty)
 {
     Value = value;
     //if (Math.Abs(value) < 0.000001 && loadType.Name.ToLower(CultureInfo.InvariantCulture) != "none") {
     //    throw new LPGException("Trying to initialize a calc device load with a max power of 0.");
     //}
     LoadType = loadType;
     AverageYearlyConsumption = averageYearlyConsumption;
     PowerStandardDeviation   = powerStandardDeviation;
 }
 //for the device factories
 public void ApplyBitArry([NotNull][ItemNotNull] BitArray br, [NotNull] CalcLoadType lt)
 {
     if (br.Length != _isBusyForLoadType[lt].Length)
     {
         throw new LPGException("Bitarry Length was not equal to BusyArrayLength. Please Report.");
     }
     for (var i = 0; i < br.Length; i++)
     {
         _isBusyForLoadType[lt][i] = br[i];
     }
 }
        public TimeStep SetTimeprofile([NotNull] TimeStep startidx, [NotNull] CalcLoadType loadType,
                                       [NotNull] string affordanceName, [NotNull] string activatingPersonName,
                                       bool activateDespiteBeingBusy, [NotNull] StepValues stepValues)
        {
            if (stepValues.Values.Count == 0)
            {
                throw new LPGException("Trying to set empty device profile. This is a bug. Please report.");
            }

            CalcDeviceLoad cdl = _deviceLoadsBy[loadType];

            if (cdl == null)
            {
                throw new LPGException("It was tried to activate the loadtype " + loadType.Name +
                                       " even though that one is not set for the device " + Name);
            }

            /*if (Math.Abs(cdl.Value) < 0.00000001 ) {
             *  throw new LPGException("Trying to calculate with a power consumption factor of 0. This is wrong.");
             * }*/
            if (CalcRepo.Odap == null && !Config.IsInUnitTesting)
            {
                throw new LPGException("ODAP was null. Please report");
            }
            var totalDuration = stepValues.Values.Count; //.GetNewLengthAfterCompressExpand(timefactor);
            //calcProfile.CompressExpandDoubleArray(timefactor,allProfiles),
            var key = _keyByLoad[cdl.LoadType];

            CalcRepo.Odap.AddNewStateMachine(
                startidx,
                cdl.LoadType.ConvertToDto(),
                affordanceName,
                activatingPersonName,
                key,
                _calcDeviceDto, stepValues);

            if (MatchingAutoDevs.Count > 0)
            {
                foreach (CalcAutoDev matchingAutoDev in MatchingAutoDevs)
                {
                    if (matchingAutoDev._keyByLoad.ContainsKey(cdl.LoadType))
                    {
                        var zerokey = matchingAutoDev._keyByLoad[cdl.LoadType];
                        CalcRepo.Odap.AddZeroEntryForAutoDev(zerokey,
                                                             startidx,
                                                             totalDuration);
                    }
                }
            }
            SetBusy(startidx, totalDuration, loadType, activateDespiteBeingBusy);
            return(startidx.AddSteps(totalDuration));
        }
Exemple #6
0
        public void AddDeviceTuple([NotNull] CalcDevice dev,
                                   [NotNull] CalcProfile newprof,
                                   [NotNull] CalcLoadType lt,
                                   decimal timeoffset,
                                   TimeSpan internalstepsize,
                                   double multiplier,
                                   double probability)
        {
            //TODO: remove this, it is only used in unit testing
            var calctup = new DeviceEnergyProfileTuple(dev, newprof, lt, timeoffset, internalstepsize, multiplier, probability);

            Energyprofiles.Add(calctup);
        }
Exemple #7
0
            public DeviceEnergyProfileTuple([NotNull] CalcDevice pdev,
                                            [NotNull] CalcProfile ep,
                                            [NotNull] CalcLoadType pLoadType,
                                            decimal timeOffset,
                                            TimeSpan stepsize,
                                            double multiplier,
                                            double probability)
            {
                _calcDevice = pdev;
                TimeProfile = ep;
                LoadType    = pLoadType;
                TimeOffset  = timeOffset;
                _multiplier = multiplier;
                var minutesperstep = (decimal)stepsize.TotalMinutes;

                TimeOffsetInSteps = (int)(timeOffset / minutesperstep);
                Probability       = probability;
            }
 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);
     }
 }
        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);
        }
 public bool GetIsBusyForTesting([NotNull] TimeStep i, [NotNull] CalcLoadType lt) => _isBusyForLoadType[lt][i.InternalStep];