コード例 #1
0
        private void Simulate_Click(object sender, EventArgs e)
        {
            simulator.calculate_life_time(dataGridView1);
            simulator.calculate_delay_time(dataGridView2);
            Form2 f2 = new Form2(mysystem);

            f2.Show();
            Form3 f3 = new Form3(mysystem);

            f3.Show();
            string s = "";

            if (comboBox1.Text == "TestCase1")
            {
                s = TestingManager.Test(mysystem, Constants.FileNames.TestCase1);
            }
            else if (comboBox1.Text == "TestCase2")
            {
                s = TestingManager.Test(mysystem, Constants.FileNames.TestCase2);
            }
            else
            {
                s = TestingManager.Test(mysystem, Constants.FileNames.TestCase3);
            }

            MessageBox.Show(s);
            mysystem = new BearingMachineModels.SimulationSystem();
        }
コード例 #2
0
        public static void ReadInput(string testCase, ref SimulationSystem simulationSystem)
        {
            string projectPath = System.IO.Directory.GetCurrentDirectory();

            projectPath = projectPath.Remove(projectPath.Length - 10);
            string[] lines = System.IO.File.ReadAllLines(projectPath + "\\TestCases\\" + testCase + ".txt");
            InputData(lines, ref simulationSystem);
        }
コード例 #3
0
        public object Clone()
        {
            SimulationSystem system = (SimulationSystem)MemberwiseClone();

            system.DelayTimeDistribution       = new List <TimeDistribution>(DelayTimeDistribution);
            system.BearingLifeDistribution     = new List <TimeDistribution>(BearingLifeDistribution);
            system.CurrentSimulationTable      = new List <CurrentSimulationCase>(CurrentSimulationTable);
            system.ProposedSimulationTable     = new List <ProposedSimulationCase>(ProposedSimulationTable);
            system.ProposedPerformanceMeasures = (PerformanceMeasures)ProposedPerformanceMeasures.Clone();
            system.CurrentPerformanceMeasures  = (PerformanceMeasures)CurrentPerformanceMeasures.Clone();
            return(system);
        }
コード例 #4
0
        public void GetCurrentMethodSimulation(SimulationSystem SimSystem, SimulationOutput SimOutput)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Index");
            dt.Columns.Add("Life RD");
            dt.Columns.Add("Life");
            dt.Columns.Add("Accumulated Life");
            dt.Columns.Add("Delay RD");
            dt.Columns.Add("Delay");
            Random rnd1 = new Random();
            Random rnd2 = new Random();
            int    NumberOfChangedBearings = 0;
            int    TotalDelayTime          = 0;
            int    start = 0;

            for (int i = 0; i < SimSystem.NumberOfBearings; i++)
            {
                int index            = 1;
                int AccumulatedHours = 0;
                int TotalDelay       = 0;
                while (AccumulatedHours < SimSystem.NumberOfHours)
                {
                    int RndLifeTime  = rnd1.Next(1, SimSystem.BearingLifeDistribution[SimSystem.BearingLifeDistribution.Count - 1].MaxRange);
                    int RndDelayTime = rnd2.Next(1, SimSystem.DelayTimeDistribution[SimSystem.DelayTimeDistribution.Count - 1].MaxRange);
                    int LifeTime     = GetTime(RndLifeTime, SimSystem.BearingLifeDistribution);
                    int DelayTime    = GetTime(RndDelayTime, SimSystem.DelayTimeDistribution);
                    AccumulatedHours += LifeTime;
                    TotalDelay       += DelayTime;
                    CurrentSimulationCase CSC = new CurrentSimulationCase();
                    Bearing bearing           = new Bearing();
                    bearing.Index        = i;
                    bearing.RandomHours  = RndLifeTime;
                    bearing.Hours        = LifeTime;
                    CSC.Bearing          = bearing;
                    CSC.AccumulatedHours = AccumulatedHours;
                    CSC.RandomDelay      = RndDelayTime;
                    CSC.Delay            = DelayTime;
                    SimSystem.CurrentSimulationCases.Add(CSC);
                    dt.Rows.Add(index.ToString(), RndLifeTime.ToString(), LifeTime.ToString(), AccumulatedHours.ToString(), RndDelayTime.ToString(), DelayTime.ToString());
                    index++;
                    NumberOfChangedBearings++;
                }
                dt.Rows.Add('-', '-', '-', '-', '-', TotalDelay.ToString());
                TotalDelayTime += TotalDelay;
                StartAndEnd.Add(new KeyValuePair <int, int>(start, (index - 2) + start));
                start = (index - 2) + start + 1;
            }
            SimOutput.CurrentSimulation            = dt;
            SimOutput.CurrentSimulationPerformance = GetCurrentMethodPerformance(SimSystem, NumberOfChangedBearings, TotalDelayTime);
        }
