Exemple #1
0
        private void ChangeSimulationSpeed()
        {
            bool fastMode = checkBoxFastMode.Checked;

            if (fastMode)
            {
                simulation.SetMaxSimSpeed();
                return;
            }

            double duration = trackBarDuration.Value;
            double interval = trackBarInterval.Value;

            simulation.SetSimSpeed(interval, duration / 1000);
        }
        private void buttStart_Click(object sender, EventArgs e)
        {
            processStopped            = false;
            bestConfiguration         = null;
            testedConfigurationsCount = 0;
            validConfigurationsCount  = 0;
            minArrivedAfterStartRatio = 1;
            minAverageWaitingTime     = double.MaxValue;
            validConfigFound          = false;
            minCost = int.MaxValue;
            minLineBudgets.CopyTo(currentLineBudgets, 0);
            configsWithCurrentBudgetCount = 0;

            Thread thread = new Thread(() =>
            {
                simulation.SetMaxSimSpeed();
                for (int configurationIdx = 0; configurationIdx < configurationsToTestCount; configurationIdx++)
                {
                    // generate configuration
                    SimulationConfiguration config = GenerateConfiguration();

                    // test configuration
                    SetConfiguration(simulation, config);

                    simulation.Simulate((int)numReplicationsCount.Value, endTime - startTime);

                    if (processStopped)
                    {
                        return;
                    }

                    testedConfigurationsCount++;
                    DoOnGuiThread(labelTestedConfigCount, () =>
                    {
                        labelTestedConfigCount.Text = testedConfigurationsCount.ToString();
                    });

                    // check if better than best
                    bool isSimulationResultValid = IsSimulationResultValid(simulation);
                    bool hasBetterStats          =
                        hasBetterStatsThan(simulation, minAverageWaitingTime, minArrivedAfterStartRatio);
                    int currentCost = config.Cost();

                    bool isBetter = false;
                    if (bestConfiguration == null)
                    {
                        isBetter = true;
                    }
                    else if (!validConfigFound)
                    {
                        if (isSimulationResultValid || hasBetterStats)
                        {
                            isBetter = true;
                        }
                    }
                    else if (isSimulationResultValid)
                    {
                        if (currentCost < minCost ||
                            (currentCost == minCost && hasBetterStats))
                        {
                            isBetter = true;
                        }
                    }

                    if (isSimulationResultValid)
                    {
                        validConfigFound = true;
                        validConfigurationsCount++;
                        DoOnGuiThread(labelValidConfigCount, () =>
                        {
                            labelValidConfigCount.Text = validConfigurationsCount.ToString();
                        });
                    }

                    if (isBetter)
                    {
                        bestConfiguration = config;
                        PrintConfiguration(labelBestConfiguration, bestConfiguration);
                        minArrivedAfterStartRatio = simulation.ArrivedAfterStartRatioSim.Mean();
                        minAverageWaitingTime     = simulation.AveragePassengerWaitingTimeSim.Mean();
                        minCost = currentCost;
                        DoOnGuiThread(labelMinCost, () =>
                        {
                            labelMinCost.Text = minCost.ToString();
                            labelMinAverageWaitingTime.Text = StatFormatter.FormatStatistic(
                                simulation.AveragePassengerWaitingTimeSim.Mean(),
                                simulation.AveragePassengerWaitingTimeSim.ConfidenceInterval90);
                            labelMinArrivedAfterStartRatio.Text = StatFormatter.FormatStatistic(
                                simulation.ArrivedAfterStartRatioSim.Mean(),
                                simulation.ArrivedAfterStartRatioSim.ConfidenceInterval90);
                        });
                    }
                }
            });

            thread.Start();
        }
