예제 #1
0
        public void Test(double time, double dt)
        {
            int iterations = (int)Math.Ceiling(time / dt);

            // initialize all wrappers
            double initialCondition = exactSolution(0d);

            foreach (var wrapper in wrappers)
            {
                wrapper.Initialize(initialCondition, dt);
            }

            // calculate reference data
            var referenceData = GetReferenceData(iterations, dt);

            // performs test on all wrappers and results
            List <SolverResults> results = new List <SolverResults>();

            foreach (var wrapper in wrappers)
            {
                var executionTime = ExecTime.Run(() =>
                {
                    PerformModelTest(wrapper, iterations, dt);
                });
                results.Add(new SolverResults(wrapper, referenceData, executionTime));
            }

            // sort results and show
            results.Sort((r1, r2) => (r1.Mse > r2.Mse) ? 1 : -1);
            foreach (var result in results)
            {
                Console.WriteLine(result.ToString());
            }
        }
예제 #2
0
        private void LoadResults(Bitmap bitmap, IComparison comparison)
        {
            try
            {
                DisposeImages();

                var originalBitmap = bitmap;
                var originalImage  = ImageProcessingLibConverter.CreateImageFromBitmap(originalBitmap);

                Bitmap tempResult = null;
                var    fipTime    = ExecTime.Run(() =>
                {
                    tempResult = comparison.GetFIPResults(new FIP.FIP(), originalBitmap);
                });
                var fipBitmap = (Bitmap)tempResult.Clone();
                var fipImage  = ImageProcessingLibConverter.CreateImageFromBitmap(fipBitmap);

                Image <Pixel32> iplImage = null;
                var             iplTime  = ExecTime.Run(() =>
                {
                    iplImage = comparison.GetIPLResult(originalImage);
                });
                var iplBitmap = ImageProcessingLibConverter.CreateBitmapFromImage(iplImage);

                ThreadSafeInvoke.Invoke(this, () =>
                {
                    pbFIP.Image = fipBitmap;
                    pbIPL.Image = iplBitmap;

                    tsslInfo.Text = string.Format("MSE: {0:0.00}, IPL: {1:0}ms, FIP: {2:0}ms",
                                                  GetMetrics(fipImage, iplImage),
                                                  iplTime.TotalMilliseconds, fipTime.TotalMilliseconds);
                });

                createdBitmaps = new List <Bitmap>()
                {
                    fipBitmap, iplBitmap
                };
            }
            catch (Exception e)
            {
                MessageBoxEx.ShowException(e);
            }
        }
예제 #3
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Debug.WriteLine("Worker started");
            worker.ReportProgress(0);

            // extract all data from worker input
            BackgroundSimulationInput input = (BackgroundSimulationInput)e.Argument;
            double             timeHorizon  = input.timeHorizon;
            double             timeStep     = input.timeStep;
            IterativeSimulator simulator    = input.iterativeSimulator;

            int iterations    = (int)Math.Floor(timeHorizon / timeStep) + 1;
            var executionTime = ExecTime.Run(() =>
            {
                // first iteration - simulation initialization
                simulator.PrepareSimulation(timeStep);
                progressCounter.Initialize(iterations);
                progressCounter.NextIteration();

                // perform calculations
                for (int i = 1; i < iterations; i++)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }

                    simulator.NextIteration();
                    progressCounter.NextIteration();
                }
            });

            // return result
            BackgroundSimulationOutput output = new BackgroundSimulationOutput()
            {
                totalIterations = iterations,
                timeStep        = timeStep,
                executionTime   = executionTime,
                data            = simulator.GetData()
            };

            e.Result = output;
        }
        private async Task LaunchExample(Bitmap bmp, ExampleBase example)
        {
            try
            {
                TimeSpan initializationTime = TimeSpan.Zero;
                await Task.Run(() =>
                {
                    initializationTime = ExecTime.Run(() => example.ApplyExample(bmp));
                });

                view.SetResultImages(example.Images);
                view.SelectedResultImage = example.OriginalImage;
                view.SetSummary(example.GetType().Name, initializationTime.TotalMilliseconds);
            }
            catch (Exception exc)
            {
                view.ShowException(exc);
            }
        }
예제 #5
0
        private void Simulator_OnFinish(object result)
        {
            UpdateSimulationState(false);

            var output = result as BackgroundSimulationOutput;

            var plottingTime = ExecTime.Run(() =>
            {
                resultData = ExtractChartData(output);
                chart.SetPoints(resultData);
                chart.FitXAxisToSeries();
            });

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Simulation finished!");
            sb.AppendLine(string.Format("Generated total {0} points", output.data.Count));
            sb.AppendLine(string.Format("Plotted {0} points", resultData.Count));
            sb.AppendLine(string.Format("Simulation time: {0} ms", output.executionTime));
            sb.AppendLine(string.Format("Plotting time: {0} ms", plottingTime));
            MessageBoxEx.Info(sb.ToString());
        }