private void inputFromFile(string fileName)
        {
            string[] lines = File.ReadAllLines(fileName);
            DowntimeCost             = Int32.Parse(lines[1]);
            RepairPersonCost         = Int32.Parse(lines[4]);
            BearingCost              = Int32.Parse(lines[7]);
            NumberOfHours            = Int32.Parse(lines[10]);
            NumberOfBearings         = Int32.Parse(lines[13]);
            RepairTimeForOneBearing  = Int32.Parse(lines[16]);
            RepairTimeForAllBearings = Int32.Parse(lines[19]);
            string[] dd;

            //Filling Dely Time Distribution
            for (int i = 0; i < 3; i++)
            {
                dd = lines[22 + i].Split(',');
                DelayTimeDistribution.Add(new TimeDistribution());
                DelayTimeDistribution[i].Time        = Int32.Parse(dd[0]);
                DelayTimeDistribution[i].Probability = Decimal.Parse(dd[1]);
            }

            //Filling Bearing Life Distribustio
            for (int i = 0; i < lines.Length - 22 - 2 - 3; i++)
            {
                dd = lines[22 + 2 + 3 + i].Split(',');
                BearingLifeDistribution.Add(new TimeDistribution());
                BearingLifeDistribution[i].Time        = Int32.Parse(dd[0]);
                BearingLifeDistribution[i].Probability = Decimal.Parse(dd[1]);
            }
        }
        public void read_from_file()
        {
            FileStream   fs = new FileStream(@"C:\Users\TASNEEM\Downloads\[Students]_Template\BearingMachineSimulation\TestCases\TestCase2.txt", FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            while (sr.Peek() != -1)
            {
                file.Add(sr.ReadLine());
            }
            sr.Close();
            fs.Close();
            for (int i = 1; i < 21; i = i + 3)
            {
                input_inform.Add(file[i]);
            }
            DowntimeCost = int.Parse(input_inform[0]);

            RepairPersonCost = int.Parse(input_inform[1]);

            BearingCost   = int.Parse(input_inform[2]);
            NumberOfHours = int.Parse(input_inform[3]);

            NumberOfBearings = int.Parse(input_inform[4]);

            RepairTimeForOneBearing  = int.Parse(input_inform[5]);
            RepairTimeForAllBearings = int.Parse(input_inform[6]);


            for (int i = 22; i < 25; i++)
            {
                string[] arr = file[i].Split(',');
                DelayTimeDistribution.Add(new TimeDistribution()
                {
                    Time = int.Parse(arr[0]), Probability = decimal.Parse(arr[1])
                });
            }

            for (int i = 27; i < file.Count; i++)
            {
                string[] arr = file[i].Split(',');
                BearingLifeDistribution.Add(new TimeDistribution()
                {
                    Time = int.Parse(arr[0]), Probability = decimal.Parse(arr[1])
                });
            }

            calculate_CummProbability(DelayTimeDistribution, BearingLifeDistribution);
            calculate_RandomDigit(DelayTimeDistribution, BearingLifeDistribution);
        }
Exemple #3
0
        public void getSystemInformation(string filePath)
        {
            string line;

            System.IO.StreamReader file = new System.IO.StreamReader(filePath);
            List <string>          data = new List <string>();

            while ((line = file.ReadLine()) != null)
            {
                if (line.Length > 0 && line[0] >= '0' && line[0] <= '9')
                {
                    data.Add(line);
                }
            }
            DowntimeCost             = int.Parse(data[0]);
            RepairPersonCost         = int.Parse(data[1]);
            BearingCost              = int.Parse(data[2]);
            NumberOfHours            = int.Parse(data[3]);
            NumberOfBearings         = int.Parse(data[4]);
            RepairTimeForOneBearing  = int.Parse(data[5]);
            RepairTimeForAllBearings = int.Parse(data[6]);
            TimeDistribution DelayTimeDistributionTemp = new TimeDistribution();

            for (int i = 7; i < 10; i++)
            {
                DelayTimeDistributionTemp = new TimeDistribution();
                DelayTimeDistribution.Add(DelayTimeDistributionTemp.setData(data[i]));
            }
            DelayTimeDistribution = DelayTimeDistributionTemp.postProcess(DelayTimeDistribution);
            TimeDistribution BearingLifeDistributionTemp = new TimeDistribution();

            for (int i = 10; i < data.Count; i++)
            {
                BearingLifeDistributionTemp = new TimeDistribution();
                BearingLifeDistribution.Add(BearingLifeDistributionTemp.setData(data[i]));
            }
            BearingLifeDistribution = BearingLifeDistributionTemp.postProcess(BearingLifeDistribution);
            file.Close();
        }
Exemple #4
0
        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 == "DowntimeCost")
                {
                    DowntimeCost = int.Parse(sr.ReadLine());
                }
                else if (fineline == "RepairPersonCost")
                {
                    RepairPersonCost = int.Parse(sr.ReadLine());
                }
                else if (fineline == "BearingCost")
                {
                    BearingCost = int.Parse(sr.ReadLine());
                }
                else if (fineline == "NumberOfHours")
                {
                    NumberOfHours = int.Parse(sr.ReadLine());
                }
                else if (fineline == "NumberOfBearings")
                {
                    NumberOfBearings = int.Parse(sr.ReadLine());
                }

                else if (fineline == "RepairTimeForOneBearing")
                {
                    RepairTimeForOneBearing = int.Parse(sr.ReadLine());
                }
                else if (fineline == "RepairTimeForAllBearings")
                {
                    RepairTimeForAllBearings = int.Parse(sr.ReadLine());
                }
                else if (fineline == "DelayTimeDistribution")
                {
                    int cp = 0;
                    while (true)
                    {
                        string td = sr.ReadLine();
                        if (td == "")
                        {
                            break;
                        }
                        string[]         l = td.Split(',');
                        TimeDistribution x = new TimeDistribution();
                        x.Time = 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;
                        DelayTimeDistribution.Add(x);
                    }
                }
                else if (fineline == "BearingLifeDistribution")
                {
                    int cp = 0;
                    while (true)
                    {
                        string td = sr.ReadLine();
                        if (td == "" || td == null)
                        {
                            break;
                        }
                        string[]         l = td.Split(',');
                        TimeDistribution x = new TimeDistribution();
                        x.Time = 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;
                        BearingLifeDistribution.Add(x);
                    }
                }
            }
            fs.Close();
        }
