Ejemplo n.º 1
0
        internal static void LoadTimePeriodData()
        {
            TimeSlices = new TimePeriodSlice[5];

            //start of day to 5:59
            TimeSlices[0] = new TimePeriodSlice(0,
                                                Time.StartOfDay,
                                                new Time("6:00:00"));

            //6:00 to 8:59
            TimeSlices[1] = new TimePeriodSlice(1, new Time("6:00:00"),
                                                new Time("9:00:00"));

            //9:00 to 14:59
            TimeSlices[2] = new TimePeriodSlice(2,
                                                new Time("9:00:00"), new Time("15:00:00"));

            //15:00 to 18:59
            TimeSlices[3] = new TimePeriodSlice(3,
                                                new Time("15:00:00"), new Time("19:00:00"));

            //19:00 to end of day
            TimeSlices[4] = new TimePeriodSlice(0,
                                                new Time("19:00:00"), Distribution.DistributionToTimeOfDay(Scheduler.StartTimeQuanta));
        }
Ejemplo n.º 2
0
        public static bool GetRandomStartTimeFrequency(int distribution, int freq, int min, int max, Random random, out Time startTime)
        {
            float[][] pdf = Distributions[distribution].StartTimeFrequency;

            if (min >= max)
            {
                startTime = Distribution.DistributionToTimeOfDay(max);
                return(true);
            }

            double rand      = random.NextDouble();
            float  pdfFactor = 0.0f;

            for (int i = min; i < max; ++i)
            {
                pdfFactor += pdf[i][freq];
            }

            if (pdfFactor == 0)
            {
                startTime = Time.Zero;
                return(false);
            }
            rand *= pdfFactor;
            float cdf = 0.0f;

            for (int i = min; i < max; i++)
            {
                cdf += pdf[i][freq];

                if (rand < cdf)
                {
                    startTime = Distribution.DistributionToTimeOfDay(i);
                    if (startTime == Time.Zero)
                    {
                        throw new XTMFRuntimeException("Tried to create an episode that starts at time 0!");
                    }
                    return(true);
                }
            }
            // if we get here, it was the last one but off due to rounding errors
            startTime = Distribution.DistributionToTimeOfDay(max);
            return(true);
        }