Exemplo n.º 1
0
 public Simulator(int numberOfCustomersToFinish, int timeToFinish, StoppingCondition stoppingCodition)
 {
     this.neededNumberOfCustomers = numberOfCustomersToFinish;
     this.timeToFinish = timeToFinish;
     this.stoppingCodition = stoppingCodition;
     ResultStatistics = new CustomersStatistics();
 }
Exemplo n.º 2
0
        public List<ServiceResult> Simulate()
        {
            IDistributionDataReader distributionsReader = new FilesDistributionDataReader();
            Distribution interarrivalDistribution = distributionsReader.ReadIterarrivalDistribution();
            List<Distribution> serviceTimeDistributions = distributionsReader.ReadServerTimeDistributions();

            CalculateCumlativeDistributionAndRange(interarrivalDistribution);
            for (int i = 0; i < serviceTimeDistributions.Count; i++)
            {
                CalculateCumlativeDistributionAndRange(serviceTimeDistributions[i]);
            }

            FillServersData(serviceTimeDistributions);

            var results = new List<ServiceResult>();
            Random rand = new Random();

            int numberOfCustomers = 0;
            int time = 0;
            results.Add(new ServiceResult()
            {
                ArrivalTime = 0,
            });

            while (!IsFinished(numberOfCustomers, time))
            {
                int interarrivalTimeRandomNumber = rand.Next(0, 1001);
                int serviceTimeRandomNumber = rand.Next(0, 1001);

                int interarrivalTimeRangeIndex = PickRange(interarrivalTimeRandomNumber, interarrivalDistribution.Ranges);
                if (interarrivalTimeRangeIndex == -1) throw new Exception("Random interarrival time not in range");

                int interarrivalTime = interarrivalDistribution.Times[interarrivalTimeRangeIndex];

                int arrivalTime = results[results.Count - 1].ArrivalTime + interarrivalTime;

                if (arrivalTime > timeToFinish)
                    break;

                numberOfCustomers++;
                time = Math.Max(time, arrivalTime);

                int serverIndex = PickServer(arrivalTime, Servers);
                int size = Servers[serverIndex].Services.Count;
                int delayTime = new int();
                if (size <= 0)
                {
                    delayTime = 0;
                }
                else
                {
                    delayTime = Math.Max(0, Servers[serverIndex].Services[size - 1].ServiceTimeEnd - arrivalTime);
                    Servers[serverIndex].Services[size - 1].ServiceDelay = delayTime;
                }
                //error

                Distribution serverDistribution = Servers[serverIndex].ServiceTimeDistribution;
                int serviceTimeRangeIndex = PickRange(serviceTimeRandomNumber, serverDistribution.Ranges);

                int serviceTime = serverDistribution.Times[serviceTimeRangeIndex];

                var serverServices = Servers[serverIndex].Services;

                int serviceStart = arrivalTime;

                if (serverServices.Count != 0)
                    serviceStart = Math.Max(arrivalTime, serverServices[serverServices.Count - 1].ServiceTimeEnd);

                int serviceEnd = serviceStart + serviceTime;

                Service service = new Service()
                {
                    ServerID = Servers[serverIndex].ServerID,
                    ServiceTimeBegin = serviceStart,
                    ServiceDuraiton = serviceTime,
                    ServiceTimeEnd = serviceEnd
                };

                Servers[serverIndex].Services.Add(service);

                ServiceResult serviceResult = new ServiceResult();
                serviceResult.CustomerNumber = numberOfCustomers;
                serviceResult.IterarrivalTimeRandomNumber = interarrivalTimeRandomNumber;
                serviceResult.ServiceTimeRandomNumber = serviceTimeRandomNumber;
                serviceResult.InterarrivalTime = interarrivalTime;
                serviceResult.ArrivalTime = arrivalTime;
                serviceResult.ServerService = service;
                serviceResult.ServerDelay = delayTime;

                results.Add(serviceResult);
            }
            results.RemoveAt(0);

            simulationResults = results;

            CalculateCustomersQueueDistribution(results[results.Count-1].ServerService.ServiceTimeEnd);
            CalculateQueueHistogram();

            int maximumQueueLength = CalculateMaximumQueueSize();
            double averageCustomerWait = SetAverageCustomerWait(results, numberOfCustomers);
            double probabilityCustomerWait = SetProbabilityCustomerWait(results, numberOfCustomers);

            ResultStatistics = new CustomersStatistics()
            {
                MaximumQueueLength = maximumQueueLength,
                AverageCustomerWait = averageCustomerWait,
                ProbabilityCustomerWait = probabilityCustomerWait
            };

            for (int i = 0; i < Servers.Count; i++)
            {
                Servers[i].CalculateServerStatistcs(results[results.Count - 1].ServerService.ServiceTimeEnd, numberOfCustomers);
            }

            return results;
        }
Exemplo n.º 3
0
 public Simulator()
 {
     neededNumberOfCustomers = 100;
     stoppingCodition = StoppingCondition.NumberOfCustomers;
     ResultStatistics = new CustomersStatistics();
 }
Exemplo n.º 4
0
 public StatisticsForm(CustomersStatistics customersStatistics, List<ServerStatistics> serversStatistics)
 {
     this.customersStatistics = customersStatistics;
     this.serversStatistics = serversStatistics;
     InitializeComponent();
 }