private void inputs(string filename) { string[] lines = File.ReadAllLines(filename); OrderUpTo = Int32.Parse(lines[1]); ReviewPeriod = Int32.Parse(lines[4]); StartInventoryQuantity = Int32.Parse(lines[7]); StartLeadDays = Int32.Parse(lines[10]); StartOrderQuantity = Int32.Parse(lines[13]); NumberOfDays = Int32.Parse(lines[16]); string[] temp; for (int i = 19; i < 24; i++) { temp = lines[i].Split(','); DemandDistribution.Add(new Distribution()); DemandDistribution[i - 19].Value = Int32.Parse(temp[0]); DemandDistribution[i - 19].Probability = Decimal.Parse(temp[1]); } for (int i = 26; i < 29; i++) { temp = lines[i].Split(','); LeadDaysDistribution.Add(new Distribution()); LeadDaysDistribution[i - 26].Value = Int32.Parse(temp[0]); LeadDaysDistribution[i - 26].Probability = Decimal.Parse(temp[1]); } }
public void readfile(string fna) { FileStream fs = new FileStream(fna, FileMode.Open); StreamReader sr = new StreamReader(fs); while (sr.Peek() != -1) { string fineline = sr.ReadLine(); if (fineline == "") { continue; } else if (fineline.Contains("OrderUpTo")) { OrderUpTo = int.Parse(sr.ReadLine()); } else if (fineline.Contains("ReviewPeriod")) { ReviewPeriod = int.Parse(sr.ReadLine()); } else if (fineline.Contains("StartInventoryQuantity")) { StartInventoryQuantity = int.Parse(sr.ReadLine()); } else if (fineline.Contains("StartLeadDays")) { StartLeadDays = int.Parse(sr.ReadLine()); } else if (fineline.Contains("StartOrderQuantity")) { StartOrderQuantity = int.Parse(sr.ReadLine()); } else if (fineline.Contains("NumberOfDays")) { NumberOfDays = int.Parse(sr.ReadLine()); } else if (fineline.Contains("DemandDistribution")) { int cp = 0; while (true) { string td = sr.ReadLine(); if (td == "") { break; } string[] l = td.Split(','); Distribution x = new Distribution(); x.Value = int.Parse(l[0]); int pro = Convert.ToInt32(float.Parse(l[1]) * 100); x.Probability = pro; x.CummProbability = cp + pro; x.MinRange = cp + 1; cp += pro; x.MaxRange = cp; DemandDistribution.Add(x); } } else if (fineline.Contains("LeadDaysDistribution")) { int cp = 0; while (true) { string td = sr.ReadLine(); if (td == "" || td == null) { break; } string[] l = td.Split(','); Distribution x = new Distribution(); x.Value = int.Parse(l[0]); int pro = Convert.ToInt32(float.Parse(l[1]) * 100); x.Probability = pro; x.CummProbability = cp + pro; x.MinRange = cp + 1; cp += pro; x.MaxRange = cp; LeadDaysDistribution.Add(x); } } } fs.Close(); }
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 == "OrderUpTo") { OrderUpTo = int.Parse(SR.ReadLine()); SR.ReadLine(); continue; } else if (str == "ReviewPeriod") { ReviewPeriod = int.Parse(SR.ReadLine()); SR.ReadLine(); continue; } else if (str == "StartLeadDays") { StartLeadDays = int.Parse(SR.ReadLine()); SR.ReadLine(); continue; } else if (str == "StartInventoryQuantity") { StartInventoryQuantity = int.Parse(SR.ReadLine()); SR.ReadLine(); continue; } else if (str == "StartOrderQuantity") { StartOrderQuantity = int.Parse(SR.ReadLine()); SR.ReadLine(); continue; } else if (str == "NumberOfDays") { NumberOfDays = int.Parse(SR.ReadLine()); SR.ReadLine(); continue; } else if (str == "DemandDistribution") { str = SR.ReadLine(); while (str != "") { string[] substrings = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); Distribution DD = new Distribution(); DD.Value = int.Parse(substrings[0]); DD.Probability = decimal.Parse(substrings[1]); str = SR.ReadLine(); DemandDistribution.Add(DD); } generate_cumulative_range(DemandDistribution); continue; } else if (str == "LeadDaysDistribution") { str = SR.ReadLine(); while (str != "" && str != null) { string[] substrings = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); Distribution LTD = new Distribution(); LTD.Value = int.Parse(substrings[0]); LTD.Probability = decimal.Parse(substrings[1]); str = SR.ReadLine(); LeadDaysDistribution.Add(LTD); } generate_cumulative_range(LeadDaysDistribution); continue; } } SR.Close(); }
///////////// My Methods ///////////// public void ReadFromFile(string path) { Distribution distribution; List <string> fileLines = new List <string>(); StreamReader sr = new StreamReader(path); while (!sr.EndOfStream) { fileLines.Add(sr.ReadLine()); } sr.Close(); int idx0 = fileLines.IndexOf("OrderUpTo"); OrderUpTo = Convert.ToInt32(fileLines[idx0 + 1]); int idx1 = fileLines.IndexOf("ReviewPeriod"); ReviewPeriod = Convert.ToInt32(fileLines[idx1 + 1]); int idx2 = fileLines.IndexOf("StartInventoryQuantity"); StartInventoryQuantity = Convert.ToInt32(fileLines[idx2 + 1]); int idx3 = fileLines.IndexOf("StartLeadDays"); StartLeadDays = Convert.ToInt32(fileLines[idx3 + 1]); int idx4 = fileLines.IndexOf("StartOrderQuantity"); StartOrderQuantity = Convert.ToInt32(fileLines[idx4 + 1]); int idx5 = fileLines.IndexOf("NumberOfDays"); NumberOfDays = Convert.ToInt32(fileLines[idx5 + 1]); int idx6 = fileLines.IndexOf("DemandDistribution"); for (int i = idx6 + 1; i < fileLines.Count(); ++i) { if (string.IsNullOrEmpty(fileLines[i])) { break; } distribution = new Distribution(); string[] numbers = fileLines[i].Split(new string[] { ", " }, StringSplitOptions.None); distribution.Value = Convert.ToInt32(numbers[0]); distribution.Probability = Convert.ToDecimal(numbers[1]); DemandDistribution.Add(distribution); } int idx7 = fileLines.IndexOf("LeadDaysDistribution"); for (int i = idx7 + 1; i < fileLines.Count(); ++i) { if (string.IsNullOrEmpty(fileLines[i])) { break; } distribution = new Distribution(); string[] numbers = fileLines[i].Split(new string[] { ", " }, StringSplitOptions.None); distribution.Value = Convert.ToInt32(numbers[0]); distribution.Probability = Convert.ToDecimal(numbers[1]); LeadDaysDistribution.Add(distribution); } }