public void InstantSimButton_Click(object sender, EventArgs e)
 {
     UpdateSentValues();
     if (CheckValues())
     {
         patients = new PatientQueue(numRooms, ref rnd);
         InstantSimulation(ref (patients));
     }
 }
        void InstantSimulation(ref PatientQueue patients)
        {
            float shift     = 0;
            float shiftOver = 0;
            float incrament;
            int   numPatients = 0;
            int   openRooms   = 0;
            int   rating1     = 0;
            int   rating2     = 0;
            int   rating3     = 0;
            int   rating4     = 0;
            float stopper     = 0;

            instantSimNum++;
            //int counter =0;

            //Pregenerate patients
            for (float j = 0; j <= shiftLen * 60;)
            {
                //Create new patient
                numPatients++;
                patients.AddPatient(ref (severityRatings), ref (roomTimes), ref (waitDelays));
                j += patients.GetPatient(numPatients).GetDelayTime();
                patients.GetPatient(numPatients).SetArrivalTime((int)j);
            }

            shift  += patients.GetPatient(1).GetArrivalTime();
            stopper = patients.GetPatient(patients.GetSize()).GetArrivalTime();
            //System.Diagnostics.Debug.WriteLine("Stopper: " + stopper);

            //Run Shift
            while (shift <= shiftLen * 60)
            {
                //counter++;
                //System.Diagnostics.Debug.WriteLine(counter);
                incrament = 100000;
                //if not null -> if arrived -> if smaller than current room time
                for (int z = 1; z <= numRooms; z++)
                {
                    /*System.Diagnostics.Debug.Write("Arive Time");
                     * System.Diagnostics.Debug.WriteLine(patients.GetPatient(z).GetArrivalTime());
                     * System.Diagnostics.Debug.Write("current Time");
                     * System.Diagnostics.Debug.WriteLine(shift);*/
                    if (patients.GetPatient(z) != null)
                    {
                        if (patients.GetPatient(z).roomTimeManip < incrament && patients.GetPatient(z).GetArrivalTime() <= shift)
                        {
                            incrament = patients.GetPatient(z).roomTimeManip;
                        }
                        if (patients.GetPatient(z).GetArrivalTime() < incrament + shift && patients.GetPatient(z).GetArrivalTime() > shift)
                        {
                            incrament = patients.GetPatient(z).GetArrivalTime() - shift;
                        }
                    }
                }

                for (int i = 1; i <= numRooms; i++)
                {
                    if (patients.GetPatient(i) != null)
                    {
                        if (patients.GetPatient(i).GetArrivalTime() <= shift)
                        {
                            patients.GetPatient(i).roomTimeManip -= incrament;

                            //Creates inacuracies if value is less than zero as that is not propogated forward
                            if (patients.GetPatient(i).roomTimeManip == 0)
                            {
                                patients.RemovePatient(i, shift + incrament);
                            }
                        }
                    }
                }
                //System.Diagnostics.Debug.WriteLine(shift);
                //Resort Queue
                patients.SortQueue((int)shift);
                shift += incrament;
            }
            for (int i = 1; i <= numRooms; i++)
            {
                if (patients.GetPatient(i) == null)
                {
                    openRooms++;
                }
                else
                {
                    switch (patients.GetPatient(i).GetRating())
                    {
                    case 1: rating1++; break;

                    case 2: rating2++; break;

                    case 3: rating3++; break;

                    case 4: rating4++; break;
                    }
                }
            }
            for (int i = numRooms + 1; i <= patients.GetSize(); i++)
            {
                switch (patients.GetPatient(i).GetRating())
                {
                case 1: rating1++; break;

                case 2: rating2++; break;

                case 3: rating3++; break;

                case 4: rating4++; break;
                }
            }

            while (patients.GetPatient(numRooms + 1) != null || stopper >= (shift + shiftOver))
            {
                //counter++;
                //System.Diagnostics.Debug.WriteLine(counter);
                incrament = 100000;
                //if not null -> if arrived -> if smaller than current room time
                for (int z = 1; z <= numRooms; z++)
                {
                    /*System.Diagnostics.Debug.Write("Arive Time");
                     * System.Diagnostics.Debug.WriteLine(patients.GetPatient(z).GetArrivalTime());
                     * System.Diagnostics.Debug.Write("current Time");
                     * System.Diagnostics.Debug.WriteLine(shift);*/
                    if (patients.GetPatient(z) != null)
                    {
                        if (patients.GetPatient(z).roomTimeManip < incrament && patients.GetPatient(z).GetArrivalTime() <= (shift + shiftOver))
                        {
                            incrament = patients.GetPatient(z).roomTimeManip;
                        }
                        if (patients.GetPatient(z).GetArrivalTime() < incrament + (shift + shiftOver) && patients.GetPatient(z).GetArrivalTime() > (shift + shiftOver))
                        {
                            incrament = patients.GetPatient(z).GetArrivalTime() - (shift + shiftOver);
                        }
                    }
                }

                for (int i = 1; i <= numRooms; i++)
                {
                    if (patients.GetPatient(i) != null)
                    {
                        if (patients.GetPatient(i).GetArrivalTime() <= (shift + shiftOver))
                        {
                            patients.GetPatient(i).roomTimeManip -= incrament;

                            //Creates inacuracies if value is less than zero as that is not propogated forward
                            if (patients.GetPatient(i).roomTimeManip == 0)
                            {
                                patients.RemovePatient(i, (shift + shiftOver) + incrament);
                            }
                        }
                    }
                }
                //System.Diagnostics.Debug.WriteLine(shift);
                //Resort Queue
                shiftOver += incrament;
                patients.SortQueue((int)(shift + shiftOver));
            }
            results = new Results(shiftLen, rating1, rating2, rating3, rating4, patients.GetAvgWait1(shift + shiftOver), patients.GetAvgWait2(), patients.GetAvgWait3(),
                                  patients.GetAvgWait4(), shiftOver / 60, openRooms, instantSimNum);
            results.Show();
            //System.Diagnostics.Debug.WriteLine("Next Run");
        }