Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/20/15 16:45:08 (9 years ago)
Author:
aballeit
Message:

#2283 stable GUI; ThreadPool for runs; improved TreeAnalysis

Location:
branches/HeuristicLab.Problems.GrammaticalOptimization
Files:
1 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization

    • Property svn:ignore
      •  

        old new  
        33TestResults
        44_ReSharper.GrammaticalOptimization
         5EvaluationResults
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation

    • Property svn:ignore set to
      bin
      obj
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/Evaluation.csproj

    r12762 r12781  
    5454      <SubType>Designer</SubType>
    5555    </ApplicationDefinition>
    56     <Compile Include="EvaluationStat.cs" />
     56    <Compile Include="FoundSolution.cs" />
    5757    <Compile Include="Run.cs" />
    5858    <Compile Include="ViewModel\EvaluationViewModel.cs" />
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/MainWindow.xaml

    r12762 r12781  
    3939                          DisplayMemberPath="Name"
    4040                          SelectedValue="{Binding SelectedAlgorithm}"
    41                           Width="200"
     41                          Width="280"
    4242                          SelectionChanged="ComboBoxAlgorithms_OnSelectionChanged"></ComboBox>
    4343                <ComboBox Name="ComboBoxPolicies"
     
    7575                <TextBlock Margin="2" Grid.Column="2" Grid.Row="0" VerticalAlignment="Center">MaxLen:</TextBlock>
    7676                <TextBox Name="TextBoxMaxLen" Margin="2" Grid.Column="3" Grid.Row="0" Width="100" VerticalAlignment="Center" TextAlignment="Right" Text="{Binding MaxLen}"></TextBox>
    77                 <TextBlock Margin="2" Grid.Column="2" Grid.Row="1" VerticalAlignment="Center">Threads:</TextBlock>
    78                 <TextBox Name="TextBoxThreads" Margin="2" Grid.Column="3" Grid.Row="1" Width="100" VerticalAlignment="Center" TextAlignment="Right" Text="{Binding Threads}"></TextBox>
    7977            </Grid>
    8078        </GroupBox>
     
    125123                                        <ColumnDefinition Width="*"></ColumnDefinition>
    126124                                    </Grid.ColumnDefinitions>
    127                                     <Grid Name="MyGrid" Grid.Column="0" DataContext="{Binding CurrentRun.TreeInfos}">
     125                                    <Grid Name="MyGrid" Grid.Column="0" DataContext="{Binding SelectedRun.TreeInfos}">
    128126                                        <Grid.RowDefinitions>
    129                                             <RowDefinition Height="Auto"></RowDefinition>
    130                                             <RowDefinition Height="Auto"></RowDefinition>
    131127                                            <RowDefinition Height="Auto"></RowDefinition>
    132128                                            <RowDefinition Height="Auto"></RowDefinition>
     
    148144                                        <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding LeaveNodes}" TextAlignment="Right"></TextBlock>
    149145                                        <TextBlock Grid.Row="4" Grid.Column="0" Text="DeepestLevel:"></TextBlock>
    150                                         <TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding DeepestLevel}" TextAlignment="Right"></TextBlock>
    151                                         <TextBlock Grid.Row="5" Grid.Column="0" Text="AverageLevel:"></TextBlock>
    152                                         <TextBlock Grid.Row="5" Grid.Column="1" Text="{Binding AverageLevel}" TextAlignment="Right"></TextBlock>
    153                                         <TextBlock Grid.Row="6" Grid.Column="0" Text="AverageChildren:"></TextBlock>
    154                                         <TextBlock Grid.Row="6" Grid.Column="1" Text="{Binding AverageChildren}" TextAlignment="Right"></TextBlock>
     146                                        <TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding DeepestLevel}" TextAlignment="Right"></TextBlock>                                       
    155147                                    </Grid>
    156148                                    <Frame Grid.Column="1" Name="treeDrawing" Source="pack://application:,,,/WpfTestSvgSample;component/DrawingPage.xaml"/>
     
    162154
    163155                <TabItem Header="Run-Comparison">
    164                     <TabControl Name="TabControlRunComparison" SelectionChanged="TabControlRunComparison_OnSelectionChanged">
     156                    <TabControl Name="TabControlRunComparison">
    165157                        <TabItem Name="TabItemChartRunComparison" Header="Chart">
    166158                            <d3:ChartPlotter x:Name="ComparisonChartPlotter" LegendVisible="False" EnableSmoothPanningForNumericAxes="True">
     
    182174                                                            Header="BestKnownQuality"/>
    183175                                            <GridViewColumn DisplayMemberBinding="{Binding Path=BestSolutionQuality}"
    184                                                             Header="BestFoundQuality"/>
     176                                                            Header="BestQuality"/>
    185177                                            <GridViewColumn DisplayMemberBinding="{Binding Path=EvaluationsPerSecond}"
    186178                                                            Header="EvaluationsPerSecond"/>
     
    211203                    <RowDefinition Height="Auto" />
    212204                    <RowDefinition Height="Auto" />
     205                    <RowDefinition Height="Auto" />
    213206                </Grid.RowDefinitions>
    214207                <Grid.ColumnDefinitions>
     
    216209                    <ColumnDefinition Width="*" />
    217210                </Grid.ColumnDefinitions>
    218                 <TextBlock Grid.Row="0" Grid.Column="0">Run:</TextBlock>
    219                 <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding CurrentRunString}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    220                 <TextBlock Grid.Row="1" Grid.Column="0">Evaluations:</TextBlock>
    221                 <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Evaluations}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    222                 <TextBlock Grid.Row="2" Grid.Column="0">MaxEvaluations:</TextBlock>
    223                 <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding MaxEvaluations}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    224                 <TextBlock Grid.Row="3" Grid.Column="0">CurrentBestQuality:</TextBlock>
    225                 <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding CurrentBestQuality}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    226                 <TextBlock Grid.Row="4" Grid.Column="0">BestKnownQuality:</TextBlock>
    227                 <TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding BestKnownQuality}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    228                 <TextBlock Grid.Row="5" Grid.Column="0">MaxLen:</TextBlock>
    229                 <TextBlock Grid.Row="5" Grid.Column="1" Text="{Binding MaxLen}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    230                 <TextBlock Grid.Row="6" Grid.Column="0">Evaluations/sec:</TextBlock>
    231                 <TextBlock Grid.Row="6" Grid.Column="1" Text="{Binding EvaluationsPerSec}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    232                 <TextBlock Grid.Row="7" Grid.Column="0">BestSolutionFoundAt:</TextBlock>
    233                 <TextBlock Grid.Row="7" Grid.Column="1" Text="{Binding BestSolutionFoundAt}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    234                 <TextBlock Grid.Row="8" Grid.Column="0">BestSolution:</TextBlock>
    235                 <TextBlock Grid.Row="8" Grid.Column="1" Text="{Binding BestSolution}" Margin="5,0,0,0" HorizontalAlignment="Right" MaxWidth="100"/>
     211                <TextBlock Grid.Row="0" Grid.Column="0">CompletedRuns:</TextBlock>
     212                <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding CompletedRuns}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     213                <TextBlock Grid.Row="1" Grid.Column="0">RunState:</TextBlock>
     214                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding SelectedRun.RunState}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     215                <TextBlock Grid.Row="2" Grid.Column="0">Evaluations:</TextBlock>
     216                <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding SelectedRun.Evaluations}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     217                <TextBlock Grid.Row="3" Grid.Column="0">MaxEvaluations:</TextBlock>
     218                <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding SelectedRun.MaxEvaluations}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     219                <TextBlock Grid.Row="4" Grid.Column="0">BestQuality:</TextBlock>
     220                <TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding SelectedRun.BestQuality}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     221                <TextBlock Grid.Row="5" Grid.Column="0">BestKnownQuality:</TextBlock>
     222                <TextBlock Grid.Row="5" Grid.Column="1" Text="{Binding SelectedRun.BestKnownQuality}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     223                <TextBlock Grid.Row="6" Grid.Column="0">MaxLen:</TextBlock>
     224                <TextBlock Grid.Row="6" Grid.Column="1" Text="{Binding SelectedRun.MaxLen}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     225                <TextBlock Grid.Row="7" Grid.Column="0">Evaluations/sec:</TextBlock>
     226                <TextBlock Grid.Row="7" Grid.Column="1" Text="{Binding SelectedRun.EvaluationsPerSecond}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     227                <TextBlock Grid.Row="8" Grid.Column="0">BestSolutionFoundAt:</TextBlock>
     228                <TextBlock Grid.Row="8" Grid.Column="1" Text="{Binding SelectedRun.BestSolutionFoundAt}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     229                <TextBlock Grid.Row="9" Grid.Column="0">BestSolution:</TextBlock>
     230                <TextBlock Grid.Row="9" Grid.Column="1" Text="{Binding SelectedRun.BestSolution}" TextWrapping="Wrap" Margin="5,0,0,0" HorizontalAlignment="Right" MaxWidth="100"/>
    236231            </Grid>
    237232        </Grid>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/MainWindow.xaml.cs

    r12762 r12781  
    3030    public partial class MainWindow : Window
    3131    {
    32         private BackgroundWorker worker = new BackgroundWorker();
    3332        private EvaluationViewModel vm;
    3433
     
    4241            CenterWindowOnScreen();
    4342            this.DataContext = vm = new EvaluationViewModel();
    44             vm.MaxLen = 50;
    45             vm.MaxEvaluations = 250000;
    46             vm.NrRuns = 1;
    47             vm.CurrentRunString = "0/1";
    48             vm.Threads = 6;
     43            vm.MaxLen = 100;
     44            vm.MaxEvaluations = 1000000;
     45            vm.NrRuns = 10;
    4946            vm.VerticalAxisString = "SolutionQuality";
    5047            vm.HorizontalAxisString = "Iteration";
    51             this.worker.WorkerSupportsCancellation = true;
    52             this.worker.DoWork += worker_DoWork;
    53             this.worker.ProgressChanged += worker_ProgressChanged;
    54             this.worker.RunWorkerCompleted += worker_RunWorkerCompleted;
    55 
    56             ////updateCollectionTimer = new DispatcherTimer();
    57             ////updateCollectionTimer.Interval = TimeSpan.FromMilliseconds(100);
    58             ////updateCollectionTimer.Tick += updateCollectionTimer_Tick;
    59             ////updateCollectionTimer.Start();
    6048        }
    6149
     
    7058        }
    7159
    72         ////void updateCollectionTimer_Tick(object sender, EventArgs e)
    73         ////{
    74         ////    while (newStats.Count > 0)
    75         ////    {
    76         ////        EvaluationStat stat = newStats.Pop();
    77         ////        stats.Add(stat);
    78         ////    }
    79         ////}
    80 
    81         void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
     60        private void DrawLineChart(Run run)
     61        {
     62            List<FoundSolution> solutions = new List<FoundSolution>(run.FoundSolutions);
     63
     64            if (run.BestSolutionFoundAt < run.Evaluations)
     65            {
     66                solutions.Add(new FoundSolution(run.EndTime, run.Evaluations, run.BestQuality, run.BestSolution));
     67            }
     68
     69            var ds = new EnumerableDataSource<FoundSolution>(solutions);
     70
     71
     72            ds.SetXMapping(x => x.Iteration);
     73            ds.SetYMapping(y => y.Quality);
     74
     75            LineGraph graph = new LineGraph(ds);
     76
     77            graph.StrokeThickness = 2;
     78            graph.AddToPlotter(ChartPlotter);
     79        }
     80
     81        private void DrawTreeChart(Run run)
     82        {
     83            if (!string.IsNullOrEmpty(run.SvgFile))
     84            {
     85                treeDrawingPage.LoadDocument(run.SvgFile);
     86            }
     87        }
     88
     89        private void DoRun(Object threadContext)
     90        {
     91            Run run = (Run)threadContext;
     92            run.RunState = RunState.Running;
     93            run.StartTime = DateTime.Now;
     94
     95            run.Solver.Run(run.MaxEvaluations);
     96
     97            run.EndTime = DateTime.Now;
     98            run.RunState = RunState.Analyzing;
     99
     100            if (run.FoundSolutions.Count > 0)
     101            {
     102                if (run.Solver is MonteCarloTreeSearch)
     103                {
     104                    MonteCarloTreeSearch mctsSolver = (MonteCarloTreeSearch)run.Solver;
     105
     106                    run.TreeInfos = mctsSolver.GetTreeInfos();
     107
     108                    //byte[] output = mctsSolver.GenerateSvg();
     109                    //if (output != null && output.Length > 0)
     110                    //{
     111                    //    run.SvgFile = string.Format("MCTS_SVG_#{0}_{1}.svg", run.RunNumber, DateTime.Now.Ticks);
     112                    //    File.WriteAllBytes(run.SvgFile, mctsSolver.GenerateSvg());
     113                    //}
     114                }
     115            }
     116            run.RunState = RunState.Finished;
     117            lock (vm.CompletedRuns)
     118            {
     119                int completed = 0;
     120                foreach (Run r in vm.Runs)
     121                {
     122                    if (r.RunState == RunState.Finished)
     123                    {
     124                        completed++;
     125                    }
     126                }
     127                vm.CompletedRuns = string.Format("{0}/{1}", completed, vm.Runs.Count);
     128                if (completed == vm.NrRuns)
     129                {
     130                    Dispatcher.Invoke(AllRunsFinished);
     131                }
     132            }
     133        }
     134
     135        private void AllRunsFinished()
    82136        {
    83137            ButtonRun.IsEnabled = true;
     
    85139            TextBoxMaxLen.IsEnabled = true;
    86140            TextBoxRuns.IsEnabled = true;
    87             TextBoxThreads.IsEnabled = true;
    88         }
    89 
    90         private void DrawCharts(Run run)
    91         {
    92             ClearChart();
    93 
    94             var ds = new EnumerableDataSource<EvaluationStat>(run.EvaluationStats);
    95             ds.SetXMapping(x => x.Iteration);
    96             ds.SetYMapping(y => y.CurrentBestQuality);
    97 
    98             LineGraph graph = new LineGraph(ds);
    99 
    100             graph.StrokeThickness = 2;
    101             graph.AddToPlotter(ChartPlotter);
    102 
    103             DrawTreeChart(run);
    104         }
    105 
    106         private void DrawTreeChart(Run run)
    107         {
    108             if (!string.IsNullOrEmpty(run.SvgFile))
    109             {
    110                 treeDrawingPage.LoadDocument(run.SvgFile);
    111             }
    112         }
    113 
    114 
    115         void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    116         {
    117             Debug.WriteLine(e.UserState);
    118         }
    119 
    120         void worker_DoWork(object sender, DoWorkEventArgs e)
    121         {
     141        }
     142
     143        private void StartRuns()
     144        {
     145            vm.CompletedRuns = string.Format("0/{0}", vm.NrRuns);
    122146
    123147            Type algorithmType = vm.SelectedAlgorithm;
     
    143167            }
    144168
    145             vm.BestKnownQuality = problem.BestKnownQuality(vm.MaxLen);
    146 
    147169            for (int i = 0; i < vm.NrRuns; i++)
    148170            {
    149                 vm.CurrentRunString = string.Format("{0}/{1}", i + 1, vm.NrRuns);
    150                 vm.Evaluations = 0;
    151                 vm.CurrentBestQuality = 0;
    152 
    153                 List<EvaluationStat> stats = new List<EvaluationStat>();
    154 
    155171                ISolver solver = null;
    156172
    157                 if (algorithmType == typeof(MonteCarloTreeSearch))
     173                if (algorithmType == typeof(MonteCarloTreeSearch_PruneLeaves))
     174                {
     175                    solver = new MonteCarloTreeSearch_PruneLeaves(problem, vm.MaxLen, random, policyInstance, new RandomSimulation(problem, random, vm.MaxLen));
     176                }
     177                else if (algorithmType == typeof(MonteCarloTreeSearch))
    158178                {
    159179                    solver = new MonteCarloTreeSearch(problem, vm.MaxLen, random, policyInstance, new RandomSimulation(problem, random, vm.MaxLen));
     
    177197                }
    178198
    179                 solver.FoundNewBestSolution += (sentence, quality) =>
    180                 {
    181                     vm.BestSolutionFoundAt = vm.Evaluations;
    182                     vm.BestSolution = sentence;
    183                 };
    184                 solver.SolutionEvaluated += (sentence, quality) =>
    185                 {
    186                     vm.Evaluations++;
    187                     if (vm.CurrentBestQuality < quality)
    188                     {
    189                         vm.CurrentBestQuality = quality;
    190                     }
    191                     stats.Add(new EvaluationStat(DateTime.Now, vm.Evaluations, quality, vm.CurrentBestQuality));
    192                 };
    193 
    194                 solver.Run(vm.MaxEvaluations);
    195 
    196 
    197                 if (stats.Count > 0)
    198                 {
    199                     TimeSpan totalTimeNeeded = stats[stats.Count - 1].Time - stats[0].Time;
    200                     vm.EvaluationsPerSec = Math.Round(vm.Evaluations / totalTimeNeeded.TotalSeconds, 2);
    201 
    202                     TimeSpan timeForBestSolution = stats[vm.BestSolutionFoundAt - 1].Time - stats[0].Time;
    203 
    204                     Run run = new Run(i, vm.Evaluations, vm.CurrentBestQuality, vm.BestKnownQuality,
    205                         vm.BestSolutionFoundAt, vm.BestSolution, vm.EvaluationsPerSec,
    206                         totalTimeNeeded, timeForBestSolution, stats);
    207 
    208 
    209                     MonteCarloTreeSearch mctsSolver = null;
    210                     if (algorithmType == typeof(MonteCarloTreeSearch))
    211                     {
    212                         mctsSolver = (MonteCarloTreeSearch)solver;
    213 
    214                         run.TreeInfos = mctsSolver.GetTreeInfos();
    215 
    216                         byte[] output = mctsSolver.GenerateSvg();
    217                         if (output.Length > 0)
    218                         {
    219                             run.SvgFile = string.Format("MCTS_SVG_#{0}_{1}.svg", i, DateTime.Now.Ticks);
    220                             File.WriteAllBytes(run.SvgFile, mctsSolver.GenerateSvg());
    221                         }
    222                     }
    223 
    224                     Dispatcher.BeginInvoke(new Action(() => vm.Runs.Add(run)));
    225                 }
    226             }
    227         }
    228 
    229         private void ClearChart()
     199                Run run = new Run(problem, policyInstance, solver, i + 1, vm.MaxEvaluations, vm.MaxLen);
     200
     201                vm.Runs.Add(run);
     202
     203                ThreadPool.QueueUserWorkItem(DoRun, run);
     204            }
     205        }
     206
     207        private void ClearLineChart()
    230208        {
    231209            ChartPlotter.Children.RemoveAll<LineGraph>();
    232210        }
    233211
     212        private void ClearComparisonChart()
     213        {
     214            ComparisonChartPlotter.Children.RemoveAll<LineGraph>();
     215        }
     216
    234217        private void ButtonRun_OnClick(object sender, RoutedEventArgs e)
    235218        {
    236             ClearChart();
     219            ClearLineChart();
     220            ClearComparisonChart();
     221
    237222            vm.Runs.Clear();
    238             vm.CurrentRun = null;
     223            vm.SelectedRun = null;
    239224            ButtonRun.IsEnabled = false;
    240225            TextBoxMaxEvaluations.IsEnabled = false;
    241226            TextBoxMaxLen.IsEnabled = false;
    242227            TextBoxRuns.IsEnabled = false;
    243             TextBoxThreads.IsEnabled = false;
    244             worker.RunWorkerAsync();
     228            StartRuns();
    245229        }
    246230
     
    264248        private void ButtonStop_OnClick(object sender, RoutedEventArgs e)
    265249        {
    266             worker.CancelAsync();
     250            //worker.CancelAsync();
    267251        }
    268252
    269253        private void ComboBoxAlgorithms_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    270254        {
    271             if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch))
     255            if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch) || vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch_PruneLeaves))
    272256            {
    273257                ComboBoxPolicies.IsEnabled = true;
     
    293277        private void ListBoxRuns_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    294278        {
     279            if (vm.SelectedRun != null)
     280            {
     281                vm.SelectedRun.Solver.FoundNewBestSolution -= SelectedRun_FoundNewBestSolution;
     282            }
    295283            if (ListBoxRuns.SelectedItem != null)
    296284            {
    297                 vm.CurrentRun = (Run)ListBoxRuns.SelectedItem;
    298                 DrawCharts(vm.CurrentRun);
    299             }
     285                vm.SelectedRun = (Run)ListBoxRuns.SelectedItem;
     286
     287                vm.SelectedRun.Solver.FoundNewBestSolution += SelectedRun_FoundNewBestSolution;
     288
     289                ClearLineChart();
     290                DrawLineChart(vm.SelectedRun);
     291                //DrawTreeChart(vm.SelectedRun);
     292            }
     293            else
     294            {
     295                vm.SelectedRun = null;
     296            }
     297        }
     298
     299        void SelectedRun_FoundNewBestSolution(string arg1, double arg2)
     300        {
     301            Dispatcher.BeginInvoke(new Action(() =>
     302            {
     303                ClearLineChart();
     304                DrawLineChart(vm.SelectedRun);
     305            }));
    300306        }
    301307
     
    349355        private void LoadButton_OnClick(object sender, RoutedEventArgs e)
    350356        {
    351            LoadFromFile();
     357            LoadFromFile();
    352358        }
    353359
     
    355361        {
    356362            SaveToFile();
    357         }
    358 
    359         private void TabControlRunComparison_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    360         {
    361             ////if (TabControlRunComparison.SelectedItem == TabItemChartRunComparison)
    362             ////{
    363             ////    ComparisonChartPlotter.Children.RemoveAll<LineGraph>();
    364 
    365             ////    var ds = new EnumerableDataSource<EvaluationStat>(run.EvaluationStats);
    366             ////    ds.SetXMapping(x => x.Iteration);
    367             ////    ds.SetYMapping(y => y.CurrentBestQuality);
    368 
    369             ////    LineGraph graph = new LineGraph(ds);
    370 
    371             ////    graph.StrokeThickness = 2;
    372             ////    graph.AddToPlotter(ChartPlotter);
    373 
    374             ////}
    375363        }
    376364    }
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/Run.cs

    r12762 r12781  
    1 using System;
     1using HeuristicLab.Algorithms.Bandits;
     2using HeuristicLab.Algorithms.GrammaticalOptimization;
     3using HeuristicLab.Algorithms.MonteCarloTreeSearch.Base;
     4using HeuristicLab.Problems.GrammaticalOptimization;
     5using System;
    26using System.Collections.Generic;
    3 using HeuristicLab.Algorithms.MonteCarloTreeSearch.Base;
     7using System.ComponentModel;
    48
    59namespace Evaluation
    610{
    7     public class Run
     11
     12    public enum RunState
     13    {
     14        NotStarted,
     15        Running,
     16        Analyzing,
     17        Finished
     18    }
     19
     20    public class Run : INotifyPropertyChanged
    821    {
    922        public Run()
     
    1225        }
    1326
    14         public Run(int runNumber, int evaluations, double bestSolutionQuality, double bestKnownQuality,
    15             int bestSolutionFoundAt, string bestSolution,
    16             double evaluationsPerSecond, TimeSpan totalTime, TimeSpan bestSolutionTime,
    17             List<EvaluationStat> evaluationStats)
    18         {
     27        public Run(ISymbolicExpressionTreeProblem problem, IBanditPolicy banditPolicy, ISolver solver, int runNumber,
     28            int maxEvaluations, int maxLen)
     29        {
     30            Problem = problem;
     31            BanditPolicy = banditPolicy;
     32            Solver = solver;
    1933            RunNumber = runNumber;
    20             Evaluations = evaluations;
    21             BestSolutionQuality = bestSolutionQuality;
    22             BestKnownQuality = bestKnownQuality;
    23             BestSolutionFoundAt = bestSolutionFoundAt;
    24             BestSolution = bestSolution;
    25             EvaluationsPerSecond = evaluationsPerSecond;
    26             TotalTime = totalTime;
    27             BestSolutionTime = bestSolutionTime;
    28             EvaluationStats = evaluationStats;
    29         }
    30 
    31         public int RunNumber { get; set; }
    32         public int Evaluations { get; set; }
    33         public double BestSolutionQuality { get; set; }
    34 
    35         public string BestSolution { get; set; }
    36 
    37         public double BestKnownQuality { get; set; }
    38         public int BestSolutionFoundAt { get; set; }
    39 
    40         public double EvaluationsPerSecond { get; set; }
    41         public TimeSpan TotalTime { get; set; }
    42         public TimeSpan BestSolutionTime { get; set; }
    43         public List<EvaluationStat> EvaluationStats { get; set; }
     34            MaxEvaluations = maxEvaluations;
     35            MaxLen = maxLen;
     36
     37            Evaluations = 0;
     38            BestQuality = double.MinValue;
     39            RunState = RunState.NotStarted;
     40            FoundSolutions = new List<FoundSolution>();
     41
     42            BestKnownQuality = problem.BestKnownQuality(maxLen);
     43            solver.SolutionEvaluated += (sentence, quality) =>
     44            {
     45                Evaluations++;
     46                if (quality > BestQuality)
     47                {
     48                    BestQuality = quality;
     49                    BestSolution = sentence;
     50                    BestSolutionFoundAt = evaluations;
     51                    FoundSolutions.Add(new FoundSolution(DateTime.Now, Evaluations, quality, sentence));
     52                }
     53            };
     54        }
     55
     56        private ISymbolicExpressionTreeProblem problem;
     57
     58        public ISymbolicExpressionTreeProblem Problem
     59        {
     60            get { return this.problem; }
     61            set
     62            {
     63                this.problem = value;
     64                this.OnPropertyChanged("Problem");
     65            }
     66        }
     67
     68        private IBanditPolicy banditPolicy;
     69
     70        public IBanditPolicy BanditPolicy
     71        {
     72            get { return this.banditPolicy; }
     73            set
     74            {
     75                this.banditPolicy = value;
     76                this.OnPropertyChanged("BanditPolicy");
     77            }
     78        }
     79
     80        private ISolver solver;
     81
     82        public ISolver Solver
     83        {
     84            get { return this.solver; }
     85            set
     86            {
     87                this.solver = value;
     88                this.OnPropertyChanged("Solver");
     89            }
     90        }
     91
     92        private int runNumber;
     93
     94        public int RunNumber
     95        {
     96            get { return this.runNumber; }
     97            set
     98            {
     99                this.runNumber = value;
     100                this.OnPropertyChanged("RunNumber");
     101            }
     102        }
     103
     104        private int maxEvaluations;
     105
     106        public int MaxEvaluations
     107        {
     108            get { return this.maxEvaluations; }
     109            set
     110            {
     111                this.maxEvaluations = value;
     112                this.OnPropertyChanged("MaxEvaluations");
     113            }
     114        }
     115
     116        private int maxLen;
     117
     118        public int MaxLen
     119        {
     120            get { return this.maxLen; }
     121            set
     122            {
     123                this.maxLen = value;
     124                this.OnPropertyChanged("MaxLen");
     125            }
     126        }
     127
     128        private int evaluations;
     129
     130        public int Evaluations
     131        {
     132            get { return this.evaluations; }
     133            set
     134            {
     135                this.evaluations = value;
     136                this.OnPropertyChanged("Evaluations");
     137                if (endTime > startTime)
     138                {
     139                    // endTime is set...
     140                    EvaluationsPerSecond = Math.Round(evaluations / TotalTime.TotalSeconds, 2);
     141                }
     142                else if (startTime > endTime)
     143                {
     144                    // only startTime is set...
     145                    TimeSpan currentTimeNeeded = DateTime.Now - startTime;
     146                    EvaluationsPerSecond = Math.Round(evaluations / currentTimeNeeded.TotalSeconds, 2);
     147                }
     148            }
     149        }
     150
     151        private double bestQuality;
     152
     153        public double BestQuality
     154        {
     155            get { return this.bestQuality; }
     156            set
     157            {
     158                this.bestQuality = value;
     159                this.OnPropertyChanged("BestQuality");
     160            }
     161        }
     162
     163        private string bestSolution;
     164
     165        public string BestSolution
     166        {
     167            get { return this.bestSolution; }
     168            set
     169            {
     170                this.bestSolution = value;
     171                this.OnPropertyChanged("BestSolution");
     172            }
     173        }
     174
     175        private double bestKnownQuality;
     176
     177        public double BestKnownQuality
     178        {
     179            get { return this.bestKnownQuality; }
     180            set
     181            {
     182                this.bestKnownQuality = value;
     183                this.OnPropertyChanged("BestKnownQuality");
     184            }
     185        }
     186
     187        private int bestSolutionFoundAt;
     188
     189        public int BestSolutionFoundAt
     190        {
     191            get { return this.bestSolutionFoundAt; }
     192            set
     193            {
     194                this.bestSolutionFoundAt = value;
     195                this.OnPropertyChanged("BestSolutionFoundAt");
     196            }
     197        }
     198
     199        private double evaluationsPerSecond;
     200
     201        public double EvaluationsPerSecond
     202        {
     203            get { return this.evaluationsPerSecond; }
     204            set
     205            {
     206                this.evaluationsPerSecond = value;
     207                this.OnPropertyChanged("EvaluationsPerSecond");
     208            }
     209        }
     210
     211        private DateTime startTime;
     212
     213        public DateTime StartTime
     214        {
     215            get { return this.startTime; }
     216            set
     217            {
     218                this.startTime = value;
     219                this.OnPropertyChanged("StartTime");
     220            }
     221        }
     222
     223        private DateTime endTime;
     224
     225        public DateTime EndTime
     226        {
     227            get { return this.endTime; }
     228            set
     229            {
     230                this.endTime = value;
     231                this.OnPropertyChanged("EndTime");
     232                TotalTime = EndTime - StartTime;
     233            }
     234        }
     235
     236        private TimeSpan totalTime;
     237
     238        public TimeSpan TotalTime
     239        {
     240            get { return this.totalTime; }
     241            set
     242            {
     243                this.totalTime = value;
     244                this.OnPropertyChanged("TotalTime");
     245            }
     246        }
     247
     248        private TimeSpan bestSolutionTime;
     249
     250        public TimeSpan BestSolutionTime
     251        {
     252            get { return this.bestSolutionTime; }
     253            set
     254            {
     255                this.bestSolutionTime = value;
     256                this.OnPropertyChanged("BestSolutionTime");
     257            }
     258        }
     259
     260        public List<FoundSolution> FoundSolutions { get; set; }
    44261
    45262        public string SvgFile { get; set; }
    46263
    47         public TreeInfos TreeInfos { get; set; }
     264        private TreeInfos treeInfos;
     265
     266        public TreeInfos TreeInfos
     267        {
     268            get { return this.treeInfos; }
     269            set
     270            {
     271                this.treeInfos = value;
     272                this.OnPropertyChanged("TreeInfos");
     273            }
     274        }
     275
     276        private RunState runState;
     277
     278        public RunState RunState
     279        {
     280            get { return this.runState; }
     281            set
     282            {
     283                this.runState = value;
     284                this.OnPropertyChanged("RunState");
     285            }
     286        }
    48287
    49288        public override string ToString()
     
    51290            return string.Format("Run #{0}", this.RunNumber);
    52291        }
     292
     293        #region INotifyPropertyChanged members
     294
     295        public event PropertyChangedEventHandler PropertyChanged;
     296
     297        protected void OnPropertyChanged(string propertyName)
     298        {
     299            if (PropertyChanged != null)
     300                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     301        }
     302
     303        #endregion INotifyPropertyChanged members
    53304    }
    54305}
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/ViewModel/EvaluationViewModel.cs

    r12762 r12781  
    1 using System.Collections.ObjectModel;
    2 using HeuristicLab.Algorithms.Bandits.BanditPolicies;
     1using HeuristicLab.Algorithms.Bandits.BanditPolicies;
    32using HeuristicLab.Algorithms.GeneticProgramming;
    43using HeuristicLab.Algorithms.GrammaticalOptimization;
     
    76using System;
    87using System.Collections.Generic;
     8using System.Collections.ObjectModel;
    99using System.ComponentModel;
    1010using System.Linq;
    11 using System.Text;
    12 using System.Threading.Tasks;
    13 using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
    1411
    1512namespace Evaluation.ViewModel
     
    8582        }
    8683
    87         private double bestKnownQuality;
    88 
    89         public double BestKnownQuality
    90         {
    91             get { return this.bestKnownQuality; }
    92             set
    93             {
    94                 this.bestKnownQuality = value;
    95                 this.OnPropertyChanged("BestKnownQuality");
    96             }
    97         }
    98 
    99         private double currentBestQuality;
    100 
    101         public double CurrentBestQuality
    102         {
    103             get { return this.currentBestQuality; }
    104             set
    105             {
    106                 this.currentBestQuality = value;
    107                 this.OnPropertyChanged("CurrentBestQuality");
    108             }
    109         }
    110 
    111         private int evaluations;
    112 
    113         public int Evaluations
    114         {
    115             get { return this.evaluations; }
    116             set
    117             {
    118                 this.evaluations = value;
    119                 this.OnPropertyChanged("Evaluations");
    120             }
    121         }
    122 
    12384        private int nrRuns;
    12485
     
    12990        }
    13091
    131         private int threads;
    132 
    133         public int Threads
    134         {
    135             get { return this.threads; }
    136             set { this.threads = value; this.OnPropertyChanged("Threads"); }
    137         }
    138 
    13992        private int maxLen;
    14093
     
    193146        }
    194147
    195         private string currentRunString;
    196 
    197         public string CurrentRunString
    198         {
    199             get { return this.currentRunString; }
    200             set
    201             {
    202                 currentRunString = value;
    203                 this.OnPropertyChanged("CurrentRunString");
    204             }
    205         }
    206 
    207         private double evaluationsPerSec;
    208 
    209         public double EvaluationsPerSec
    210         {
    211             get { return this.evaluationsPerSec; }
    212             set
    213             {
    214                 evaluationsPerSec = value;
    215                 this.OnPropertyChanged("EvaluationsPerSec");
    216             }
    217         }
    218 
    219         private int bestSolutionFoundAt;
    220 
    221         public int BestSolutionFoundAt
    222         {
    223             get { return this.bestSolutionFoundAt; }
    224             set
    225             {
    226                 bestSolutionFoundAt = value;
    227                 this.OnPropertyChanged("BestSolutionFoundAt");
    228             }
    229         }
    230 
    231         private string bestSolution;
    232 
    233         public string BestSolution
    234         {
    235             get { return this.bestSolution; }
    236             set
    237             {
    238                 bestSolution = value;
    239                 this.OnPropertyChanged("BestSolution");
    240             }
    241         }
    242 
    243148        private ObservableCollection<Run> runs = new ObservableCollection<Run>();
    244149
     
    253158        }
    254159
    255         private Run currentRun;
    256 
    257         public Run CurrentRun
    258         {
    259             get { return this.currentRun; }
    260             set
    261             {
    262                 currentRun = value;
    263                 if (currentRun != null)
    264                 {
    265                     Evaluations = currentRun.Evaluations;
    266                     BestKnownQuality = currentRun.BestKnownQuality;
    267                     CurrentBestQuality = currentRun.BestSolutionQuality;
    268                     EvaluationsPerSec = currentRun.EvaluationsPerSecond;
    269                 }
    270                 this.OnPropertyChanged("CurrentRun");
     160        private Run selectedRun;
     161
     162        public Run SelectedRun
     163        {
     164            get { return this.selectedRun; }
     165            set
     166            {
     167                selectedRun = value;
     168                this.OnPropertyChanged("SelectedRun");
     169            }
     170        }
     171
     172        private string completedRuns;
     173
     174        public string CompletedRuns
     175        {
     176            get { return this.completedRuns; }
     177            set
     178            {
     179                completedRuns = value;
     180                this.OnPropertyChanged("CompletedRuns");
    271181            }
    272182        }
     
    305215            this.algorithms.Add(typeof(SequentialSearch));
    306216            this.algorithms.Add(typeof(MonteCarloTreeSearch));
     217            this.algorithms.Add(typeof(MonteCarloTreeSearch_PruneLeaves));
    307218            this.algorithms.Add(typeof(StandardGP));
    308219            this.algorithms.Add(typeof(OffspringSelectionGP));
    309220
    310             this.selectedAlgorithm = typeof(MonteCarloTreeSearch);
     221            this.selectedAlgorithm = typeof(MonteCarloTreeSearch_PruneLeaves);
    311222        }
    312223
Note: See TracChangeset for help on using the changeset viewer.