Exemple #3
0
        public static void CarConfig()
        {
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";

            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

            string line = "";

            System.IO.StreamReader file = new System.IO.StreamReader("configurationA.txt");

            while ((line = file.ReadLine()) != null)
            {
                int[]        SelectedCars = ToIntArray(line, ',');
                MySimulation ms           = new MySimulation();
                ms.AgentModelu.SelectedCars = SelectedCars;
                ms.SetMaxSimSpeed();
                ms.Simulate(5, 788400);

                using (StreamWriter w = File.AppendText("resultsConfigurationA.txt"))
                {
                    w.WriteLine(line + ", " +
                                ms.AgentSkladky.WaitingTimeSimulacia.Mean().ToString() + ", " +
                                ms.AgentSkladky.LengthOfQueueSimulacia.Mean().ToString() + ", " +
                                (ms.AgentSkladky.WaitingTimeSimulacia.Mean() / SelectedCars.Length).ToString() + ", " +
                                ms.AgentSkladky.RealWorkingTimeASimulacia.Mean().ToString() + ", " +
                                ms.AgentSkladky.RealWorkingTimeBSimulacia.Mean().ToString() + ", " +

                                "<" + ms.AgentSkladky.WaitingTimeSimulacia.ConfidenceInterval90[0].ToString() + ";" + ms.AgentSkladky.WaitingTimeSimulacia.ConfidenceInterval90[1].ToString() + ">" + ", " +
                                "<" + ms.AgentSkladky.LengthOfQueueSimulacia.ConfidenceInterval90[0].ToString() + ";" + ms.AgentSkladky.LengthOfQueueSimulacia.ConfidenceInterval90[1].ToString() + ">" + ", " +
                                "<" + ms.AgentSkladky.RealWorkingTimeASimulacia.ConfidenceInterval90[0].ToString() + ";" + ms.AgentSkladky.RealWorkingTimeASimulacia.ConfidenceInterval90[1].ToString() + ">" + ", " +
                                "<" + ms.AgentSkladky.RealWorkingTimeBSimulacia.ConfidenceInterval90[0].ToString() + ";" + ms.AgentSkladky.RealWorkingTimeBSimulacia.ConfidenceInterval90[1].ToString() + ">" + ", " +

                                ms.AgentStavby.WaitingTimeSimulacia.Mean().ToString() + ", " +
                                ms.AgentStavby.LengthOfQueueSimulacia.Mean().ToString() + ", " +
                                (ms.AgentStavby.WaitingTimeSimulacia.Mean() / SelectedCars.Length).ToString() + ", " +
                                ms.AgentStavby.RealWorkingTimeASimulacia.Mean().ToString() + ", " +
                                //ms.AgentStavby.RealWorkingTimeBSimulacia.Mean().ToString("P") + ", " +

                                "<" + ms.AgentStavby.WaitingTimeSimulacia.ConfidenceInterval90[0].ToString() + ";" + ms.AgentStavby.WaitingTimeSimulacia.ConfidenceInterval90[1].ToString() + ">" + ", " +
                                "<" + ms.AgentStavby.LengthOfQueueSimulacia.ConfidenceInterval90[0].ToString() + ";" + ms.AgentStavby.LengthOfQueueSimulacia.ConfidenceInterval90[1].ToString() + ">" + ", " +
                                "<" + ms.AgentStavby.RealWorkingTimeASimulacia.ConfidenceInterval90[0].ToString() + ";" + ms.AgentStavby.RealWorkingTimeASimulacia.ConfidenceInterval90[1].ToString() + ">" + ", "


                                /*
                                 * if (!ms.AgentStavby.VykladacBIsDisabled)
                                 * {
                                 *  "<"+ms.AgentStavby.RealWorkingTimeBSimulacia.ConfidenceInterval90[0].ToString("####.00") + ";" + ms.AgentStavby.RealWorkingTimeBSimulacia.ConfidenceInterval90[1].ToString("####.00") + ">" + ", "
                                 * }
                                 */
                                )
                    ;
                }



                /*
                 *
                 * using (StreamWriter w = File.AppendText("results.txt"))
                 * {
                 *  w.WriteLine(line + ", " + ms.AgentStavby.OdoberMaterialKumulativny.Mean() + " ");
                 * }
                 *
                 * using (StreamWriter w = File.AppendText("resultsTop.txt"))
                 * {
                 *  if (ms.AgentStavby.OdoberMaterialKumulativny.Mean() >= 0.95)
                 *  {
                 *      w.WriteLine(line + " " + ms.AgentStavby.OdoberMaterialKumulativny.Mean() + ms.AgentModelu.CostOfVehicles().ToString("C") + " ");
                 *  }
                 * }
                 */
            }

            file.Close();
        }