}        //End TestPriority ( )

        /// <summary>
        /// Tests the methods.
        /// </summary>
        public static void TestMethodPriority( )
        {
            PriorityQueue <int, Event> test = new PriorityQueue <int, Event> ( );
            Random random = new Random( );
            PriorityQueue <int, Event> Events = new PriorityQueue <int, Event> ( );
            DateTime TimeNow = new DateTime(DateTime.Today.Year,
                                            DateTime.Today.Month,
                                            DateTime.Today.Day,
                                            8, 0, 0);
            DateTime TimeStop = new DateTime(DateTime.Today.Year,
                                             DateTime.Today.Month,
                                             DateTime.Today.Day,
                                             18, 0, 0);
            List <Registrant> list = new List <Registrant> ( );
            TimeSpan          time;
            Event             evntTemp;
            Exponential       exp = new Exponential(4.5);

            for (int i = 0; i < 100; i++)
            {
                Registrant temp = new Registrant(random.Next(1, 9999), (Math.Log(1 - random.NextDouble( )) * (-4.5) + 1.5));
                Console.WriteLine("Id: " + temp.Id);
                Console.WriteLine("Time: " + temp.RegisterTime);
                int nextInt = random.Next(10 * 60);
                time = new TimeSpan(0, nextInt, 0);
                DateTime priority = TimeNow.Add(time);
                Console.WriteLine("Priority: " + nextInt);
                evntTemp = new Event(EVENT.ENTER, priority, temp.Id);
                Console.WriteLine("Event: " + evntTemp.Time);
                Events.Enqueue(nextInt, evntTemp);
                temp.Event = evntTemp;
                list.Add(temp);
            }            //end for loop
            foreach (var item in Events)
            {
                Console.WriteLine(Events.Peek( ));
                Events.Dequeue( );
            }    //End foreach statement
        }        //End TestMethodPriority ( )
示例#2
0
        }        //End ConventionRegistration

        /// <summary>
        /// Initializes a new instance of the <see cref="ConventionRegistration"/> class.
        /// </summary>
        /// <param name="windows">The windows.</param>
        /// <param name="distribution">The distribution.</param>
        public ConventionRegistration(List <Window> windows, double distribution, double average)
        {
            TimeNow = new DateTime(DateTime.Today.Year,
                                   DateTime.Today.Month,
                                   DateTime.Today.Day,
                                   8, 0, 0);
            list    = new List <Registrant> ( );
            Events  = new PriorityQueue <int, Event> ( );
            Windows = windows;
            int Poisson = Creation.Next(distribution);

            //Creates all enter events
            for (int i = 0; i < distribution; i++)
            {
                Registrant temp     = new Registrant(random.Next(1, 9999), (1.5 + Creation.NegExp(average - 1.5)));
                int        nextInt  = random.Next(10 * 60);
                TimeSpan   time     = new TimeSpan(0, nextInt, 0);
                DateTime   priority = TimeNow.Add(time);
                temp.Event = new Event(EVENT.ENTER, priority, temp.Id);
                list.Add(temp);
                Events.Enqueue(nextInt, temp.getEvents(EVENT.ENTER));
            }            //end for loop
            //Display Console Screen
            Console.WriteLine(ToStringConsole(windows));
            Thread.Sleep(500);

            //Set Max to zero
            Min = 0;
            Max = 1;
            //Runs until no event are present
            do
            {
                //Sets the new time
                runevent = new TimeSpan(0, Counter, 0);
                TimeNew  = TimeNow.Add(runevent);
                //Check for Min, Max, and Departure times
                for (int i = 0; i < Windows.Count; i++)
                {
                    if (Windows [i].SizeOfLine( ) != 0)
                    {
                        if (Windows [i].HeadLine( ).Departure.Year == 0001)
                        {
                            int counter = (int)Windows [i].HeadLine( ).RegisterTime * 60;
                            runevent   = new TimeSpan(0, 0, counter);
                            TimeDepart = TimeNew.Add(runevent);
                            Registrant tempRegistrant = Windows [i].HeadLine( );
                            int        position       = list.IndexOf(tempRegistrant);
                            tempRegistrant       = list [position];
                            tempRegistrant.Event = new Event(EVENT.LEAVE, TimeDepart, tempRegistrant.Id);
                            Events.Enqueue(counter / 60 + Counter, tempRegistrant.getEvents(EVENT.LEAVE));
                        }        //End if statement
                    }//End if statement
                }                //End for loop
                                 //Check for event to the time
                while (Events.Peek( ).Time <= TimeNew)
                {
                    //Grab Registrant
                    Event      TempEvent      = Events.Peek( );
                    Registrant tempRegistrant = new Registrant(TempEvent.Register);
                    int        position       = list.IndexOf(tempRegistrant);
                    tempRegistrant = list [position];
                    LineCounts(windows);
                    //Check if the event was to enter or leave
                    if (TempEvent.Type == EVENT.ENTER)
                    {
                        Arrivals++;
                        Events.Dequeue( );
                        Windows [Min].AddLine(tempRegistrant);
                    }                    //End if statement
                    else if (TempEvent.Type == EVENT.LEAVE)
                    {
                        for (int i = 0; i < Windows.Count; i++)
                        {
                            if (Windows [i].SizeOfLine( ) != 0)
                            {
                                if (tempRegistrant == Windows [i].HeadLine( ))
                                {
                                    windows [i].RemoveLine( );
                                    Events.Dequeue( );

                                    Departures++;
                                } //End if statement
                            }     //End if statement
                        }
                    }             //End if statement
                }                 //End while statement

                //Increase Time
                Counter++;
                Console.WriteLine(ToStringConsole(windows));
                Thread.Sleep(210);
            } while (Arrivals - Departures != 0 && Arrivals > 0); //End do-while loop
        }                                                         //End ConventionRegistration (List<Window>, double)
示例#3
0
 /// <summary>
 /// Adds a registrant to the line
 /// </summary>
 /// <param name="reg">The registrant to be added</param>
 public void Enqueue(Registrant reg)
 {
     Registrants.Enqueue(reg);
     Count++;
 }
        }        //End Window ( )

        #endregion

        #region Methods

        /// <summary>
        /// Adds the line.
        /// </summary>
        /// <param name="register">The register.</param>
        public void AddLine(Registrant register)
        {
            Line.Enqueue(register);
        }        //End AddLine (Registrant
示例#5
0
 /// <summary>
 /// Parameterized constructor
 /// </summary>
 /// <param name="type">EventType</param>
 /// <param name="time">DateTime</param>
 /// <param name="registrant">Registrant</param>
 public Event(EventType type, DateTime time, Registrant registrant)
 {
     Time   = time;
     Type   = type;
     Person = registrant;
 }