Exemplo n.º 1
0
        public override void Execute(List <Event> scheduler, BloodStore bloodStorage, PatientQueue patientQ)
        {
            _type = "BT";
            int time = BUnits == 1 ? 500 : 300; // lambda statemenet N and Q are connect with T1 and T2

            for (int i = 0; i < BUnits; i++)
            {
                bloodStorage.BloodLevel++;
                bloodStorage.BloodStorageList.Add(new Blood(time));
                Utilisation temp = new Utilisation(SystemTime + time, "aUT");
                AddToScheduler(scheduler, temp); // Adds time of utilisation of Blood
                if (_flagEmergency == true)      // Enables to return exactly right units of blood from Emergency
                {
                    temp.BloodFromEmergency = true;
                }
            }
            BloodStore.Sorted(bloodStorage.BloodStorageList);
            Sorted(scheduler);
            if (time == 300)
            {
                BloodStore.OrderFlag = false;
            }                                                 // Setting right flags (makes NewOrder available)
            else
            {
                BloodStore.EmergencyFlag = false;
            }                                          // Makes EmergencyOrder available
        }
Exemplo n.º 2
0
 public override void Execute(List <Event> scheduler, BloodStore bloodStorage, PatientQueue patientQ)
 {
     bloodStorage.BloodLevel = --bloodStorage.BloodLevel; // Changes value of BloodLevel
     Sorted(scheduler);
     bloodStorage.BloodStorageList.RemoveAt(0);           // Removes Blood from BloodList
     Console.WriteLine("\n### UTILISATION -> Current blood level: " + bloodStorage.BloodLevel + " ###");
 }
Exemplo n.º 3
0
        public override void Execute(List <Event> scheduler, BloodStore bloodStorage, PatientQueue patientQ)
        {
            Type = "ND";
            int time = Rnd.Next(11, 21);    // Gets this from generator

            time = SystemTime + time;
            Console.WriteLine("\n### NEW DONNOR ###");
            Blood.AddBlood(bloodStorage.BloodStorageList, time);                           // Adds Blood to the Storage
            BloodStore.Sorted(bloodStorage.BloodStorageList);
            AddToScheduler(scheduler, new BloodSupply(SystemTime + time, "TR", 1, false)); // Adds Transport with Blood which will arrive
            AddToScheduler(scheduler, new NewDonnor(SystemTime + time, "ND"));             // Planning new Donnor Event
            Sorted(scheduler);
        }
Exemplo n.º 4
0
        public override void Execute(List <Event> scheduler, BloodStore bloodStorage, PatientQueue patientQ)
        {
            _type = "NP";
            int timeExp = Rnd.Next(5, 16);

            Console.WriteLine("\n### NEW PATIENT ###");
            var i = BloodStore.Rnd.Next(1, 6);         // Patient needs 1-5 units of Blood

            patientQ.PatientQ.Enqueue(new Patient(i)); // new Patient who needs X blood units
            patientQ.BloodNeeded = patientQ.BloodNeeded + i;

            // Planning New Event
            // TIME_EXP comes from generator Exponential and Average P
            scheduler.Add(new NewPatient(SystemTime + timeExp, "NP"));
            Sorted(scheduler);
        }
Exemplo n.º 5
0
 public override void Execute(List <Event> scheduler, BloodStore bloodStorage, PatientQueue patientQ)
 {
     SortedByType(scheduler); // Sorting scheduler by Type aUT will be first
     while (true)
     {
         if ((_timeGenerator == SystemTime) && (scheduler[0].Type == "aUT") && (scheduler[0].BloodFromEmergency == true))
         {
             bloodStorage.BloodLevel = --bloodStorage.BloodLevel; // Changes value of BloodLevel
             bloodStorage.BloodStorageList.RemoveAt(0);           // Removes Blood from BloodList
             Console.WriteLine("\n### ReturnBlood -> Current blood level: " + bloodStorage.BloodLevel + " ###");
         }
         else
         {
             break;
         }
     }
     Sorted(scheduler); // Sorting scheduler by expDate.
 }
Exemplo n.º 6
0
        public void Begin(List <Event> scheduler, BloodStore bloodStorage, PatientQueue patientQ)
        {
            SystemTime = 0;
            bloodStorage.FillBlood(scheduler); // initializes Blood into Storage and adds an ExpDate into scheduler
            Console.WriteLine("\nPo sortowaniu: ");
            bloodStorage.ShowExpDate();
            NewDonnor  donator = new NewDonnor(5, "ND");
            NewPatient patient = new NewPatient(5, "NP");

            for (int i = 0; i < 5; i++)
            {
                donator.Execute(scheduler, bloodStorage, patientQ);                         // Gives new 5 Donnors
            }
            Sorted(scheduler);
            Console.WriteLine("\nSCHEDULER: ");
            ShowScheduler(scheduler);
            for (int i = 0; i < 5; i++)
            {
                patient.Execute(scheduler, bloodStorage, patientQ);                        // creates 5 patients to the Queue
            }
            patientQ.ShowQueue();
        }
Exemplo n.º 7
0
 public virtual void Execute(List <Event> scheduler, BloodStore bloodStorage, PatientQueue patientQ)
 {
 }
