Exemplo n.º 1
0
        public void ManageChannels()
        {
            List <Channel> channels    = new List <Channel>();
            List <Channel> outChannels = new List <Channel>();

            if ((ElementsList[Event].GetType() == typeof(HospitalProcess) || ElementsList[Event] is HospitalProcess == true) && ElementsList[Event].Name != "EXIT")
            {
                HospitalProcess p = (HospitalProcess)ElementsList[Event];
                p.InChannel();
            }
            foreach (var e in ElementsList)
            {
                if ((e.GetType() == typeof(HospitalProcess) || e is HospitalProcess == true) && e.Name != "EXIT")
                {
                    HospitalProcess p = (HospitalProcess)e;
                    outChannels = p.OutChannel(TNext);
                    foreach (var o in outChannels)
                    {
                        channels.Add(o);
                    }
                }
            }
            channels = channels.OrderBy(x => x.TimeOut).ToList();
            foreach (var c in channels)
            {
                Console.WriteLine();
                Console.WriteLine($"{c.Name} is free now t = {c.TimeOut}");
                Console.WriteLine();
            }
        }
Exemplo n.º 2
0
        public override void OutAct()
        {
            Quantity += 1;
            TNext     = Double.MaxValue;
            int patientType = 0;

            if (States.Count > 0)
            {
                patientType = States[0];
                States.RemoveAt(0);
            }

            if (Queue.Count > 0)
            {
                int patientTypeQueue = Queue[0];
                Queue.RemoveAt(0);
                States.Add(patientTypeQueue);
            }
            PatientType = patientType;
            if (patientType != 0)
            {
                Types[patientType - 1].Quantity++;
            }
            if (NextProcesses.Count != 0 && patientType != 0)
            {
                int             index       = random.Next(0, NextProcesses.Count);
                HospitalProcess nextProcess = NextProcesses[index];
                nextProcess.InAct(patientType);
                TNext = TCurrent + GetDelay();
                Console.WriteLine($"IN FUTURE from {Name} to {nextProcess.Name} t = {nextProcess.TNext}");
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //HospitalCreate c = new HospitalCreate(15, "CREATOR", "Exponential");

            //Doctor p0 = new Doctor(5, 8, "DOCTOR", "Exponential", 2);

            ////'''час следования в палату
            ////равномерно от 3 до 8 и следующая 3 это сопровождающие'''
            //HospitalProcess p1 = new HospitalProcess(3, 8, "CHAMBERS", "Exponential", 6);

            ////'''час обслуживания в регестратуре лаборатории
            //// мат.ожидание - 4.5
            ////коэфф. - 3'''
            //HospitalProcess p2 = new HospitalProcess(3, 4.5, "REGISTRATION", "Exponential", 1);

            ////'''час проведения анализа
            ////  мат.ожидание - 4
            //// коэфф. - 2'''
            //Laboratory p3 = new Laboratory(2, 4, "LABORATORY", "Exponential", 2);

            //c.NextElement = p0;
            //p0.NextProcesses = new List<HospitalProcess> { p1, p2 };
            //p2.NextProcesses = new List<HospitalProcess> { p3 };
            //p3.NextProcesses = new List<HospitalProcess> { p0 };

            //List<Element> elementsList = new List<Element> { c, p0, p1, p2, p3 };
            //HospitalModel model = new HospitalModel(elementsList);
            //model.Simulate(1000.0);

            HospitalCreate  c  = new HospitalCreate(10, "CREATOR", "Exponential");
            HospitalProcess p0 = new HospitalProcess(2, 5, "GO TO DOCTOR", "Uniform", 3);
            HospitalProcess p1 = new HospitalProcess(3, 8, "CHAMBERS", "Uniform", 3);
            HospitalProcess d  = new HospitalProcess(3, 8, "EXIT", "Exponential", 3);
            HospitalProcess p2 = new HospitalProcess(3, 4.5, "REGISTRATION", "Erlang", 4);
            Laboratory      p3 = new Laboratory(2, 4, "LABORATORY", "Erlang", 2);
            HospitalProcess p4 = new HospitalProcess(2, 5, "GO TO REGISTRATION", "Exponential", 3);
            Doctor          p5 = new Doctor(2, 5, "DOCTOR", "Uniform", 2);

            c.NextElement   = p0;
            c.PatientsTypes = new List <PatientType> {
                new PatientType(1, 0.5, 1 / 15),
                new PatientType(2, 0.1, 1 / 40),
                new PatientType(3, 0.4, 1 / 30)
            };
            p0.NextProcesses = new List <HospitalProcess> {
                p5
            };
            p5.NextProcesses = new List <HospitalProcess> {
                p1, p4
            };
            p2.NextProcesses = new List <HospitalProcess> {
                p3
            };
            p3.NextProcesses = new List <HospitalProcess> {
                p0, d
            };
            p4.NextProcesses = new List <HospitalProcess> {
                p2
            };

            List <Element> elementsList = new List <Element> {
                c, p0, p1, p2, p3, p4, p5, d
            };
            HospitalModel model = new HospitalModel(elementsList);

            model.Simulate(1000.0);
        }
Exemplo n.º 4
0
        public void PrintResult()
        {
            Console.WriteLine("---------------------RESULTS-----------------------");
            int           patients       = 0;
            double        tWaiting       = 0;
            double        timeBetweenLab = 0;
            List <double> types          = new List <double> {
                0, 0, 0
            };
            List <int> quantities = new List <int> {
                0, 0, 0
            };

            foreach (var e in ElementsList)
            {
                patients += e.Quantity;
                //if (e.GetType() == typeof(HospitalCreate))
                //{
                //    patients += e.Quantity;
                //}
                e.PrintResult();
                if (e.GetType() == typeof(HospitalCreate))
                {
                    HospitalCreate c = (HospitalCreate)e;
                    for (int i = 0; i < c.PatientsTypes.Count; i++)
                    {
                        quantities[i] = c.PatientsTypes[i].Quantity;
                    }
                }
                if (e.GetType() == typeof(HospitalProcess))
                {
                    HospitalProcess process = new HospitalProcess();
                    process   = (HospitalProcess)e;
                    patients += process.Quantity;
                    //if (process.Name == "LABORATORY" || process.Name == "DOCTOR" || process.Name == "CHAMBER")
                    //{
                    tWaiting += process.WaitingTime;
                    //}
                    foreach (var t in process.Types)
                    {
                        types[t.Index - 1] += t.WaitingTime;
                        //quantities[t.Index - 1] += process.Quantity;
                        quantities[t.Index - 1] += t.Quantity;
                    }
                    double average  = process.AverageQueue / process.TCurrent;
                    double workload = process.AverageWorkload / process.TCurrent;
                    Console.WriteLine($"name = {process.Name} max parallel = {process.MaxParallel} quantity = {process.Quantity} averageQ = {average} " +
                                      $" workload = {workload}");
                }
                if (e.GetType() == typeof(Doctor))
                {
                    Doctor doctor = (Doctor)e;
                    //patients += doctor.Quantity;
                    tWaiting += doctor.WaitingTime;
                    foreach (var t in doctor.Types)
                    {
                        types[t.Index - 1] += t.WaitingTime;
                        //quantities[t.Index - 1] += doctor.Quantity;
                        quantities[t.Index - 1] += t.Quantity;
                    }
                    double average  = doctor.AverageQueue / doctor.TCurrent;
                    double workload = doctor.AverageWorkload / doctor.TCurrent;
                    Console.WriteLine($"name = {doctor.Name} max parallel = {doctor.MaxParallel} quantity = {doctor.Quantity} averageQ = {average} " +
                                      $" workload = {workload}");
                    timeBetweenLab = doctor.DelaySum / doctor.ToLabAmount;
                }
            }
            double AverageTime = tWaiting / patients;

            for (int i = 0; i < types.Count; i++)
            {
                types[i] /= quantities[i];
                Console.WriteLine($"Average time in the hospital of type {i + 1} is {types[i]}");
            }
            //Console.WriteLine($"Average time in the hospital is {AverageTime}");
            Console.WriteLine($"Avg trip from doctor to lab duration is {timeBetweenLab}");
        }