public void intertime_dist_set(int t, decimal prob, int cust, int rows, int listOfTime) { InterarrivalDistribution.Add(new TimeDistribution()); InterarrivalDistribution[listOfTime].Time = t; InterarrivalDistribution[listOfTime].Probability = prob; IntComProb += prob; InterarrivalDistribution[listOfTime].CummProbability = IntComProb; InterarrivalDistribution[listOfTime].MinRange = Imin + 1; InterarrivalDistribution[listOfTime].MaxRange = Convert.ToInt32(IntComProb * 100); Imin = InterarrivalDistribution[listOfTime].MaxRange; }
public int getInterArrivalTimeByRandomRange(int randomNumber) { int arrivalTime = 0; for (int i = 0; i < InterarrivalDistribution.Count(); ++i) { int minRange = InterarrivalDistribution[i].MinRange, maxRange = InterarrivalDistribution[i].MaxRange; if (randomNumber >= minRange && randomNumber <= maxRange) { arrivalTime = InterarrivalDistribution[i].Time; break; } } return(arrivalTime); }
///////////// OPERATIONS ///////////// public void CalculateInterArrivalTimeDistribution() { decimal oldProb = 0; int maxRange = 0; for (int i = 0; i < InterarrivalDistribution.Count(); ++i) { InterarrivalDistribution[i].CummProbability = oldProb + InterarrivalDistribution[i].Probability; oldProb = InterarrivalDistribution[i].CummProbability; InterarrivalDistribution[i].MinRange = maxRange + 1; maxRange = (int)(InterarrivalDistribution[i].CummProbability * 100); InterarrivalDistribution[i].MaxRange = maxRange; } }
//=================================================================================================================== //===============================CASE HANDLER (FOR NUMBER OF CUS OR TIME)========================================= public void GenerateRand(SimulationSystem s) { int RINER, RSERVICE_T; //=================FOR CEREATION NUMBER OF CUSTOMERS========================== if (s.StoppingCriteria == Enums.StoppingCriteria.NumberOfCustomers) { for (int i = 0; i < s.StoppingNumber; i++) { RINER = Randomize(); SimulationTable.Add(new SimulationCase()); SimulationTable[i].RandomInterArrival = RINER; countofcustomer++; } SimulationTable[0].InterArrival = 0; for (int x = 1; x < countofcustomer; x++) { for (int i = 0; i < InterarrivalDistribution.Count(); i++) { if (SimulationTable[x].RandomInterArrival >= InterarrivalDistribution[i].MinRange && SimulationTable[x].RandomInterArrival <= InterarrivalDistribution[i].MaxRange) { SimulationTable[x].InterArrival = InterarrivalDistribution[i].Time; break; } } } for (int i = 0; i < countofcustomer; i++) { RSERVICE_T = Randomize(); SimulationTable[i].RandomService = RSERVICE_T; } } //=========================FOR CEREATION TIME============================================ else if (s.StoppingCriteria == Enums.StoppingCriteria.SimulationEndTime) { while (shrouk <= s.StoppingNumber) { RINER = Randomize(); SimulationTable.Add(new SimulationCase()); SimulationTable[countofcustomer].RandomInterArrival = RINER; for (int i = 0; i < InterarrivalDistribution.Count(); i++) { if (SimulationTable[countofcustomer].RandomInterArrival >= InterarrivalDistribution[i].MinRange && SimulationTable[countofcustomer].RandomInterArrival <= InterarrivalDistribution[i].MaxRange) { SimulationTable[countofcustomer].InterArrival = InterarrivalDistribution[i].Time; shrouk += SimulationTable[countofcustomer].InterArrival; break; } } if (shrouk == s.StoppingNumber) { countofcustomer++; break; } countofcustomer++; } } for (int i = 0; i < countofcustomer; i++) { RSERVICE_T = Randomize(); SimulationTable[i].RandomService = RSERVICE_T; } }
public void ReadInput(string filepath) { string str; FileStream fs = new FileStream(filepath, FileMode.Open); StreamReader SR = new StreamReader(fs); // char s = (char)SR.Read(); while (SR.Peek() != -1) { str = SR.ReadLine(); if (str == "NumberOfServers") { NumberOfServers = int.Parse(SR.ReadLine()); SR.ReadLine(); continue; } else if (str == "StoppingNumber") { StoppingNumber = int.Parse(SR.ReadLine()); SR.ReadLine(); continue; } else if (str == "StoppingCriteria") { StoppingCriteria = (Enums.StoppingCriteria)(int.Parse(SR.ReadLine())); SR.ReadLine(); continue; } else if (str == "SelectionMethod") { SelectionMethod = (Enums.SelectionMethod)(int.Parse(SR.ReadLine())); SR.ReadLine(); continue; } else if (str == "InterarrivalDistribution") { str = SR.ReadLine(); while (str != "") { string[] substrings = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); TimeDistribution TD = new TimeDistribution(); TD.Time = int.Parse(substrings[0]); TD.Probability = decimal.Parse(substrings[1]); str = SR.ReadLine(); InterarrivalDistribution.Add(TD); } generate_cumulative_range(InterarrivalDistribution); continue; } else { for (int i = 0; i < NumberOfServers; i++) { Servers.Add(new Server()); Servers[i].ID = i + 1; str = SR.ReadLine(); while (str != "" && str != null) { string[] substrings = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); TimeDistribution TD = new TimeDistribution(); TD.Time = int.Parse(substrings[0]); TD.Probability = decimal.Parse(substrings[1]); str = SR.ReadLine(); Servers[i].TimeDistribution.Add(TD); } str = SR.ReadLine(); continue; } } } SR.Close(); }