Exemplo n.º 8
0
        private static void Main()
        {
            bool flag    = true;
            bool flagAcc = true;

            while (flag)
            {
                Console.WriteLine("\n-----------------------------");
                // ####### BEGINING INITIALIZATION OF THE SYSTEM #######
                List <Event> scheduler    = new List <Event>(); // Creates scheduler which is list of Events
                var          bloodStorage = new BloodStore(0);  // object contains bloodStorage; 0 is value how much blood units is inside
                var          patientQ     = new PatientQueue(); // object contains patientQueue
                bloodStorage.Begin(scheduler, bloodStorage, patientQ);
                // ####### END INITIALIZATION OF THE SYSTEM #######
                Console.Write("\n\nMENU:\n1.Tryb ciagly\n2.Tryb krokowy\n3.Koniec symulacji\n-----------\n");
                const int r        = 15;
                int       loopTime = 100;
                Console.Write("Wybor: ");
                int loop = Convert.ToInt32(Console.ReadLine());
                switch (loop)
                {
                case 1:     // Constant Loop
                {
                    while (loopTime != 0)
                    {
                        while (flagAcc)
                        {
                            Console.WriteLine("\n\n@@@ " + loopTime + " @@@\n");
                            if (bloodStorage.BloodLevel <= r)
                            {
                                BloodStore.NewOrder(scheduler);
                            }                                                                            // Make a NewOrder
                            if (patientQ.BloodNeeded >= bloodStorage.BloodLevel)
                            {
                                BloodStore.EmergencyOrder(scheduler);
                            }                                                                                                     // Make a EmergencyOrder
                            // Make Transfusion
                            if ((patientQ.BloodNeeded != 0) &&
                                (bloodStorage.BloodLevel > patientQ.BloodNeededFirst()))
                            {
                                bloodStorage.Transfusion(patientQ, scheduler);
                                Console.WriteLine("\n### MAKE TRANSFUSION ###\n### PATIENT QUEUE ###");
                                patientQ.ShowQueue();
                                Console.WriteLine("### CURRENT SCHEDULER ###");
                                ShowScheduler(scheduler);
                            }
                            else
                            {
                                flagAcc = false;
                            }
                        }

                        flagAcc = true;
                        if (SystemTime == scheduler[0].EventTime)
                        {
                            Event temp = scheduler[0];                       // pull out object from list
                            temp.Execute(scheduler, bloodStorage, patientQ); // Execute function
                            scheduler.RemoveAt(0);                           // Remove object from list
                            Console.WriteLine("\n### REMOVE OBJECT ###");
                            ShowScheduler(scheduler);
                        }
                        else
                        {
                            Console.WriteLine("\nNEW OBJECT -> SYS:" + SystemTime + " EVENT: " + scheduler[0].EventTime);
                            SystemTime = scheduler[0].EventTime;
                            Console.Write("System Time after Actualisation: " + SystemTime + "\n");
                            loopTime--;
                            ShowScheduler(scheduler);
                        }
                    }
                    break;
                }

                case 2:     // Stepping Loop
                {
                    while (loopTime != 0)
                    {
                        while (flagAcc)
                        {
                            Console.WriteLine("\n\n" + loopTime + " @@@@@@@@@@@@\n");
                            if (bloodStorage.BloodLevel <= r)
                            {
                                BloodStore.NewOrder(scheduler);
                            }                                                                             // Make a NewOrder
                            if (patientQ.BloodNeeded >= bloodStorage.BloodLevel)
                            {
                                BloodStore.EmergencyOrder(scheduler);
                            }                                                                                                      // Make a EmergencyOrder
                            // Make Transfusion
                            if ((patientQ.BloodNeeded != 0) &&
                                (bloodStorage.BloodLevel > patientQ.BloodNeededFirst()))
                            {
                                bloodStorage.Transfusion(patientQ, scheduler);
                                Console.WriteLine("\n### MAKE TRANSFUSION ###\n### PATIENT QUEUE ###");
                                patientQ.ShowQueue();
                                Console.WriteLine("### CURRENT SCHEDULER ###");
                                ShowScheduler(scheduler);
                            }
                            else
                            {
                                flagAcc = false;
                            }
                        }
                        flagAcc = true;
                        if (SystemTime == scheduler[0].EventTime)
                        {
                            Event temp = scheduler[0];                       // pull out object from list
                            temp.Execute(scheduler, bloodStorage, patientQ); // Execute function
                            scheduler.RemoveAt(0);                           // Remove object from list
                            Console.WriteLine("\n### REMOVE OBJECT ###");
                            ShowScheduler(scheduler);
                        }
                        else
                        {
                            Console.WriteLine("\nNEW OBJECT -> SYS:" + SystemTime + " EVENT: " + scheduler[0].EventTime);
                            SystemTime = scheduler[0].EventTime;
                            Console.Write("System Time after Actualisation: " + SystemTime + "\n");
                            loopTime--;
                            ShowScheduler(scheduler);
                        }
                        Console.WriteLine("\n\nCLICK ENTER TO CONTINUE\n");
                        Console.ReadLine();         // stepping loop
                    }
                    break;
                }

                case 3:
                {
                    flag = false;
                    Console.WriteLine("Zakonczyles prace programu. Dziekujemy za symulacje.");
                    break;
                }

                default:
                {
                    Console.WriteLine("Ups.. Podales nieznany numer. Sprobuj ponownie");
                    break;
                }
                }
            }
        }