Beispiel #1
0
        /// <summary>
        /// Searches linearly for the best newspaper count through the entire range
        /// </summary>
        /// <param name="system">The system to find the best newspaper count for</param>
        /// <returns>The best possible newspaper count in the range</returns>
        static public int LinearSearch(SimulationSystem system)
        {
            Igniter.SequntialRun(system);
            int     Ans    = 0;
            decimal MaxAns = 0;

            for (int i = MinRange / 10; i <= MaxRange / 10; i++)
            {
                system.NumOfNewspapers = i * 10;
                Igniter.SequntialReEvaluationRun(system);
                if (system.PerformanceMeasures.TotalNetProfit > MaxAns)
                {
                    Ans    = i * 10;
                    MaxAns = system.PerformanceMeasures.TotalNetProfit;
                }
            }
            return(Ans);
        }
Beispiel #2
0
        /// <summary>
        /// Logirthmically searches for the best possible newspaper count
        /// </summary>
        /// <param name="system">The system to find the best newspaper count for</param>
        /// <returns>The best possible newspaper count</returns>
        static public int TernarySearch(SimulationSystem system)
        {
            system.SimulationTable.Clear();
            system.PerformanceMeasures = new PerformanceMeasures();
            Igniter.ParallelRun(system);
            SimulationSystem LeftSystem = system.Clone() as SimulationSystem;
            SimulationSystem RightSystem = system.Clone() as SimulationSystem;
            int Start = MinRange / 10, End = MaxRange / 10, Left, Right;

            while (Start <= End)
            {
                Left  = Start + (End - Start) / 3;
                Right = End - (End - Start) / 3;
                if (Left == Start && Right == End)
                {
                    return(((Left + Right) * 10) / 2);
                }
                LeftSystem.NumOfNewspapers  = Left * 10;
                RightSystem.NumOfNewspapers = Right * 10;
                Task[] tasks = new Task[]
                {
                    Task.Run(() =>
                    {
                        Igniter.ParallelReEvaluationRun(LeftSystem);
                    }),
                    Task.Run(() =>
                    {
                        Igniter.ParallelReEvaluationRun(RightSystem);
                    })
                };
                Task.WaitAll(tasks);
                if (LeftSystem.PerformanceMeasures.TotalNetProfit < RightSystem.PerformanceMeasures.TotalNetProfit)
                {
                    Start = Left;
                }
                else
                {
                    End = Right;
                }
            }
            throw new System.Exception("???");
        }
        private async void StartSimulationButton_Click(object sender, EventArgs e)
        {
            DisableAllControls();
            SimulationSystem system = LoadSystemFromUI();
            DialogResult     result;

            do
            {
                await Task.Run(() => Igniter.ParallelRun(system));

                SimulationTable TableViewer = new SimulationTable(system);
                TableViewer.ShowDialog();
                result = MessageBox.Show("Run Again?", "Results", MessageBoxButtons.YesNoCancel);
            }while (result == DialogResult.Yes);
            EnableAllControls();
            if (result == DialogResult.No)
            {
                ClearUI();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Runs all test cases in TestCases folder
        /// </summary>
        /// <returns>Result of running all of the testcases</returns>
        static public string RunAllTestCases()
        {
            string        path    = Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory().ToString()).ToString()) + "\\TestCases\\";
            StringBuilder builder = new StringBuilder();
            Stopwatch     watch   = new Stopwatch();
            int           i       = 1;

            foreach (string file in Directory.EnumerateFiles(path))
            {
                string fileName = file.Substring(file.LastIndexOf('\\') + 1);
                if (fileName.Contains("TestCase"))
                {
                    builder.AppendLine("---TestCase #" + i++);
                    SimulationSystem system = FromFile(file);
                    watch.Restart();
                    Igniter.ParallelRun(system);
                    watch.Stop();
                    builder.AppendLine(TestingManager.Test(system, fileName)
                                       + "\nTime = " + watch.ElapsedMilliseconds + "ms");
                }
            }
            return(builder.ToString().Trim());
        }