public void GenerateDistribution(List <TimeDistribution> TimeDistributionTable) { TimeDistribution Last = new TimeDistribution(); Last.CummProbability = 0; Last.MaxRange = 0; for (int i = 0; i < TimeDistributionTable.Count; i++) { TimeDistributionTable[i].SetCummProp(Last.CummProbability); TimeDistributionTable[i].SetRanges(Last.MaxRange + 1); Last = TimeDistributionTable[i]; } }
public List <TimeDistribution> gettable_baker() { List <TimeDistribution> inter = new List <TimeDistribution>(); FileStream fs = new FileStream("C:/Users/Eslam Yehia/Desktop/baker.txt", FileMode.Open); StreamReader sr = new StreamReader(fs); while (sr.Peek() != -1) { string[] l = sr.ReadLine().Split(','); TimeDistribution x = new TimeDistribution(); x.Time = int.Parse(l[0]); x.Probability = int.Parse(l[1]); x.CummProbability = int.Parse(l[2]); x.MinRange = int.Parse(l[3]); x.MaxRange = int.Parse(l[4]); inter.Add(x); } fs.Close(); return(inter); }
void SetUsersTimeTable() { TimeDistribution tmp1 = new TimeDistribution(); tmp1.Time = 1; tmp1.Probability = 0.25m; tmp1.CummProbability = 0.25m; tmp1.MinRange = 1; tmp1.MaxRange = 25; TimeDistribution tmp2 = new TimeDistribution(); tmp2.Time = 2; tmp2.Probability = 0.40m; tmp2.CummProbability = 0.65m; tmp2.MinRange = 26; tmp2.MaxRange = 65; TimeDistribution tmp3 = new TimeDistribution(); tmp3.Time = 3; tmp3.Probability = 0.20m; tmp3.CummProbability = 0.85m; tmp3.MinRange = 66; tmp3.MaxRange = 85; TimeDistribution tmp4 = new TimeDistribution(); tmp4.Time = 4; tmp4.Probability = 0.15m; tmp4.CummProbability = 1m; tmp4.MinRange = 86; tmp4.MaxRange = 100; this.InterarrivalDistribution.Add(tmp1); this.InterarrivalDistribution.Add(tmp2); this.InterarrivalDistribution.Add(tmp3); this.InterarrivalDistribution.Add(tmp4); }
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(); }
public void fillSystemInformation(string filePath) { FileStream testCaseFile = new FileStream(filePath, FileMode.Open); StreamReader teseCaseReader = new StreamReader(testCaseFile); for (int i = 0; i < 13; ++i) { string Line = teseCaseReader.ReadLine(); if (i % 3 == 1) { if (i / 3 == 0) { this.NumberOfServers = int.Parse(Line); } else if (i / 3 == 1) { this.StoppingNumber = int.Parse(Line); } else if (i / 3 == 2) { this.StoppingCriteria = (Enums.StoppingCriteria)(int.Parse(Line)); } else { this.SelectionMethod = (Enums.SelectionMethod)(int.Parse(Line)); } } } while (true) { string Line = teseCaseReader.ReadLine(); if (String.IsNullOrEmpty(Line) || String.IsNullOrWhiteSpace(Line)) { break; } Line = Line.Replace(" ", ""); string[] values = Line.Split(','); TimeDistribution Element = new TimeDistribution(); Element.Time = int.Parse(values[0]); Element.Probability = decimal.Parse(values[1]); this.InterarrivalDistribution.Add(Element); } for (int i = 1; i <= this.NumberOfServers; ++i) { Server newServer = new Server(); newServer.ID = i; string Line = teseCaseReader.ReadLine(); while (true) { Line = teseCaseReader.ReadLine(); if (String.IsNullOrEmpty(Line) || String.IsNullOrWhiteSpace(Line)) { break; } Line = Line.Replace(" ", ""); string[] values = Line.Split(','); TimeDistribution Element = new TimeDistribution(); Element.Time = int.Parse(values[0]); Element.Probability = decimal.Parse(values[1]); newServer.TimeDistribution.Add(Element); } this.Servers.Add(newServer); } testCaseFile.Close(); }
public void Read(string path) { //for testing put the path of testcase1.txt and debug to see the variables FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(fs); int initialNumberOfServers = 0; string var; while (!reader.EndOfStream) { var = reader.ReadLine(); switch (var) { case "NumberOfServers": { Input.NumberOfServers = int.Parse(reader.ReadLine()); initialNumberOfServers = Input.NumberOfServers; } break; case "StoppingNumber": { Input.StoppingNumber = int.Parse(reader.ReadLine()); } break; case "StoppingCriteria": { Input.StoppingCriterea = int.Parse(reader.ReadLine()); } break; case "SelectionMethod": { Input.SelectionMethod = int.Parse(reader.ReadLine()); } break; case "InterarrivalDistribution": { List <TimeDistribution> tlist = new List <TimeDistribution>(); while (true) { TimeDistribution t = new TimeDistribution(); string tmp = reader.ReadLine(); string[] arr = tmp.Split(','); if (arr.Length == 1) { break; } t.Time = int.Parse(arr[0]); t.Probability = decimal.Parse(arr[1]); tlist.Add(t); } InterarrivalDistribution = tlist; } break; case "ServiceDistribution_Server1": { List <Server> Servers = new List <Server>(); for (int i = 0; i < initialNumberOfServers; i++) { List <TimeDistribution> tlist = new List <TimeDistribution>(); Server S = new Server(); while (!reader.EndOfStream) { TimeDistribution t = new TimeDistribution(); string tmp = reader.ReadLine(); string[] arr = tmp.Split(','); if (arr.Length == 1) { break; } t.Time = int.Parse(arr[0]); t.Probability = decimal.Parse(arr[1]); tlist.Add(t); } S.ID = i + 1; S.TimeDistribution = tlist; Servers.Add(S); reader.ReadLine(); } Input.ServersList = Servers; } break; } } }
public void readData(string FilePath) { string[] lines = File.ReadAllLines(FilePath); for (int i = 0; i < lines.Length; i++) { if (lines[i].Equals("NumberOfServers")) { i++; system.NumberOfServers = int.Parse(lines[i]); } else if (lines[i].Equals("StoppingNumber")) { i++; system.StoppingNumber = int.Parse(lines[i]); } else if (lines[i].Equals("StoppingCriteria")) { i++; StoppingCriteria = int.Parse(lines[i]); } else if (lines[i].Equals("SelectionMethod")) { i++; SelectedMethod = int.Parse(lines[i]); } else if (lines[i].Equals("InterarrivalDistribution")) { i++; int ac = 0; while (lines[i].Length > 0) { string[] interval = lines[i].Split(','); TimeDistribution distribution = new TimeDistribution(); int prob = (int)(double.Parse(interval[1]) * 100.0); distribution.Time = int.Parse(interval[0]); distribution.MinRange = ac + 1; ac += prob; distribution.MaxRange = ac; i++; system.InterarrivalDistribution.Add(distribution); } for (int y = 0; y < system.NumberOfServers; y++) { i += 2; int acc = 0; Server server = new Server(); while (i < lines.Length && lines[i].Length > 0) { string[] interval = lines[i].Split(','); TimeDistribution distribution = new TimeDistribution(); int prob = (int)(double.Parse(interval[1]) * 100.0); distribution.Time = int.Parse(interval[0]); distribution.MinRange = acc + 1; acc += prob; distribution.MaxRange = acc; i++; server.TimeDistribution.Add(distribution); } server.ID = system.Servers.Count + 1; server.TotalWorkingTime = 0; server.FinishTime = 0; server.TotalServerCustomer = 0; system.Servers.Add(server); } } } //MessageBox.Show("Number Of Servers = " + system.NumberOfServers.ToString()); //MessageBox.Show("Stopping Number = " + system.StoppingNumber.ToString()); //MessageBox.Show("Stopping Criteria = " + StoppingCriteria.ToString()); //MessageBox.Show("Selected Method = " + SelectedMethod.ToString()); //MessageBox.Show("InterArrival Time "); //foreach (TimeDistribution t in system.InterarrivalDistribution) { // MessageBox.Show(t.Time.ToString() + " " + t.MinRange.ToString() + " " + t.MaxRange.ToString()); //} //foreach (Server s in system.Servers) { // MessageBox.Show("Sever " + s.ID); // foreach (TimeDistribution t in s.TimeDistribution) // { // MessageBox.Show(t.Time.ToString() + " " + t.MinRange.ToString() + " " + t.MaxRange.ToString()); // } //} buildTable(); }
void SetServersTimeTable() { Server tmp1 = new Server(); tmp1.ID = 1; TimeDistribution S1T1 = new TimeDistribution(); S1T1.Time = 2; S1T1.Probability = 0.30m; S1T1.CummProbability = 0.30m; S1T1.MinRange = 1; S1T1.MaxRange = 30; TimeDistribution S1T2 = new TimeDistribution(); S1T2.Time = 3; S1T2.Probability = 0.28m; S1T2.CummProbability = 0.58m; S1T2.MinRange = 31; S1T2.MaxRange = 58; TimeDistribution S1T3 = new TimeDistribution(); S1T3.Time = 4; S1T3.Probability = 0.25m; S1T3.CummProbability = 0.83m; S1T3.MinRange = 59; S1T3.MaxRange = 83; TimeDistribution S1T4 = new TimeDistribution(); S1T4.Time = 5; S1T4.Probability = 0.17m; S1T4.CummProbability = 1m; S1T4.MinRange = 84; S1T4.MaxRange = 100; tmp1.TimeDistribution.Add(S1T1); tmp1.TimeDistribution.Add(S1T2); tmp1.TimeDistribution.Add(S1T3); tmp1.TimeDistribution.Add(S1T4); Server tmp2 = new Server(); tmp2.ID = 2; TimeDistribution S2T1 = new TimeDistribution(); S2T1.Time = 3; S2T1.Probability = 0.35m; S2T1.CummProbability = 0.35m; S2T1.MinRange = 1; S2T1.MaxRange = 35; TimeDistribution S2T2 = new TimeDistribution(); S2T2.Time = 4; S2T2.Probability = 0.25m; S2T2.CummProbability = 0.60m; S2T2.MinRange = 36; S2T2.MaxRange = 60; TimeDistribution S2T3 = new TimeDistribution(); S2T3.Time = 5; S2T3.Probability = 0.20m; S2T3.CummProbability = 0.80m; S2T3.MinRange = 61; S2T3.MaxRange = 80; TimeDistribution S2T4 = new TimeDistribution(); S2T4.Time = 6; S2T4.Probability = 0.20m; S2T4.CummProbability = 1m; S2T4.MinRange = 81; S2T4.MaxRange = 100; tmp2.TimeDistribution.Add(S2T1); tmp2.TimeDistribution.Add(S2T2); tmp2.TimeDistribution.Add(S2T3); tmp2.TimeDistribution.Add(S2T4); Servers.Add(tmp1); Servers.Add(tmp2); }