Esempio n. 1
0
        static void Main(string[] args)
        {
            int    simulationEmployeeNum    = 20;                //  default value
            int    simulationBrewingTime    = 30;                // 30 seconds default value for brewing time
            int    simulationTimeInBusyMode = 60 * 60 * 2;       // 2 hours default value
            double simulationProbabilityToBecomeSuperBusy = 0.2; // default value

            List <Employee> currentEmploeeList = new List <Employee>();

            while (true)
            {
                Console.WriteLine("Please spicify number of employees (or just enter empty for default value {0}) :=>", simulationEmployeeNum);
                string readline = Console.ReadLine();
                int    value;
                if (readline == "")
                {
                    break;
                }
                if (int.TryParse(readline, out value) && value > 0)
                {
                    simulationEmployeeNum = value;
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter correct value");
                }
            }

            while (true)
            {
                Console.WriteLine("Please spicify coffe breewing time in seconds (default value {0}) :=>", simulationBrewingTime);
                string readline = Console.ReadLine();
                int    value;
                if (readline == "")
                {
                    break;
                }
                if (int.TryParse(readline, out value) && value > 0)
                {
                    simulationBrewingTime = value;
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter correct value");
                }
            }

            while (true)
            {
                Console.WriteLine("Please spicify time in busy mode (or just enter empty for default value {0}) :=>", simulationTimeInBusyMode);
                string readline = Console.ReadLine();
                int    value;
                if (readline == "")
                {
                    break;
                }
                if (int.TryParse(readline, out value) && value > 0)
                {
                    simulationTimeInBusyMode = value;
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter correct value");
                }
            }

            while (true)
            {
                Console.WriteLine("Please spicify probability become superbusy (or just enter empty for default value {0}) :=>", simulationProbabilityToBecomeSuperBusy);
                string readline = Console.ReadLine();
                double value;
                if (readline == "")
                {
                    break;
                }
                if (double.TryParse(readline, out value) && value >= 0.0)
                {
                    simulationProbabilityToBecomeSuperBusy = value;
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter correct value");
                }
            }

            var simulationEventsTimeline = new EventsTimeline();
            var simulationCoffeMachine   = new CoffeMachine(simulationEventsTimeline, simulationBrewingTime);

            for (int i = 0; i < simulationEmployeeNum; i++)
            {
                Func <int> workingTime = () =>
                {
                    double rnd = IVLRand.nextRandomExp(1.0 / 60.0 * 60.0) * 1000;
                    int    ret = Convert.ToInt32(rnd);
                    return(ret);
                };

                Func <int> inNonBusyMode = () =>
                {
                    double rnd = IVLRand.nextRandomExp(0.2) * 1000;
                    int    ret = Convert.ToInt32(rnd);
                    return(ret);
                };

                Func <int> inBusyMode = () =>
                {
                    return(simulationTimeInBusyMode);
                };


                //Console.WriteLine("Generated random {0}", workingTime);
                var empl = new Employee(i.ToString(), simulationEventsTimeline, simulationCoffeMachine, workingTime, inNonBusyMode, inBusyMode);
                currentEmploeeList.Add(empl);
                Thread.Sleep(50); // added to prevent filling by same numbers on very fast machine
            }

            // also can be entered in the beginning num of the simulation iteration
            for (int i = 0; i < 2000; i++)
            {
                var res = simulationEventsTimeline.doSimulationStep();
                if (res != "")
                {
                    Console.WriteLine(res);
                }
            }
            Console.ReadKey();
        }