コード例 #5
0
        DataTable GetProposedMethodPerformance(SimulationSystem SimSystem, int NumberOfChangedBearings, int TotalDelayTime)
        {
            DataTable pdt = new DataTable();

            pdt.Columns.Add("Cost Type");
            pdt.Columns.Add("Value");
            SimSystem.ProposedPerformanceMeasures.BearingCost = (NumberOfChangedBearings * SimSystem.NumberOfBearings) * SimSystem.BearingCost;
            pdt.Rows.Add("Cost of bearings", SimSystem.ProposedPerformanceMeasures.BearingCost.ToString() + '$');
            SimSystem.ProposedPerformanceMeasures.DelayCost = TotalDelayTime * SimSystem.DowntimeCost;
            pdt.Rows.Add("Cost of delay time", SimSystem.ProposedPerformanceMeasures.DelayCost.ToString() + '$');
            SimSystem.ProposedPerformanceMeasures.DowntimeCost = NumberOfChangedBearings * SimSystem.RepairTimeForAllBearings * SimSystem.DowntimeCost;
            pdt.Rows.Add("Cost of downtime during repair", SimSystem.ProposedPerformanceMeasures.DowntimeCost.ToString() + '$');
            SimSystem.ProposedPerformanceMeasures.RepairPersonCost = (NumberOfChangedBearings * SimSystem.RepairTimeForAllBearings) * ((decimal)SimSystem.RepairPersonCost / 60);
            pdt.Rows.Add("Cost of repairpersons", SimSystem.ProposedPerformanceMeasures.RepairPersonCost.ToString() + '$');
            SimSystem.ProposedPerformanceMeasures.TotalCost = SimSystem.ProposedPerformanceMeasures.BearingCost + SimSystem.ProposedPerformanceMeasures.DelayCost + SimSystem.ProposedPerformanceMeasures.DowntimeCost + SimSystem.ProposedPerformanceMeasures.RepairPersonCost;
            pdt.Rows.Add("Total cost", SimSystem.ProposedPerformanceMeasures.TotalCost.ToString() + '$');
            return(pdt);
        }
コード例 #6
0
 public Form3(BearingMachineModels.SimulationSystem mysys)
 {
     mysystem = mysys;
     InitializeComponent();
 }
コード例 #7
0
 public static void load(BearingMachineModels.SimulationSystem mysy)
 {
     mysystem = mysy;
 }
