private void CalculateOrbit() { // clear lists and initialize position and velocity _positions.Clear(); // temporary variables used to create positions Vector3 acceleration; Vector3 velocity; // init pos vel depending on if we're in the editor or not. _positions.Add(_this_body.position); if (Application.isPlaying) { velocity = _this_body.velocity; } else { velocity = _this_body.initialVelocity; } _initial_velocity = velocity; // iterate forward using the simulation system and future timesteps for (int i = 0; i < time_into_future; i++) { acceleration = SimulationSystem.CalculateAcceleration(_positions[i], _this_body); // get current acceleration velocity = velocity + (acceleration * Universe.physicsTimeStep); // update velocity _positions.Add(_positions[i] + (velocity * Universe.physicsTimeStep)); // add new position } }
private void Simulate_Click(object sender, EventArgs e) { if (mysys == null) { MessageBox.Show("Error No Input !!!"); } else { Simulator Simulator_Case = new Simulator(mysys); Simulator_Case.Run(); SimulationTableForm simulationTable = new SimulationTableForm(mysys); simulationTable.Show(); string test_res = ""; string s = comboBox1.Text; if (s == "TestCase1") { test_res = TestingManager.Test(mysys, Constants.FileNames.TestCase1); } else if (s == "TestCase2") { test_res = TestingManager.Test(mysys, Constants.FileNames.TestCase2); } else if (s == "TestCase3") { test_res = TestingManager.Test(mysys, Constants.FileNames.TestCase3); } else if (s == "TestCase4") { test_res = TestingManager.Test(mysys, Constants.FileNames.TestCase4); } MessageBox.Show(test_res); mysys = new SimulationSystem(); } }
private static void RecieveData(Socket socket, SimulationSystem system) { byte[] buffer = new byte[1024]; int n = socket.Receive(buffer); system.DowntimeCost = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); n = socket.Receive(buffer); system.RepairPersonCost = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); n = socket.Receive(buffer); system.BearingCost = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); n = socket.Receive(buffer); system.NumberOfHours = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); n = socket.Receive(buffer); system.NumberOfBearings = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); n = socket.Receive(buffer); system.RepairTimeForOneBearing = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); n = socket.Receive(buffer); system.RepairTimeForAllBearings = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); n = socket.Receive(buffer); foreach (List <TimeDistribution> l in new List <TimeDistribution>[] { system.DelayTimeDistribution, system.BearingLifeDistribution }) { int len = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); for (int i = 0; i < len; i++) { TimeDistribution distribution = new TimeDistribution(); n = socket.Receive(buffer); int time = int.Parse(Encoding.ASCII.GetString(buffer, 0, n)); n = socket.Receive(buffer); decimal probability = decimal.Parse(Encoding.ASCII.GetString(buffer, 0, n)); distribution.Time = time; distribution.Probability = probability; l.Add(distribution); } } }
SimulationSystem LoadFromUI() { SimulationSystem system = new SimulationSystem() { OrderUpTo = (int)FIPOrderUpTo.Value, ReviewPeriod = (int)FIPReviewPeriod.Value, StartInventoryQuantity = (int)FIPStartingInventoryQuantity.Value, StartLeadDays = (int)FIPStartLeadDays.Value, StartOrderQuantity = (int)FIPStartOrderQuantity.Value, NumberOfDays = (int)FIPNumberOfDays.Value }; KeyValuePair <List <Distribution>, DataGridView>[] list = new KeyValuePair <List <Distribution>, DataGridView>[] { new KeyValuePair <List <Distribution>, DataGridView>(system.DemandDistribution, SIPDemandDistribution), new KeyValuePair <List <Distribution>, DataGridView>(system.LeadDaysDistribution, SIPLeadDaysDistribution) }; foreach (var v in list) { for (int i = 0; i < v.Value.Rows.Count - 1; i++) { DataGridViewRow row = v.Value.Rows[i]; v.Key.Add(new Distribution() { Value = int.Parse((string)row.Cells[0].Value), Probability = decimal.Parse((string)row.Cells[1].Value) }); } } return(system); }
/// <summary> /// Runs the simulation concurrently for this instance of Igniter class /// </summary> /// <param name="system">System to be simulated</param> /// <param name="rnd">Random number generator instance</param> private void ParallelRunStarter(SimulationSystem system, Random rnd = null) { this.rnd = rnd; CurrentSystem = system; if (RunningMode == Enums.RunningMode.FullRun) { WorkList = new SimulationCase[CurrentSystem.NumOfRecords]; } Thread[] threads = new Thread[Environment.ProcessorCount]; for (int i = 0; i < Environment.ProcessorCount; i++) { threads[i] = new Thread(new ParameterizedThreadStart(ParallelRunHelper)) { Name = "Parallel Run #" + i.ToString() + " - " + GetHashCode().ToString() }; threads[i].Start(i); } foreach (Thread t in threads) { t.Join(); } if (RunningMode == Enums.RunningMode.FullRun) { CurrentSystem.SimulationTable = new List <SimulationCase>(WorkList); } }
void PutOnUI(SimulationSystem system) { ClearUI(); FIPOrderUpTo.Value = system.OrderUpTo; FIPReviewPeriod.Value = system.ReviewPeriod; FIPStartingInventoryQuantity.Value = system.StartInventoryQuantity; FIPStartLeadDays.Value = system.StartLeadDays; FIPStartOrderQuantity.Value = system.StartOrderQuantity; FIPNumberOfDays.Value = system.NumberOfDays; KeyValuePair <List <Distribution>, DataGridView>[] list = new KeyValuePair <List <Distribution>, DataGridView>[] { new KeyValuePair <List <Distribution>, DataGridView>(system.DemandDistribution, SIPDemandDistribution), new KeyValuePair <List <Distribution>, DataGridView>(system.LeadDaysDistribution, SIPLeadDaysDistribution) }; foreach (var v in list) { foreach (Distribution distribution in v.Key) { DataGridViewRow row = new DataGridViewRow(); row.Cells.Add(new DataGridViewTextBoxCell() { Value = distribution.Value.ToString() }); row.Cells.Add(new DataGridViewTextBoxCell() { Value = distribution.Probability.ToString() }); v.Value.Rows.Add(row); } } }
/// <summary> /// Clean code i guess... /// </summary> static private SimulationCase GenerateCase(SimulationSystem system, Inventory inventory, int Day) { int R1 = rnd.Next(1, 100); int CurrentDemand = CalculateRandomValue(system.DemandDistribution, R1); int CarryOverShortage = 0; if (inventory.CurrentOrder != null && inventory.CurrentOrder.DueDate == Day) { CarryOverShortage = Math.Min(inventory.Quantity, 0) * -1; inventory.Quantity = Math.Max(inventory.Quantity, 0) + inventory.CurrentOrder.Quantity; inventory.CurrentOrder = null; } SimulationCase Case = new SimulationCase() { Day = Day + 1, Cycle = (Day / system.ReviewPeriod) + 1, BeginningInventory = Math.Max(0, inventory.Quantity), DayWithinCycle = (Day % system.ReviewPeriod) + 1, RandomDemand = R1, Demand = CurrentDemand, EndingInventory = Math.Max(0, inventory.Quantity - CurrentDemand - CarryOverShortage), ShortageQuantity = Math.Max(0, CarryOverShortage + CurrentDemand - inventory.Quantity) }; inventory.Quantity -= CurrentDemand + CarryOverShortage; return(Case); }
public static void RenderCurrentState(SimulationSystem simulationSystem) { var currentRender = new List <List <char> >(); for (var i = 0; i < 50; i++) { currentRender.Add(new List <char>()); for (var j = 0; j < 50; j++) { currentRender[i].Add(' '); } } if (oldRender == null) { oldRender = CopyList(currentRender); } Console.CursorVisible = false; Spinner.Turn(); RenderWarehouse(simulationSystem, currentRender); RenderEmployees(simulationSystem, currentRender); RenderOpenPickingTours(simulationSystem); RenderWarehouseDimensions(simulationSystem); RenderWarehouseDelta(currentRender); oldRender = CopyList(currentRender); }
/// <summary> /// Runs the Simulation and fills the required outputs /// </summary> /// <param name="System">The system to be simulated</param> static public async Task StartSimulation(SimulationSystem System) { await Task.Run(() => { SimulationMain(System); }); }
private void Simulate_Click(object sender, EventArgs e) { SimulationSystem SS = new SimulationSystem(); if (!Imported) { SS = FormulateSimulattor(); } else { SS = ReadTestCase(DirCase); } SS.BeginSimulation(); //string TestRes = TestingManager.Test(SS, Constants.FileNames.TestCase1); //MessageBox.Show(TestRes); this.Text = "News Paper Problem - Home"; SimulationTable ST = new SimulationTable(SS); ST.Show(); }
void FormulateFormView(SimulationSystem SS) { TextBoxes["Number of NewsPapers"].Text = SS.NumOfNewspapers.ToString(); TextBoxes["Number Of Records"].Text = SS.NumOfRecords.ToString(); TextBoxes["Purchase Price"].Text = SS.PurchasePrice.ToString(); TextBoxes["Scrap Price"].Text = SS.ScrapPrice.ToString(); TextBoxes["SellingPrice"].Text = SS.SellingPrice.ToString(); TextBoxes["Good Distrubtion"].Text = SS.DayTypeDistributions[0].Probability.ToString(); TextBoxes["Fair Distrubtion"].Text = SS.DayTypeDistributions[1].Probability.ToString(); TextBoxes["Poor Distrubtion"].Text = SS.DayTypeDistributions[2].Probability.ToString(); DemandGridView.DataSource = null; foreach (DemandDistribution DD in SS.DemandDistributions) { DataGridViewRow DVR = new DataGridViewRow(); DVR.CreateCells(DemandGridView); DVR.Cells[0].Value = DD.Demand; DVR.Cells[1].Value = DD.DayTypeDistributions[0].Probability; DVR.Cells[2].Value = DD.DayTypeDistributions[1].Probability; DVR.Cells[3].Value = DD.DayTypeDistributions[2].Probability; DemandGridView.Rows.Add(DVR); } DemandGridView.Refresh(); }
SimulationSystem FormulateSimulattor() { SimulationSystem SS = new SimulationSystem(); SS.NumOfNewspapers = int.Parse(TextBoxes["Number of NewsPapers"].Text); SS.NumOfRecords = int.Parse(Text = TextBoxes["Number Of Records"].Text); SS.PurchasePrice = Convert.ToDecimal(TextBoxes["Purchase Price"].Text); SS.ScrapPrice = Convert.ToDecimal(TextBoxes["Scrap Price"].Text); SS.SellingPrice = Convert.ToDecimal(TextBoxes["SellingPrice"].Text); SS.InputDayDistrubution = TextBoxes["Good Distrubtion"].Text + ", " + TextBoxes["Fair Distrubtion"].Text + ", " + TextBoxes["Poor Distrubtion"].Text; string Accu = ""; foreach (DataGridViewRow DC in DemandGridView.Rows) { if (DC.Cells[0].Value == null) { break; } Accu += DC.Cells[0].Value + ", "; Accu += DC.Cells[1].Value + ", "; Accu += DC.Cells[2].Value + ", "; Accu += DC.Cells[3].Value + "\r\n"; } SS.InputDemandDistrubution = Accu; return(SS); }
/// <summary> /// Writes the simulation system to a string /// </summary> /// <param name="system">The simulation system to be written</param> static public string ToString(SimulationSystem system) { StringBuilder builder = new StringBuilder(); builder.AppendLine("NumOfNewspapers\n" + system.NumOfNewspapers.ToString() + "\n\nNumOfRecords\n" + system.NumOfRecords.ToString() + "\n\nPurchasePrice\n" + system.PurchasePrice.ToString() + "\n\nScrapPrice\n" + system.ScrapPrice.ToString() + "\n\nSellingPrice\n" + system.SellingPrice.ToString() + "\n\nDayTypeDistributions"); for (int i = 0; i < system.DayTypeDistributions.Count; i++) { builder.Append(system.DayTypeDistributions[i].Probability.ToString()); if (i != system.DayTypeDistributions.Count - 1) { builder.Append(", "); } } builder.AppendLine("\n\nDemandDistributions"); for (int i = 0; i < system.DemandDistributions.Count; i++) { builder.Append(system.DemandDistributions[i].Demand.ToString() + ", "); for (int j = 0; j < system.DemandDistributions[i].DayTypeDistributions.Count; j++) { builder.Append(system.DemandDistributions[i].DayTypeDistributions[j].Probability.ToString()); if (j != system.DemandDistributions[i].DayTypeDistributions.Count - 1) { builder.Append(", "); } } builder.AppendLine(); } return(builder.ToString().Trim()); }
private SimulationSystem ExtractFromUI() { SimulationSystem system = new SimulationSystem { DowntimeCost = (int)DownTimeCost.Value, RepairPersonCost = (int)RepairPersonCost.Value, BearingCost = (int)BearingCost.Value, NumberOfHours = (int)NumberOfHours.Value, NumberOfBearings = (int)NumberOfBearings.Value, RepairTimeForOneBearing = (int)RepairTimeForOneBearing.Value, RepairTimeForAllBearings = (int)RepairTimeForAllBearing.Value }; for (int i = 0; i < DelayTimeDistribution.Rows.Count - 1; i++) { DataGridViewRow c = DelayTimeDistribution.Rows[i]; system.DelayTimeDistribution.Add(new TimeDistribution() { Time = int.Parse((string)c.Cells[0].Value), Probability = decimal.Parse((string)c.Cells[1].Value) }); } for (int i = 0; i < BearingLifeDistribution.Rows.Count - 1; i++) { DataGridViewRow c = BearingLifeDistribution.Rows[i]; system.BearingLifeDistribution.Add(new TimeDistribution() { Time = int.Parse((string)c.Cells[0].Value), Probability = decimal.Parse((string)c.Cells[1].Value) }); } return(system); }
public static void DistributeSystem(SimulationSystem system) { AllowedToAnnounce = false; int i = 1; List <List <CurrentSimulationCase> > Cases = new List <List <CurrentSimulationCase> >() { new List <CurrentSimulationCase>() }; List <Thread> ActiveThreads = new List <Thread>(); List <SimulationSystem> Systems = new List <SimulationSystem>(); foreach (Socket s in ConnectedSockets) { if (i == system.NumberOfBearings) { break; } List <CurrentSimulationCase> Bearing = new List <CurrentSimulationCase>(); Cases.Add(Bearing); ActiveThreads.Add(new Thread(new ParameterizedThreadStart(ServersideDataCommunication))); Systems.Add((SimulationSystem)system.Clone()); ActiveThreads[ActiveThreads.Count - 1].Start(new object[] { Systems[Systems.Count - 1], Bearing, s }); i++; } Simulator.CurrrentCalculateCase(system); foreach (Thread t in ActiveThreads) { t.Join(); } // }
/// <summary> /// Runs the simulation through multiple threads /// </summary> /// <param name="system">The system to be simulated</param> /// <param name="rnd">Random number generator instance</param> static public void ParallelRun(SimulationSystem system, Random rnd = null) { new Igniter() { RunningMode = Enums.RunningMode.FullRun }.ParallelRunStarter(system, rnd); }
/// <summary> /// Re-evaluates concurrently the system profit based on the pre-determined demand values /// </summary> /// <param name="system">The system to be re-evaluated</param> static public void ParallelReEvaluationRun(SimulationSystem system) { system.PerformanceMeasures = new PerformanceMeasures(); new Igniter() { RunningMode = Enums.RunningMode.ReEvaluationRun }.ParallelRunStarter(system); }
public Total_performance(SimulationSystem sys) { InitializeComponent(); label4.Text = "System Performance as a all"; label2.Text = "MaxQueueLength = " + sys.PerformanceMeasures.MaxQueueLength.ToString(); label3.Text = "WaitingProbability = " + sys.PerformanceMeasures.WaitingProbability.ToString(); label1.Text = "AverageWaitingTime = " + sys.PerformanceMeasures.AverageWaitingTime.ToString(); }
/// <summary> /// Re-evalutes sequntially the system's profit based on predetermined demand values /// </summary> /// <param name="system">The system to be re-evaluated</param> static public void SequntialReEvaluationRun(SimulationSystem system) { system.PerformanceMeasures = new PerformanceMeasures(); foreach (SimulationCase c in system.SimulationTable) { Simulator.ReEvaluateProfit(c, system); } }
private void rd_data_Click(object sender, EventArgs e) { Inputs_Read File_Obj = new Inputs_Read(); sys = File_Obj.Read_fromFile(); MessageBox.Show("Done"); }
/// <summary> /// Writes a simulation system to a file. if the file exists it will be overwritten, otherwise it will be created /// </summary> /// <param name="system">The simulation system to be written</param> /// <param name="path">path to file</param> static public void ToFile(SimulationSystem system, string path) { FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write); StreamWriter writer = new StreamWriter(file); writer.Write(ToString(system)); writer.Close(); }
private static void ServersideDataCommunication(object o) { SimulationSystem system = (SimulationSystem)((object[])o)[0]; List <CurrentSimulationCase> Cases = (List <CurrentSimulationCase>)((object[])o)[1]; Socket socket = (Socket)((object[])o)[2]; TransmitData(socket, system); RecieveData(socket, Cases, system.CurrentPerformanceMeasures); }
static void Main() { SimulationSystem system = new SimulationSystem(); string result = TestingManager.Test(system, Constants.FileNames.TestCase1); MessageBox.Show(result); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
private void ok_btn_Click(object sender, EventArgs e) { sys = new SimulationSystem(); customersCount = 0; rand = new Random(); customerGrid.Rows.Clear(); initialize_inputs(); start_process(); }
private void button1_Click(object sender, EventArgs e) { string TestCasePath = txttestcase.Text.ToString(); SimulationSystem SimSystem = new SimulationSystem(); Display(SimSystem.StartSimulation(TestCasePath), SimSystem); string TestResult = TestingManager.Test(SimSystem, Constants.FileNames.TestCase3); MessageBox.Show(TestResult); }
public Form1() { InitializeComponent(); _simulationSystem = new SimulationSystem(); _bearingDistributions = new List <TimeDistribution>(); _delayDistributions = new List <TimeDistribution>(); _currentSimulationCases = new List <CurrentSimulationCase>(); _proposedSimulationCases = new List <ProposedSimulationCase>(); _rnd = new Random(); }
private static void ClientSideDataCommunication() { while (true) { SimulationSystem system = new SimulationSystem(); RecieveData(TCPSocket, system); Simulator.CurrrentCalculateCase(system); TransmitData(TCPSocket, system.CurrentSimulationTable, system.CurrentPerformanceMeasures); } }
private void Simulate_Click(object sender, EventArgs e) { SimulationSystem ss = new SimulationSystem { DowntimeCost = (int)DC_numeric.Value, RepairPersonCost = (int)RPC_numeric.Value, BearingCost = (int)BC_numeric.Value, NumberOfHours = (int)NH_numeric.Value, NumberOfBearings = (int)NB_numeric.Value, RepairTimeForOneBearing = (int)RT1B_numeric.Value, RepairTimeForAllBearings = (int)RTAB_numeric.Value }; int convertedTime; decimal convertedProbability; var DTD = DTD_textbox.Text.Split('\n'); var BTD = BLD_textbox.Text.Split('\n'); foreach (var dtd in DTD) { string[] spliced = dtd.Split(','); if (spliced.Length == 2 && int.TryParse(spliced[0], out convertedTime) && decimal.TryParse(spliced[1], out convertedProbability)) { ss.DelayTimeDistribution.Add(new TimeDistribution { Time = convertedTime, Probability = convertedProbability }); } } foreach (var btd in BTD) { var spliced = btd.Split(','); if (spliced.Length == 2 && int.TryParse(spliced[0], out convertedTime) && decimal.TryParse(spliced[1], out convertedProbability)) { ss.BearingLifeDistribution.Add(new TimeDistribution { Time = convertedTime, Probability = convertedProbability }); } } ss.CalculateBearingLifeDistribution(); ss.CalculateDelayTimeDistribution(); ss.InitBearings(); ss.CurrentSimulationTable = ss.GenerateCurrentSimulationCase(); ss.ProposedSimulationTable = ss.GenerateProposedSimulationCase(); ss.CurrentPerformanceMeasures = ss.SolveCurrentSimulationCase(); ss.ProposedPerformanceMeasures = ss.SolveProposedSimulationCase(); if (File.Exists("TestCases\\" + TC_list.Text)) { var testingResult = TestingManager.Test(ss, TC_list.Text); MessageBox.Show(testingResult); ResultsForm resultsForm = new ResultsForm(ss); resultsForm.ShowDialog(this); } }
private static void RenderWarehouseDimensions(SimulationSystem simulationSystem) { var warehouse = (Warehouse)simulationSystem.World.Objects.First(); var warehouseDimensions = new Vector3( warehouse.WarehouseCompartments.Max(wc => wc.Location.X), warehouse.WarehouseCompartments.Max(wc => wc.Location.Y), warehouse.WarehouseCompartments.Max(wc => wc.Location.Z)); Console.SetCursorPosition(0, Convert.ToInt32(warehouseDimensions.Y) + 9); Console.Write($"Warehouse Dimensions: X: {warehouseDimensions.X} Y: {warehouseDimensions.Y} Z: {warehouseDimensions.Z}"); }
private async void RRunAgain_Click(object sender, EventArgs e) { SimulationSystem system = null; await Task.Run(() => { system = LoadFromUI(); Simulator.StartSimulation(system); }); FillSimulationTable(system); }