private void Construct_proposedPolicy() { int accHours = 0; int order = 1; while (true) { ProposedSimulationCase tmpSimulationCase = new ProposedSimulationCase(); List <Bearing> tmpbearings = new List <Bearing>(); List <int> Hours = new List <int>(); for (int i = 0; i < _simulationSystem.NumberOfBearings; i++) { Bearing tmpBearing = new Bearing(); tmpBearing.Hours = Get_HoursOfind(order, i + 1); tmpbearings.Add(tmpBearing); Hours.Add(tmpBearing.Hours); } order++; Hours.Sort(); tmpSimulationCase.Bearings = tmpbearings; tmpSimulationCase.FirstFailure = Hours[0]; accHours += tmpSimulationCase.FirstFailure; tmpSimulationCase.AccumulatedHours = accHours; tmpSimulationCase.RandomDelay = _rnd.Next(1, 11); tmpSimulationCase.Delay = Get_Delay(tmpSimulationCase.RandomDelay); _proposedSimulationCases.Add(tmpSimulationCase); if (accHours >= _simulationSystem.NumberOfHours) { break; } } _simulationSystem.ProposedSimulationCases = _proposedSimulationCases; PerformanceMeasures tmpMeasures = new PerformanceMeasures(); tmpMeasures.BearingCost = (_simulationSystem.NumberOfBearings * _simulationSystem.ProposedSimulationCases.Count) * _simulationSystem.BearingCost; tmpMeasures.DelayCost = Get_Sum_proposed_Delay(_simulationSystem.ProposedSimulationCases) * _simulationSystem.DowntimeCost; tmpMeasures.DowntimeCost = _simulationSystem.ProposedSimulationCases.Count * _simulationSystem.RepairTimeForAllBearings * _simulationSystem.DowntimeCost; Decimal val = Convert.ToDecimal(_simulationSystem.RepairPersonCost) / 60; tmpMeasures.RepairPersonCost = _simulationSystem.ProposedSimulationCases.Count * _simulationSystem.RepairTimeForAllBearings * val; tmpMeasures.TotalCost = tmpMeasures.BearingCost + tmpMeasures.DelayCost + tmpMeasures.DowntimeCost + tmpMeasures.RepairPersonCost; _simulationSystem.ProposedPerformanceMeasures = tmpMeasures; TotlBearingCost_lbl1.Text = tmpMeasures.BearingCost.ToString(CultureInfo.CurrentCulture); TotlDelayCost_lbl1.Text = tmpMeasures.DelayCost.ToString(CultureInfo.CurrentCulture); TotlDownCost_lbl1.Text = tmpMeasures.DowntimeCost.ToString(CultureInfo.CurrentCulture); TotlRepairPerson_lbl1.Text = tmpMeasures.RepairPersonCost.ToString(CultureInfo.CurrentCulture); TotlCost_lbl1.Text = tmpMeasures.TotalCost.ToString(CultureInfo.CurrentCulture); }
public static void calculate_proposed_solution(DataGridView dataGridView4) { dataGridView4.Columns.Add("Count", "Count"); for (int i = 0; i < mysystem.NumberOfBearings; i++) { dataGridView4.Columns.Add("Bearing" + (i + 1).ToString(), "Bearing" + (i + 1).ToString()); } dataGridView4.Columns.Add("First Failure", "First Failure"); dataGridView4.Columns.Add("Accumelated Life", "Accumelated Life"); dataGridView4.Columns.Add("Random Delay", "Random Delay"); dataGridView4.Columns.Add("Delay", "Delay"); List <List <Bearing> > total_bears = new List <List <Bearing> >(); List <Bearing> tmp = new List <Bearing>(); int pre = 1; int max_len = 0; for (int i = 0; i < mysystem.CurrentSimulationCases.Count; i++) { if (mysystem.CurrentSimulationCases[i].Bearing.Index != pre) { total_bears.Add(tmp); max_len = Math.Max(max_len, tmp.Count()); pre = mysystem.CurrentSimulationCases[i].Bearing.Index; tmp = new List <Bearing>(); } tmp.Add(mysystem.CurrentSimulationCases[i].Bearing); } total_bears.Add(tmp); max_len = Math.Max(max_len, tmp.Count()); int total_time = 0; Random r = new Random(); mysystem.ProposedSimulationCases = new List <ProposedSimulationCase>(); for (int j = 0; total_time < mysystem.NumberOfHours; j++) { ProposedSimulationCase psc = new ProposedSimulationCase(); List <string> s = new List <string>(); s.Add(j.ToString()); int minn = int.MaxValue; for (int i = 0; i < mysystem.NumberOfBearings; i++) { if (j < total_bears[i].Count()) { psc.Bearings.Add(total_bears[i][j]); if (total_bears[i][j].Hours < minn) { minn = total_bears[i][j].Hours; } } else { Bearing Bearing_tmp = new Bearing(); Bearing_tmp.Index = i + 1; Bearing_tmp.RandomHours = r.Next(1, 100); for (int k = 0; k < mysystem.BearingLifeDistribution.Count; k++) { if (Bearing_tmp.RandomHours >= mysystem.BearingLifeDistribution[k].MinRange && Bearing_tmp.RandomHours <= mysystem.BearingLifeDistribution[k].MaxRange) { Bearing_tmp.Hours = mysystem.BearingLifeDistribution[k].Time; } } if (Bearing_tmp.Hours < minn) { minn = Bearing_tmp.Hours; } psc.Bearings.Add(Bearing_tmp); } } psc.FirstFailure = minn; total_time += psc.FirstFailure; if (mysystem.ProposedSimulationCases.Count() == 0) { psc.AccumulatedHours = psc.FirstFailure; } else { psc.AccumulatedHours = psc.FirstFailure + mysystem.ProposedSimulationCases[mysystem.ProposedSimulationCases.Count() - 1].AccumulatedHours; } int random_tmp = r.Next(1, 100); int delay_tmp = 0; for (int l = 0; l < mysystem.DelayTimeDistribution.Count; l++) { if (random_tmp >= mysystem.DelayTimeDistribution[l].MinRange && random_tmp <= mysystem.DelayTimeDistribution[l].MaxRange) { delay_tmp = mysystem.DelayTimeDistribution[l].Time; } } psc.RandomDelay = random_tmp; psc.Delay = delay_tmp; mysystem.ProposedSimulationCases.Add(psc); } int total_delay = 0; for (int i = 0; i < mysystem.ProposedSimulationCases.Count(); i++) { List <string> s = new List <string>(); s.Add((i + 1).ToString()); for (int j = 0; j < mysystem.ProposedSimulationCases[i].Bearings.Count(); j++) { s.Add(mysystem.ProposedSimulationCases[i].Bearings[j].Hours.ToString()); } s.Add(mysystem.ProposedSimulationCases[i].FirstFailure.ToString()); s.Add(mysystem.ProposedSimulationCases[i].AccumulatedHours.ToString()); s.Add(mysystem.ProposedSimulationCases[i].RandomDelay.ToString()); s.Add(mysystem.ProposedSimulationCases[i].Delay.ToString()); dataGridView4.Rows.Add(s.ToArray()); total_delay += mysystem.ProposedSimulationCases[i].Delay; } mysystem.ProposedPerformanceMeasures.BearingCost = mysystem.ProposedSimulationCases.Count() * mysystem.NumberOfBearings * mysystem.BearingCost; mysystem.ProposedPerformanceMeasures.DelayCost = total_delay * mysystem.DowntimeCost; mysystem.ProposedPerformanceMeasures.DowntimeCost = mysystem.ProposedSimulationCases.Count() * mysystem.RepairTimeForAllBearings * mysystem.DowntimeCost; mysystem.ProposedPerformanceMeasures.RepairPersonCost = mysystem.ProposedSimulationCases.Count() * mysystem.RepairTimeForAllBearings * mysystem.RepairPersonCost / 60; mysystem.ProposedPerformanceMeasures.TotalCost = mysystem.ProposedPerformanceMeasures.BearingCost + mysystem.ProposedPerformanceMeasures.DelayCost + mysystem.ProposedPerformanceMeasures.DowntimeCost + mysystem.ProposedPerformanceMeasures.RepairPersonCost; }
void BuildTable2() { List <List <Bearing> > bearingsCategorized = new List <List <Bearing> >(); int bearingIDX = 0; foreach (CurrentSimulationCase csc in simulationSystem.CurrentSimulationTable) { Bearing b = csc.Bearing; if (b.Index != bearingIDX) { bearingsCategorized.Add(new List <Bearing>()); bearingIDX++; } bearingsCategorized[bearingsCategorized.Count - 1].Add(b); } int delayt = 0; Random rnd = new Random(); for (int life = 0, j = 0; life < simulationSystem.NumberOfHours; j++) { ProposedSimulationCase psc = new ProposedSimulationCase(); psc.RandomDelay = rnd.Next(1, 100); psc.Delay = binarySearch(psc.RandomDelay, simulationSystem.DelayTimeDistribution); delayt += psc.Delay; psc.AccumulatedHours = life; psc.FirstFailure = int.MaxValue; for (bearingIDX = 0; bearingIDX < simulationSystem.NumberOfBearings; bearingIDX++) { if (bearingsCategorized[bearingIDX].Count <= j) { Bearing b = new Bearing(); b.Index = bearingIDX + 1; b.RandomHours = rnd.Next(1, 100); b.Hours = binarySearch(b.RandomHours, simulationSystem.BearingLifeDistribution); psc.Bearings.Add(b); psc.FirstFailure = Math.Min(b.Hours, psc.FirstFailure); } else { psc.Bearings.Add(bearingsCategorized[bearingIDX][j]); psc.FirstFailure = Math.Min(bearingsCategorized[bearingIDX][j].Hours, psc.FirstFailure); } } psc.AccumulatedHours += psc.FirstFailure; life = psc.AccumulatedHours; simulationSystem.ProposedSimulationTable.Add(psc); } simulationSystem.ProposedPerformanceMeasures.BearingCost = simulationSystem.ProposedSimulationTable.Count * simulationSystem.BearingCost * simulationSystem.NumberOfBearings; simulationSystem.ProposedPerformanceMeasures.DelayCost = delayt * simulationSystem.DowntimeCost; simulationSystem.ProposedPerformanceMeasures.DowntimeCost = simulationSystem.ProposedSimulationTable.Count * simulationSystem.RepairTimeForAllBearings * simulationSystem.DowntimeCost; simulationSystem.ProposedPerformanceMeasures.RepairPersonCost = (decimal)simulationSystem.ProposedSimulationTable.Count * simulationSystem.RepairTimeForAllBearings * simulationSystem.RepairPersonCost / 60; simulationSystem.ProposedPerformanceMeasures.TotalCost = simulationSystem.ProposedPerformanceMeasures.BearingCost + simulationSystem.ProposedPerformanceMeasures.DelayCost + simulationSystem.ProposedPerformanceMeasures.DowntimeCost + simulationSystem.ProposedPerformanceMeasures.RepairPersonCost; dataGridView2.DataSource = simulationSystem.ProposedSimulationTable; for (int i = 1; i <= simulationSystem.NumberOfBearings; i++) { dataGridView3.Columns.Add("Bearing" + i.ToString() + "Life", "Bearing " + i.ToString() + " Life"); } dataGridView3.RowCount = simulationSystem.ProposedSimulationTable.Count; for (int i = 0; i < simulationSystem.ProposedSimulationTable.Count; i++) { for (int j = 0; j < simulationSystem.NumberOfBearings; j++) { dataGridView3[j, i].Value = simulationSystem.ProposedSimulationTable[i].Bearings[j].Hours; } } porBearing.Text = porBearing.Text + ": " + simulationSystem.ProposedPerformanceMeasures.BearingCost.ToString(); porCost.Text = porCost.Text + ": " + simulationSystem.ProposedPerformanceMeasures.TotalCost.ToString(); porDelay.Text = porDelay.Text + ": " + simulationSystem.ProposedPerformanceMeasures.DelayCost.ToString(); porDown.Text = porDown.Text + ": " + simulationSystem.ProposedPerformanceMeasures.DowntimeCost.ToString(); porRepair.Text = porRepair.Text + ": " + simulationSystem.ProposedPerformanceMeasures.RepairPersonCost.ToString(); }
public void fillProposedSimlationTable() { int i = 0, accHours = 0; Random randomNum = new Random(); while (true) { ProposedSimulationCase proposedSimulationCase = new ProposedSimulationCase(); int sum = 0, generalSum = 0; int index = 1; List <Bearing> currentBearing = new List <Bearing>(); ///////////////////////////////////////////first bearing//////////////////////////////////////// if (i < countOfBearings[0]) { currentBearing.Add(simSys.CurrentSimulationTable[i].Bearing); } else { Bearing bearing = new Bearing(); index = 1; bearing.RandomHours = randomNum.Next(1, 101); bearing.Index = index; for (int k = 0; k < simSys.BearingLifeDistribution.Count(); k++) { if (bearing.RandomHours >= simSys.BearingLifeDistribution[k].MinRange && bearing.RandomHours <= simSys.BearingLifeDistribution[k].MaxRange) { bearing.Hours = simSys.BearingLifeDistribution[k].Time; break; } } currentBearing.Add(bearing); } /////////////////////////////////////////////rest of bearings////////////////////////////////////// generalSum += countOfBearings[0]; for (int j = 0; j < simSys.NumberOfBearings - 1; j++) { sum += countOfBearings[j]; generalSum += countOfBearings[j + 1]; if (i + sum < generalSum) { currentBearing.Add(simSys.CurrentSimulationTable[i + sum].Bearing); } else { Bearing bearing = new Bearing(); index = j + 2; bearing.RandomHours = randomNum.Next(1, 101); bearing.Index = index; for (int k = 0; k < simSys.BearingLifeDistribution.Count(); k++) { if (bearing.RandomHours >= simSys.BearingLifeDistribution[k].MinRange && bearing.RandomHours <= simSys.BearingLifeDistribution[k].MaxRange) { bearing.Hours = simSys.BearingLifeDistribution[k].Time; break; } } currentBearing.Add(bearing); } } /////////////////////////////////////////////////////delay///////////////////////////////////// proposedSimulationCase.RandomDelay = randomNum.Next(1, 100); for (int l = 0; l < simSys.DelayTimeDistribution.Count(); l++) { if (proposedSimulationCase.RandomDelay >= simSys.DelayTimeDistribution[l].MinRange && proposedSimulationCase.RandomDelay <= simSys.DelayTimeDistribution[l].MaxRange) { proposedSimulationCase.Delay = simSys.DelayTimeDistribution[l].Time; break; } } totalDelayProposed += proposedSimulationCase.Delay; //////////////////////////////////////////////first failure/////////////////////////////////////// int minHour = int.MaxValue; for (int l = 0; l < currentBearing.Count; l++) { if (currentBearing[l].Hours < minHour) { minHour = currentBearing[l].Hours; } } proposedSimulationCase.Bearings = currentBearing; proposedSimulationCase.FirstFailure = minHour; accHours += minHour; proposedSimulationCase.AccumulatedHours = accHours; simSys.ProposedSimulationTable.Add(proposedSimulationCase); if (proposedSimulationCase.AccumulatedHours >= simSys.NumberOfHours) { break; } i++; } }