public void ProposedSimulation() { int totalAccumlatedHours = 0; int row = 0; while (totalAccumlatedHours < NumberOfHours) { ProposedSimulationCase proposedSimulationCase = new ProposedSimulationCase(); proposedSimulationCase.FirstFailure = BearingLifeDistribution[BearingLifeDistribution.Count - 1].Time + 100; List <Bearing> currentBearings = new List <Bearing>(); for (int i = 0; i < NumberOfBearings; i++) { Bearing bearing = new Bearing(); if (row < bearingMaximumChanges[i]) { bearing = bearings[i][row]; } else { //Generate new bearing bearing.Index = i + 1; Tuple <int, int> lifeHours = HelperFunctions.GetBearingRandomNumbers("Life", BearingLifeDistribution); bearing.RandomHours = lifeHours.Item1; bearing.Hours = lifeHours.Item2; } if (bearing.Hours < proposedSimulationCase.FirstFailure) { proposedSimulationCase.FirstFailure = bearing.Hours; } currentBearings.Add(bearing); } proposedSimulationCase.Bearings = currentBearings; TotalProposedBearings += currentBearings.Count; proposedBearingsSet += 1; Tuple <int, int> delayVariables = HelperFunctions.GetBearingRandomNumbers("Delay", DelayTimeDistribution); proposedSimulationCase.RandomDelay = delayVariables.Item1; proposedSimulationCase.Delay = delayVariables.Item2; totalProposedDelayTime += proposedSimulationCase.Delay; totalAccumlatedHours += proposedSimulationCase.FirstFailure; proposedSimulationCase.AccumulatedHours = totalAccumlatedHours; ProposedSimulationTable.Add(proposedSimulationCase); row++; } }
public void sec_step(List <Bearing>[] mylist) { Random rnd = new Random(); int acc = 0; for (int j = 0; acc < NumberOfHours; j++) { ProposedSimulationCase prp = new ProposedSimulationCase(); prp.Bearings = new List <Bearing>(); int first_fail = NumberOfHours; for (int k = 0; k < NumberOfBearings; k++) { if (mylist[k].Count > j) { prp.Bearings.Add(mylist[k][j]); if (first_fail > prp.Bearings[k].Hours) { first_fail = prp.Bearings[k].Hours; } } else { Bearing curbear = new Bearing(); curbear.Index = k + 1; curbear.RandomHours = rnd.Next(1, 100); curbear.Hours = life_dist(curbear.RandomHours); prp.Bearings.Add(curbear); if (first_fail > prp.Bearings[k].Hours) { first_fail = prp.Bearings[k].Hours; } } } prp.AccumulatedHours = acc; prp.FirstFailure = first_fail; acc += first_fail; prp.AccumulatedHours = acc; prp.RandomDelay = rnd.Next(1, 100); prp.Delay = delay_dist(prp.RandomDelay); ProposedPerformanceMeasures.DelayCost += (decimal)prp.Delay * DowntimeCost; ProposedSimulationTable.Add(prp); } ProposedPerformanceMeasures.BearingCost = (decimal)ProposedSimulationTable.Count * NumberOfBearings * BearingCost; ProposedPerformanceMeasures.DowntimeCost = (decimal)ProposedSimulationTable.Count * RepairTimeForAllBearings * DowntimeCost; decimal nrcost = (decimal)RepairPersonCost / 60; ProposedPerformanceMeasures.RepairPersonCost = (decimal)(ProposedSimulationTable.Count * RepairTimeForAllBearings) * nrcost; ProposedPerformanceMeasures.TotalCost = (decimal)ProposedPerformanceMeasures.BearingCost + ProposedPerformanceMeasures.DelayCost + ProposedPerformanceMeasures.DowntimeCost + ProposedPerformanceMeasures.RepairPersonCost; }
private void runProposedPolicy() { int c = 0, hours = 0; for (int i = 0; c < NumberOfHours; i++) { // need to add more Random numbers ProposedSimulationCase proposedSimulationCase = new ProposedSimulationCase(); for (int j = 0; j < NumberOfBearings; j++) { addRandomNumber(j, i); proposedSimulationCase.Bearings.Add(getBearing(j, i)); } proposedSimulationCase.FirstFailure = getFirstFaliure(proposedSimulationCase.Bearings); c += proposedSimulationCase.FirstFailure; proposedSimulationCase.AccumulatedHours = c; proposedSimulationCase.RandomDelay = r.Next(1, 101); proposedSimulationCase.Delay = getDelay(proposedSimulationCase.RandomDelay); ProposedSimulationTable.Add(proposedSimulationCase); } }
public void fillSimulationTableForProposed() { int SumOfDelayTime = 0; int min = 1000000; Random rand = new Random(); ProposedSimulationCase row = new ProposedSimulationCase(); for (int j = 0; j < NumberOfBearings; j++) { Bearing bearing = new Bearing(); bearing.Index = j + 1; bearing.RandomHours = CurrentSimulationTable[AccumulatedSetsNumbers[j]].Bearing.RandomHours; bearing.Hours = CurrentSimulationTable[AccumulatedSetsNumbers[j]].Bearing.Hours; row.Bearings.Add(bearing); if (min > bearing.Hours) { min = bearing.Hours; } } row.FirstFailure = min; row.AccumulatedHours = row.FirstFailure; row.RandomDelay = rand.Next(1, 100); row.Delay = SearchForHours(row.RandomDelay, DelayTimeDistribution); ProposedSimulationTable.Add(row); SumOfDelayTime += row.Delay; min = 100000; int i = 1; while (ProposedSimulationTable[i - 1].AccumulatedHours <= NumberOfHours) { row = new ProposedSimulationCase(); for (int j = 0; j < NumberOfBearings; j++) { Bearing bearing = new Bearing(); bearing.Index = j + 1; if (AccumulatedSetsNumbers[j] + i < AccumulatedSetsNumbers[j + 1]) { bearing.RandomHours = CurrentSimulationTable[AccumulatedSetsNumbers[j] + i].Bearing.RandomHours; bearing.Hours = CurrentSimulationTable[AccumulatedSetsNumbers[j] + i].Bearing.Hours; row.Bearings.Add(bearing); } else { bearing.RandomHours = rand.Next(1, 100); bearing.Hours = SearchForHours(bearing.RandomHours, BearingLifeDistribution); row.Bearings.Add(bearing); } if (min > bearing.Hours) { min = bearing.Hours; } } row.FirstFailure = min; row.AccumulatedHours = row.FirstFailure + ProposedSimulationTable[i - 1].AccumulatedHours; row.RandomDelay = rand.Next(1, 100); row.Delay = SearchForHours(row.RandomDelay, DelayTimeDistribution); ProposedSimulationTable.Add(row); SumOfDelayTime += row.Delay; min = 100000; i++; } ProposedPerformanceMeasures.BearingCost = Convert.ToDecimal(ProposedSimulationTable.Count) * NumberOfBearings * Convert.ToDecimal(BearingCost); ProposedPerformanceMeasures.DelayCost = Convert.ToDecimal(SumOfDelayTime) * Convert.ToDecimal(DowntimeCost); ProposedPerformanceMeasures.DowntimeCost = Convert.ToDecimal(ProposedSimulationTable.Count) * Convert.ToDecimal(RepairTimeForAllBearings) * Convert.ToDecimal(DowntimeCost); ProposedPerformanceMeasures.RepairPersonCost = Convert.ToDecimal(ProposedSimulationTable.Count) * Convert.ToDecimal(RepairTimeForAllBearings) * (Convert.ToDecimal(RepairPersonCost) / Convert.ToDecimal(60)); ProposedPerformanceMeasures.TotalCost = ProposedPerformanceMeasures.BearingCost + ProposedPerformanceMeasures.DelayCost + ProposedPerformanceMeasures.DowntimeCost + ProposedPerformanceMeasures.RepairPersonCost; }
public void fill_ProposedSimulationTable() { List <List <Bearing> > listOflifetimeBearings = new List <List <Bearing> >(); Dictionary <int, int> dic_bearings = new Dictionary <int, int>(); List <Bearing> currentBearings; Random rand = new Random(); int index_currentStable; int index_bearings; index_currentStable = 0; //to fill listOflifetimeBearings list for (int i = 1; i <= this.NumberOfBearings; i++) { //num of changes in one bearing index_bearings = 0; listOflifetimeBearings.Add(new List <Bearing>()); while (this.CurrentSimulationTable[index_currentStable].Bearing.Index == i) { listOflifetimeBearings[i - 1].Add(new Bearing()); listOflifetimeBearings[i - 1][index_bearings] = CurrentSimulationTable[index_currentStable].Bearing; index_bearings++; if (index_currentStable != CurrentSimulationTable.Count - 1) { index_currentStable++; } else { break; } } } // fill dictionary with index of the bearing as key & min value of changes in bearing as value for (int i = 1; i <= listOflifetimeBearings.Count; i++) { dic_bearings.Add(i, listOflifetimeBearings[i - 1].Count); } int count = dic_bearings.Values.Max(); int acc_hours = 0; for (int i = 0; acc_hours < NumberOfHours; i++) { currentBearings = new List <Bearing>(); for (int j = 0; j < this.NumberOfBearings; j++) { if (dic_bearings[j + 1] == 0) { int ran_hours = rand.Next(1, 101); System.Threading.Thread.Sleep(10); for (int k = 0; k < BearingLifeDistribution.Count; k++) { if (ran_hours <= BearingLifeDistribution[k].MaxRange && ran_hours >= BearingLifeDistribution[k].MinRange) { currentBearings.Add(new Bearing()); currentBearings[j].Hours = BearingLifeDistribution[k].Time; currentBearings[j].RandomHours = ran_hours; currentBearings[j].Index = j + 1; break; } } } else { currentBearings.Add(new Bearing()); currentBearings[j] = listOflifetimeBearings[j][i]; dic_bearings[j + 1]--; //listOflifetimeBearings[j].RemoveAt(i); } } if (i != 0) { ProposedSimulationTable.Add(new ProposedSimulationCase()); ProposedSimulationTable[i].fill_ProposedSimulationRow(currentBearings, ProposedSimulationTable[i - 1].AccumulatedHours, this.DelayTimeDistribution); acc_hours = ProposedSimulationTable[i].AccumulatedHours; } else { ProposedSimulationTable.Add(new ProposedSimulationCase()); ProposedSimulationTable[i].fill_ProposedSimulationRow(currentBearings, 0, this.DelayTimeDistribution); } } }
public void Proposed_table() { TotalDelayTime = 0; Random rd = new Random(); Random rd2 = new Random(); int k = 0; bool[] take = new bool[CurrentSimulationTable.Count]; bool cont = true; int bearing_index = 1; bool find = false; /* int[,] bearing_array = new int[CurrentSimulationTable.Count, NumberOfBearings]; * * for (int g=0;g<CurrentSimulationTable.Count;g++) * { * for (int y=0 ; y < NumberOfBearings ; y++) * { * if(CurrentSimulationTable[g].Bearing.Index==y+1) * { * bearing_array[g,y] = CurrentSimulationTable[g].Bearing.Hours; * } * * } * * }*/ while (cont == true) { ProposedSimulationTable.Add(new ProposedSimulationCase()); bearing_index = 1; find = false; int min = 100000000; for (int i = 0; i < NumberOfBearings; i++) { //ProposedSimulationTable[i].Bearings.Add(new Bearing()); find = false; for (int y = 0; y < CurrentSimulationTable.Count && find == false; y++) { if (CurrentSimulationTable[y].Bearing.Index == bearing_index && take[y] == false) { ProposedSimulationTable[k].Bearings.Add(CurrentSimulationTable[y].Bearing); take[y] = true; find = true; bearing_index++; break; } } if (find == false) { ProposedSimulationTable[k].Bearings.Add(new Bearing()); ProposedSimulationTable[k].Bearings[i].RandomHours = rd.Next(1, 100); ProposedSimulationTable[k].Bearings[i].Index = bearing_index; bearing_index++; for (int y = 0; y < BearingLifeDistribution.Count; y++) { if (BearingLifeDistribution[y].MinRange <= ProposedSimulationTable[k].Bearings[i].RandomHours && BearingLifeDistribution[y].MaxRange >= ProposedSimulationTable[k].Bearings[i].RandomHours) { ProposedSimulationTable[k].Bearings[i].Hours = BearingLifeDistribution[y].Time; break; } } } if (ProposedSimulationTable[k].Bearings[i].Hours < min) { min = ProposedSimulationTable[k].Bearings[i].Hours; } } ProposedSimulationTable[k].FirstFailure = min; if (k == 0) { ProposedSimulationTable[k].AccumulatedHours = ProposedSimulationTable[k].FirstFailure; } else { ProposedSimulationTable[k].AccumulatedHours = ProposedSimulationTable[k].FirstFailure + ProposedSimulationTable[k - 1].AccumulatedHours; } ProposedSimulationTable[k].RandomDelay = rd2.Next(1, 100); for (int p = 0; p < DelayTimeDistribution.Count; p++) { if (ProposedSimulationTable[k].RandomDelay >= DelayTimeDistribution[p].MinRange && ProposedSimulationTable[k].RandomDelay <= DelayTimeDistribution[p].MaxRange) { ProposedSimulationTable[k].Delay = DelayTimeDistribution[p].Time; TotalDelayTime += ProposedSimulationTable[k].Delay; break; } } if (ProposedSimulationTable[k].AccumulatedHours >= NumberOfHours) { cont = false; } k++; } }