Exemple #5
0
        public void ReadInput(string filepath)
        {
            string       str;
            FileStream   fs = new FileStream(filepath, FileMode.Open);
            StreamReader SR = new StreamReader(fs);

            while (SR.Peek() != -1)
            {
                str = SR.ReadLine();
                if (str == "DowntimeCost")
                {
                    DowntimeCost = int.Parse(SR.ReadLine());
                    SR.ReadLine();
                    continue;
                }
                else if (str == "RepairPersonCost")
                {
                    RepairPersonCost = int.Parse(SR.ReadLine());
                    SR.ReadLine();
                    continue;
                }
                else if (str == "BearingCost")
                {
                    BearingCost = int.Parse(SR.ReadLine());
                    SR.ReadLine();
                    continue;
                }
                else if (str == "NumberOfHours")
                {
                    NumberOfHours = int.Parse(SR.ReadLine());
                    SR.ReadLine();
                    continue;
                }
                else if (str == "NumberOfBearings")
                {
                    NumberOfBearings = int.Parse(SR.ReadLine());
                    SR.ReadLine();
                    continue;
                }
                else if (str == "RepairTimeForOneBearing")
                {
                    RepairTimeForOneBearing = int.Parse(SR.ReadLine());
                    SR.ReadLine();
                    continue;
                }
                else if (str == "RepairTimeForAllBearings")
                {
                    RepairTimeForAllBearings = int.Parse(SR.ReadLine());
                    SR.ReadLine();
                    continue;
                }
                else if (str == "DelayTimeDistribution")
                {
                    str = SR.ReadLine();
                    while (str != "")
                    {
                        TimeDistribution TD         = new TimeDistribution();
                        string[]         substrings = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        TD.Time        = int.Parse(substrings[0]);
                        TD.Probability = decimal.Parse(substrings[1]);
                        str            = SR.ReadLine();
                        DelayTimeDistribution.Add(TD);
                    }
                    generate_cumulative_range(DelayTimeDistribution);
                    continue;
                }
                else if (str == "BearingLifeDistribution")
                {
                    str = SR.ReadLine();
                    while (str != "" && str != null)
                    {
                        TimeDistribution TD         = new TimeDistribution();
                        string[]         substrings = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        TD.Time        = int.Parse(substrings[0]);
                        TD.Probability = decimal.Parse(substrings[1]);
                        str            = SR.ReadLine();
                        BearingLifeDistribution.Add(TD);
                    }
                    generate_cumulative_range(BearingLifeDistribution);
                    continue;
                }
            }
            SR.Close();
        }