コード例 #8
0
        public void GetProposedMethodSimulation(SimulationSystem SimSystem, SimulationOutput SimOutput)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Index");
            for (int i = 0; i < SimSystem.NumberOfBearings; i++)
            {
                dt.Columns.Add("Bearing " + (i + 1).ToString() + " Life");
            }
            dt.Columns.Add("First Failure");
            dt.Columns.Add("Accumulated Life");
            dt.Columns.Add("Delay RD");
            dt.Columns.Add("Delay");
            Random rnd1 = new Random();
            Random rnd2 = new Random();
            int    NumberOfChangedBearings = 0;
            int    TotalDelayTime          = 0;
            int    AccumulatedHours        = 0;
            int    index = 1;

            while (AccumulatedHours < SimSystem.NumberOfHours)
            {
                List <Bearing> Bearings = new List <Bearing>();
                NumberOfChangedBearings++;
                int MnLife = 99999999;
                for (int i = 0; i < SimSystem.NumberOfBearings; i++)
                {
                    if ((StartAndEnd[i].Key + (index - 1)) <= StartAndEnd[i].Value)
                    {
                        Bearings.Add(SimSystem.CurrentSimulationCases[StartAndEnd[i].Key + (index - 1)].Bearing);
                        if (SimSystem.CurrentSimulationCases[StartAndEnd[i].Key + (index - 1)].Bearing.Hours < MnLife)
                        {
                            MnLife = SimSystem.CurrentSimulationCases[StartAndEnd[i].Key + (index - 1)].Bearing.Hours;
                        }
                    }
                    else
                    {
                        int     RndLifeTime = rnd1.Next(1, SimSystem.BearingLifeDistribution[SimSystem.BearingLifeDistribution.Count - 1].MaxRange);
                        int     LifeTime    = GetTime(RndLifeTime, SimSystem.BearingLifeDistribution);
                        Bearing bearing     = new Bearing();
                        bearing.Index       = i;
                        bearing.RandomHours = RndLifeTime;
                        bearing.Hours       = LifeTime;
                        Bearings.Add(bearing);
                        if (LifeTime < MnLife)
                        {
                            MnLife = LifeTime;
                        }
                    }
                }
                AccumulatedHours += MnLife;
                int RndDelayTime = rnd2.Next(1, SimSystem.DelayTimeDistribution[SimSystem.DelayTimeDistribution.Count - 1].MaxRange);
                int DelayTime    = GetTime(RndDelayTime, SimSystem.DelayTimeDistribution);
                TotalDelayTime += DelayTime;
                ProposedSimulationCase PSC = new ProposedSimulationCase();
                PSC.Bearings         = Bearings;
                PSC.FirstFailure     = MnLife;
                PSC.AccumulatedHours = AccumulatedHours;
                PSC.RandomDelay      = RndDelayTime;
                PSC.Delay            = DelayTime;
                SimSystem.ProposedSimulationCases.Add(PSC);
                DataRow dr = dt.NewRow();
                dr["Index"] = index.ToString();
                for (int i = 0; i < Bearings.Count(); i++)
                {
                    string name = "Bearing " + (i + 1).ToString() + " Life";
                    dr[name] = Bearings[i].Hours.ToString();
                }
                dr["First Failure"]    = MnLife.ToString();
                dr["Accumulated Life"] = AccumulatedHours.ToString();
                dr["Delay RD"]         = RndDelayTime.ToString();
                dr["Delay"]            = DelayTime.ToString();
                dt.Rows.Add(dr);
                index++;
            }
            DataRow rw = dt.NewRow();

            rw["Index"] = "-";
            for (int i = 0; i < SimSystem.NumberOfBearings; i++)
            {
                string name = "Bearing " + (i + 1).ToString() + " Life";
                rw[name] = "-";
            }
            rw["First Failure"]    = "-";
            rw["Accumulated Life"] = "-";
            rw["Delay RD"]         = "-";
            rw["Delay"]            = TotalDelayTime.ToString();
            dt.Rows.Add(rw);
            SimOutput.ProposedSimulation            = dt;
            SimOutput.ProposedSimulationPerformance = GetProposedMethodPerformance(SimSystem, NumberOfChangedBearings, TotalDelayTime);
        }
