Пример #1
0
        /// <summary>
        /// Test mufasa performance.
        /// </summary>
        private void test()
        {
            workingBar.Visibility = Visibility.Visible;
            progressBar.Value = 0;
            
            try
            {
                construct = new Construct(Designer.ConstructionList, Designer.FragmentDict, Designer.Settings);
            }
            catch (TmThalParamException tex)
            {
                ModernDialog.ShowMessage("Unable to assemble.\n(" + tex.Message + ")", "Warning: ", MessageBoxButton.OK);
                workingBar.Visibility = Visibility.Hidden;
                assembleButton.Content = "Assemble";
                assembleButton.IsEnabled = true;
                testButton.IsEnabled = true;
                return;
            }

            overlapOptimizer = new OverlapOptimizer(construct, Designer.Settings);
            testButton.Content = "Stop";
            BackgroundWorker bw = new BackgroundWorker();
            Stopwatch w = new Stopwatch();
            // this allows our worker to report progress during work
            bw.WorkerReportsProgress = true;
            // what to do in the background thread

            if (Designer.Settings.UseNaive)
            {
                overlapOptimizer.IgnorePreoptimizationExceptions = false;
                w.Start();
                bw.DoWork += new DoWorkEventHandler(overlapOptimizer.SemiNaiveOptimizeOverlaps);
            }
            else
            {
                overlapOptimizer.IgnorePreoptimizationExceptions = true;
                bw.DoWork += (s, args) =>
                {
                    w.Start();
                    //preoptimize
                    overlapOptimizer.SemiNaiveOptimizeOverlaps(s, args);
                    overlapOptimizer.LeaOptimizeOverlaps(s, args);
                };
            }


            // what to do when progress changed (update the progress bar)
            bw.ProgressChanged += new ProgressChangedEventHandler(
            delegate(object o, ProgressChangedEventArgs args)
            {
                progressBar.Value = args.ProgressPercentage;
            });
            // what to do when worker completes its task (notify the user)
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
            delegate(object o, RunWorkerCompletedEventArgs args)
            {
                w.Stop();
                if (args.Error == null)
                {
                    construct = overlapOptimizer.Construct;
                    ScoreTotal score = construct.Score;
                    overlapDataGrid.ItemsSource = construct.Overlaps;
                    overlapDataGrid.Items.Refresh();
                    List<Score> scoreList = new List<Score>();
                    scoreList.Add(score.Sm);
                    scoreList.Add(score.So);
                    scoreList.Add(score);
                    scoreDataGrid.ItemsSource = scoreList;
                    scoreDataGrid.Items.Refresh();


                    String sep = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
                    try
                    {
                        using (StreamWriter sw = new StreamWriter("testlog.csv",true))
                        {
                            sw.WriteLine(score.NormalizedScore.ToString() + sep + score.So.NormalizedScore.ToString() + sep + score.Sm.NormalizedScore.ToString() + sep + (double)w.ElapsedMilliseconds / 1000);
                        }
                    }
                    catch (Exception exc)
                    {
                        ModernDialog.ShowMessage(exc.Message, "Warning: ", MessageBoxButton.OK);
                    }
                }
                else
                {
                    Exception ex = args.Error as Exception;
                    ModernDialog.ShowMessage("Unable to assemble.\n(" + ex.Message + ")", "Warning: ", MessageBoxButton.OK);

                    String sep = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
                    try
                    {
                        using (StreamWriter sw = new StreamWriter(saveOverlapsDialog.FileName))
                        {
                            sw.WriteLine(ScoreTotal.Inacceptable.NormalizedScore.ToString() + sep + ScoreTotal.Inacceptable.NormalizedScore.ToString() + sep + ScoreTotal.Inacceptable.NormalizedScore.ToString() + sep + (double)w.ElapsedMilliseconds / 1000);
                        }
                    }
                    catch (Exception exc)
                    {
                        ModernDialog.ShowMessage(exc.Message, "Warning: ", MessageBoxButton.OK);
                    }

                }

                workingBar.Visibility = Visibility.Hidden;
                testButton.Content = "Test";
                testButton.IsEnabled = true;
            });

            bw.RunWorkerAsync();
        }
Пример #2
0
        /// <summary>
        /// Assemble button click event handler.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void assembleButton_Click(object sender, RoutedEventArgs e)
        {
            if (assembleButton.Content.ToString() == "Stop")
            {
                overlapOptimizer.Stop();
                assembleButton.IsEnabled = false;
            }

            if (Designer.ConstructionList != null && Designer.ConstructionList.Count > 0 && assembleButton.Content.ToString() != "Stop")
            {
                testButton.IsEnabled = false;
                workingBar.Visibility = Visibility.Visible;
                progressBar.Value = 0;

                try
                {
                    construct = new Construct(Designer.ConstructionList, Designer.FragmentDict, Designer.Settings);
                }
                catch(TmThalParamException tex)
                {
                    ModernDialog.ShowMessage("Unable to assemble.\n(" + tex.Message + ")", "Warning: ", MessageBoxButton.OK);
                    workingBar.Visibility = Visibility.Hidden;
                    assembleButton.Content = "Assemble";
                    assembleButton.IsEnabled = true;
                    testButton.IsEnabled = true;
                    return;
                }

                overlapOptimizer = new OverlapOptimizer(construct, Designer.Settings);
                assembleButton.Content = "Stop";

                BackgroundWorker bw = new BackgroundWorker();
                // this allows our worker to report progress during work
                bw.WorkerReportsProgress = true;
                // what to do in the background thread

                if (Designer.Settings.UseNaive)
                {
                    overlapOptimizer.IgnorePreoptimizationExceptions = false;
                    bw.DoWork += new DoWorkEventHandler(overlapOptimizer.SemiNaiveOptimizeOverlaps);
                }
                else
                {
                    overlapOptimizer.IgnorePreoptimizationExceptions = true;
                    bw.DoWork += (s, args) =>
                    {
                        //preoptimize
                        overlapOptimizer.SemiNaiveOptimizeOverlaps(s, args);
                        overlapOptimizer.LeaOptimizeOverlaps(s, args);
                    };
                }


                // what to do when progress changed (update the progress bar)
                bw.ProgressChanged += new ProgressChangedEventHandler(
                delegate(object o, ProgressChangedEventArgs args)
                {
                    progressBar.Value = args.ProgressPercentage;
                });
                // what to do when worker completes its task (notify the user)
                bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                delegate(object o, RunWorkerCompletedEventArgs args)
                {
                    if (args.Error == null)
                    {
                        construct = overlapOptimizer.Construct;
                        ScoreTotal score = construct.Score;
                        overlapDataGrid.ItemsSource = construct.Overlaps;
                        overlapDataGrid.Items.Refresh();
                        List<Score> scoreList = new List<Score>();
                        scoreList.Add(score.Sm);
                        scoreList.Add(score.So);
                        scoreList.Add(score);
                        scoreDataGrid.ItemsSource = scoreList;
                        scoreDataGrid.Items.Refresh();
                    }
                    else
                    {
                        Exception ex = args.Error as Exception;
                        ModernDialog.ShowMessage("Unable to assemble.\n(" + ex.Message + ")", "Warning: ", MessageBoxButton.OK);
                    }

                    workingBar.Visibility = Visibility.Hidden;
                    assembleButton.Content = "Assemble";
                    assembleButton.IsEnabled = true;
                    testButton.IsEnabled = true;
                });

                bw.RunWorkerAsync();
            }

        }