コード例 #9
0
 public void LoadData(string TestCasePath, SimulationSystem SimSystem)
 {
     string[] lines = System.IO.File.ReadAllLines(TestCasePath);
     for (int i = 0; i < lines.Count(); i++)
     {
         if (lines[i] == "DowntimeCost")
         {
             i++;
             SimSystem.DowntimeCost = Int32.Parse(lines[i]);
         }
         else if (lines[i] == "RepairPersonCost")
         {
             i++;
             SimSystem.RepairPersonCost = Int32.Parse(lines[i]);
         }
         else if (lines[i] == "BearingCost")
         {
             i++;
             SimSystem.BearingCost = Int32.Parse(lines[i]);
         }
         else if (lines[i] == "NumberOfHours")
         {
             i++;
             SimSystem.NumberOfHours = Int32.Parse(lines[i]);
         }
         else if (lines[i] == "NumberOfBearings")
         {
             i++;
             SimSystem.NumberOfBearings = Int32.Parse(lines[i]);
         }
         else if (lines[i] == "RepairTimeForOneBearing")
         {
             i++;
             SimSystem.RepairTimeForOneBearing = Int32.Parse(lines[i]);
         }
         else if (lines[i] == "RepairTimeForAllBearings")
         {
             i++;
             SimSystem.RepairTimeForAllBearings = Int32.Parse(lines[i]);
         }
         else if (lines[i] == "DelayTimeDistribution")
         {
             i++;
             while (lines[i] != "")
             {
                 string[]         dist            = lines[i].Split(',');
                 TimeDistribution TimeDitribution = new TimeDistribution();
                 TimeDitribution.Time        = Int32.Parse(dist[0]);
                 TimeDitribution.Probability = decimal.Parse(dist[1]);
                 SimSystem.DelayTimeDistribution.Add(TimeDitribution);
                 i++;
             }
         }
         else if (lines[i] == "BearingLifeDistribution")
         {
             i++;
             while (i < lines.Count())
             {
                 string[]         dist            = lines[i].Split(',');
                 TimeDistribution TimeDitribution = new TimeDistribution();
                 TimeDitribution.Time        = Int32.Parse(dist[0]);
                 TimeDitribution.Probability = decimal.Parse(dist[1]);
                 SimSystem.BearingLifeDistribution.Add(TimeDitribution);
                 i++;
             }
             break;
         }
     }
 }
コード例 #10
0
        public static void InputData(string[] lines, ref SimulationSystem simulationSystem)
        {
            int stringType = 0;

            char[] delimiters = { ',', ' ' };
            foreach (string line in lines)
            {
                if (line == "\n" || line.Length == 0)
                {
                    continue;
                }
                switch (line)
                {
                case "DowntimeCost":
                    stringType = 1;
                    continue;

                case "RepairPersonCost":
                    stringType = 2;
                    continue;

                case "BearingCost":
                    stringType = 3;
                    continue;

                case "NumberOfHours":
                    stringType = 4;
                    continue;

                case "NumberOfBearings":
                    stringType = 5;
                    continue;

                case "RepairTimeForOneBearing":
                    stringType = 6;
                    continue;

                case "RepairTimeForAllBearings":
                    stringType = 7;
                    continue;

                case "DelayTimeDistribution":
                    stringType = 8;
                    continue;

                case "BearingLifeDistribution":
                    stringType = 9;
                    continue;
                }

                switch (stringType)
                {
                case 1:
                    simulationSystem.DowntimeCost = int.Parse(line);
                    break;

                case 2:
                    simulationSystem.RepairPersonCost = int.Parse(line);
                    break;

                case 3:
                    simulationSystem.BearingCost = int.Parse(line);
                    break;

                case 4:
                    simulationSystem.NumberOfHours = int.Parse(line);
                    break;

                case 5:
                    simulationSystem.NumberOfBearings = int.Parse(line);
                    break;

                case 6:
                    simulationSystem.RepairTimeForOneBearing = int.Parse(line);
                    break;

                case 7:
                    simulationSystem.RepairTimeForAllBearings = int.Parse(line);
                    break;

                default:
                {
                    string[] distributions = line.Split(delimiters);

                    if (distributions.Length > 2)
                    {
                        TimeDistribution timeDistribution = new TimeDistribution();
                        timeDistribution.Time        = int.Parse(distributions[0]);
                        timeDistribution.Probability = decimal.Parse(distributions[2]);

                        switch (stringType)
                        {
                        case 8:
                            simulationSystem.DelayTimeDistribution.Add(timeDistribution);
                            break;

                        case 9:
                            simulationSystem.BearingLifeDistribution.Add(timeDistribution);
                            break;
                        }
                    }
                    break;
                }
                }
            }
        }