Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/14/15 20:42:55 (9 years ago)
Author:
aballeit
Message:

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

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

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/Evaluation.csproj

    r12503 r12762  
    5454      <SubType>Designer</SubType>
    5555    </ApplicationDefinition>
    56     <Compile Include="ViewModel\EvaluationStat.cs" />
     56    <Compile Include="EvaluationStat.cs" />
     57    <Compile Include="Run.cs" />
    5758    <Compile Include="ViewModel\EvaluationViewModel.cs" />
    5859    <Page Include="MainWindow.xaml">
     
    137138      <Name>HeuristicLab.Problems.GrammaticalOptimization</Name>
    138139    </ProjectReference>
     140    <ProjectReference Include="..\WpfTestSvgSample\WpfTestSvgSample.csproj">
     141      <Project>{514a1e9d-0900-46a5-8073-f3c9cb2aaee3}</Project>
     142      <Name>WpfTestSvgSample</Name>
     143    </ProjectReference>
    139144  </ItemGroup>
    140145  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/MainWindow.xaml

    r12503 r12762  
    55        xmlns:charts="http://research.microsoft.com/DynamicDataDisplay/1.0"
    66
    7         Title="MainWindow" Height="576" Width="768">
     7        Title="MainWindow" Height="900" Width="1600" Loaded="Window_Loaded">
    88    <Grid Margin="10">
    99        <Grid.RowDefinitions>
     
    2222            <Grid.ColumnDefinitions>
    2323                <ColumnDefinition Width="Auto" />
     24                <ColumnDefinition Width="Auto" />
    2425                <ColumnDefinition Width="*" />
    2526            </Grid.ColumnDefinitions>
     
    3031                      SelectedValue="{Binding SelectedProblem}"
    3132                      HorizontalAlignment="Left" Grid.Column="1" Grid.Row="0" Width="200" Margin="2">
    32                
     33
    3334            </ComboBox>
    3435            <TextBlock VerticalAlignment="Center" Grid.Column="0" Grid.Row="1">Algorithm:</TextBlock>
     
    4748                          Width="200" Margin="5,0,0,0"></ComboBox>
    4849                <Button Name="ButtonRun" Margin="5,0,0,0" Click="ButtonRun_OnClick" Height="22" VerticalAlignment="Top">Run</Button>
    49                 <Button Name="ButtonPause" Margin="5,0,0,0" Click="ButtonPause_OnClick">Pause</Button>
    50                 <Button Name="ButtonStop" Margin="5,0,0,0" Click="ButtonStop_OnClick">Stop</Button>
     50                <Button Name="ButtonPause" Margin="5,0,0,0" Click="ButtonPause_OnClick" IsEnabled="False">Pause</Button>
     51                <Button Name="ButtonStop" Margin="5,0,0,0" Click="ButtonStop_OnClick" IsEnabled="False">Stop</Button>
     52            </StackPanel>
     53            <StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right">
     54                <Button Name="LoadButton" Click="LoadButton_OnClick">Load</Button>
     55                <Button Name="SaveButton" Click="SaveButton_OnClick" Margin="5,0,0,0">Save</Button>
    5156            </StackPanel>
    5257        </Grid>
    53         <GroupBox Grid.Row="1" Header="Settings" Name="GroupBoxSettings">coming soon...</GroupBox>
     58        <GroupBox Grid.Row="1" Header="Settings" Name="GroupBoxSettings">
     59            <Grid>
     60                <Grid.RowDefinitions>
     61                    <RowDefinition Height="Auto" />
     62                    <RowDefinition Height="Auto" />
     63                </Grid.RowDefinitions>
     64                <Grid.ColumnDefinitions>
     65                    <ColumnDefinition Width="Auto" />
     66                    <ColumnDefinition Width="Auto" />
     67                    <ColumnDefinition Width="Auto" />
     68                    <ColumnDefinition Width="Auto" />
     69                    <ColumnDefinition Width="*" />
     70                </Grid.ColumnDefinitions>
     71                <TextBlock Margin="2" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center">Runs:</TextBlock>
     72                <TextBox Name="TextBoxRuns" Margin="2" Grid.Column="1" Grid.Row="0" Width="100" VerticalAlignment="Center" TextAlignment="Right" Text="{Binding NrRuns}"></TextBox>
     73                <TextBlock Margin="2" Grid.Column="0" Grid.Row="1" VerticalAlignment="Center">MaxEvaluations:</TextBlock>
     74                <TextBox Name="TextBoxMaxEvaluations" Margin="2" Grid.Column="1" Grid.Row="1" Width="100" VerticalAlignment="Center" TextAlignment="Right" Text="{Binding MaxEvaluations}"></TextBox>
     75                <TextBlock Margin="2" Grid.Column="2" Grid.Row="0" VerticalAlignment="Center">MaxLen:</TextBlock>
     76                <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>
     79            </Grid>
     80        </GroupBox>
    5481        <Grid Grid.Row="2">
    5582            <Grid.RowDefinitions>
    5683                <RowDefinition Height="*" />
    57                 <RowDefinition Height="Auto" />
    5884            </Grid.RowDefinitions>
    5985            <Grid.ColumnDefinitions>
    60                 <ColumnDefinition Width="Auto" />
    6186                <ColumnDefinition Width="*" />
    6287                <ColumnDefinition Width="Auto" />
    6388            </Grid.ColumnDefinitions>
    64             <ComboBox Name="ComboBoxVerticalAxis" Grid.Row="0" Grid.Column="0" Width="100" HorizontalAlignment="Center" VerticalAlignment="Center"></ComboBox>
    65 
    66             <d3:ChartPlotter x:Name="ChartPlotter" Grid.Row="0" Grid.Column="1" Margin="10,20,10,10" LegendVisible="False" EnableSmoothPanningForNumericAxes="True">
    67                 <d3:Header Content="{Binding HeaderString}"/>
    68                 <d3:VerticalAxisTitle Content="{Binding VerticalAxisString}" />
    69                 <d3:HorizontalAxisTitle Content="{Binding HorizontalAxisString}"/>
    70             </d3:ChartPlotter>
    71            
    72             <Grid Grid.Column="2" Grid.Row="0" Margin="0,25,0,0">
     89
     90            <TabControl Grid.Row="0" Grid.Column="0" Margin="10,20,10,10" >
     91                <TabItem Header="Run-Detail">
     92                    <Grid>
     93                        <Grid.ColumnDefinitions>
     94                            <ColumnDefinition Width="Auto"></ColumnDefinition>
     95                            <ColumnDefinition Width="*"></ColumnDefinition>
     96                        </Grid.ColumnDefinitions>
     97                        <Grid.RowDefinitions>
     98                            <RowDefinition Height="*"></RowDefinition>
     99                        </Grid.RowDefinitions>
     100                        <ListBox Name="ListBoxRuns" Grid.Column="0" Width="100" ItemsSource="{Binding Runs}" SelectionChanged="ListBoxRuns_OnSelectionChanged"/>
     101                        <TabControl Grid.Column="1">
     102                            <TabItem Header="Chart">
     103                                <Grid>
     104                                    <Grid.RowDefinitions>
     105                                        <RowDefinition Height="*"></RowDefinition>
     106                                    </Grid.RowDefinitions>
     107                                    <Grid.ColumnDefinitions>
     108                                        <ColumnDefinition Width="Auto"></ColumnDefinition>
     109                                        <ColumnDefinition Width="*"></ColumnDefinition>
     110                                    </Grid.ColumnDefinitions>
     111                                    <d3:ChartPlotter Grid.Column="1" x:Name="ChartPlotter" LegendVisible="False" EnableSmoothPanningForNumericAxes="True">
     112                                        <d3:Header Content="{Binding HeaderString}"/>
     113                                        <d3:VerticalAxisTitle Content="{Binding VerticalAxisString}" />
     114                                        <d3:HorizontalAxisTitle Content="{Binding HorizontalAxisString}"/>
     115                                    </d3:ChartPlotter>
     116                                </Grid>
     117                            </TabItem>
     118                            <TabItem Header="Tree" Name="TabItemTree">
     119                                <Grid>
     120                                    <Grid.RowDefinitions>
     121                                        <RowDefinition Height="*"></RowDefinition>
     122                                    </Grid.RowDefinitions>
     123                                    <Grid.ColumnDefinitions>
     124                                        <ColumnDefinition Width="Auto"></ColumnDefinition>
     125                                        <ColumnDefinition Width="*"></ColumnDefinition>
     126                                    </Grid.ColumnDefinitions>
     127                                    <Grid Name="MyGrid" Grid.Column="0" DataContext="{Binding CurrentRun.TreeInfos}">
     128                                        <Grid.RowDefinitions>
     129                                            <RowDefinition Height="Auto"></RowDefinition>
     130                                            <RowDefinition Height="Auto"></RowDefinition>
     131                                            <RowDefinition Height="Auto"></RowDefinition>
     132                                            <RowDefinition Height="Auto"></RowDefinition>
     133                                            <RowDefinition Height="Auto"></RowDefinition>
     134                                            <RowDefinition Height="Auto"></RowDefinition>
     135                                            <RowDefinition Height="Auto"></RowDefinition>
     136                                        </Grid.RowDefinitions>
     137                                        <Grid.ColumnDefinitions>
     138                                            <ColumnDefinition Width="Auto"></ColumnDefinition>
     139                                            <ColumnDefinition Width="Auto"></ColumnDefinition>
     140                                        </Grid.ColumnDefinitions>
     141                                        <TextBlock Grid.Row="0" Grid.Column="0" Text="TotalNodes:"></TextBlock>
     142                                        <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding TotalNodes}" TextAlignment="Right"></TextBlock>
     143                                        <TextBlock Grid.Row="1" Grid.Column="0" Text="UnexpandedNodes:"></TextBlock>
     144                                        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding UnexpandedNodes}" TextAlignment="Right"></TextBlock>
     145                                        <TextBlock Grid.Row="2" Grid.Column="0" Text="ExpandedNodes:"></TextBlock>
     146                                        <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding ExpandedNodes}" TextAlignment="Right"></TextBlock>
     147                                        <TextBlock Grid.Row="3" Grid.Column="0" Text="LeaveNodes:"></TextBlock>
     148                                        <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding LeaveNodes}" TextAlignment="Right"></TextBlock>
     149                                        <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>
     155                                    </Grid>
     156                                    <Frame Grid.Column="1" Name="treeDrawing" Source="pack://application:,,,/WpfTestSvgSample;component/DrawingPage.xaml"/>
     157                                </Grid>
     158                            </TabItem>
     159                        </TabControl>
     160                    </Grid>
     161                </TabItem>
     162
     163                <TabItem Header="Run-Comparison">
     164                    <TabControl Name="TabControlRunComparison" SelectionChanged="TabControlRunComparison_OnSelectionChanged">
     165                        <TabItem Name="TabItemChartRunComparison" Header="Chart">
     166                            <d3:ChartPlotter x:Name="ComparisonChartPlotter" LegendVisible="False" EnableSmoothPanningForNumericAxes="True">
     167                                <d3:Header Content="{Binding HeaderString}"/>
     168                                <d3:VerticalAxisTitle Content="{Binding VerticalAxisString}" />
     169                                <d3:HorizontalAxisTitle Content="{Binding HorizontalAxisString}"/>
     170                            </d3:ChartPlotter>
     171                        </TabItem>
     172                        <TabItem Header="Table">
     173                            <ListView ItemsSource="{Binding Path=Runs}">
     174                                <ListView.View>
     175                                    <GridView>
     176                                        <GridView.Columns>
     177                                            <GridViewColumn DisplayMemberBinding="{Binding Path=RunNumber}"
     178                                                            Header="Run #"/>
     179                                            <GridViewColumn DisplayMemberBinding="{Binding Path=Evaluations}"
     180                                                            Header="Evaluations"/>
     181                                            <GridViewColumn DisplayMemberBinding="{Binding Path=BestKnownQuality}"
     182                                                            Header="BestKnownQuality"/>
     183                                            <GridViewColumn DisplayMemberBinding="{Binding Path=BestSolutionQuality}"
     184                                                            Header="BestFoundQuality"/>
     185                                            <GridViewColumn DisplayMemberBinding="{Binding Path=EvaluationsPerSecond}"
     186                                                            Header="EvaluationsPerSecond"/>
     187                                            <GridViewColumn DisplayMemberBinding="{Binding Path=TotalTime}"
     188                                                            Header="TotalTime"/>
     189                                            <GridViewColumn DisplayMemberBinding="{Binding Path=BestSolutionTime}"
     190                                                            Header="BestSolutionTime"/>
     191                                            <GridViewColumn DisplayMemberBinding="{Binding Path=BestSolution}"
     192                                                            Header="BestSolution"/>
     193                                        </GridView.Columns>
     194                                    </GridView>
     195                                </ListView.View>
     196                            </ListView>
     197                        </TabItem>
     198                    </TabControl>
     199                </TabItem>
     200            </TabControl>
     201
     202            <Grid Grid.Column="1" Grid.Row="0" Margin="0,25,0,0">
    73203                <Grid.RowDefinitions>
     204                    <RowDefinition Height="Auto" />
     205                    <RowDefinition Height="Auto" />
    74206                    <RowDefinition Height="Auto" />
    75207                    <RowDefinition Height="Auto" />
     
    84216                    <ColumnDefinition Width="*" />
    85217                </Grid.ColumnDefinitions>
    86                 <TextBlock Grid.Row="0" Grid.Column="0">Evaluations:</TextBlock>
    87                 <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Evaluations}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    88                 <TextBlock Grid.Row="1" Grid.Column="0">MaxEvaluations:</TextBlock>
    89                 <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding MaxEvaluations}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    90                 <TextBlock Grid.Row="2" Grid.Column="0">CurrentBestQuality:</TextBlock>
    91                 <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding CurrentBestQuality}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    92                 <TextBlock Grid.Row="3" Grid.Column="0">BestKnownQuality:</TextBlock>
    93                 <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding BestKnownQuality}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    94                 <TextBlock Grid.Row="4" Grid.Column="0">MaxLen:</TextBlock>
    95                 <TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding MaxLen}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    96                 <TextBlock Grid.Row="5" Grid.Column="0">Evaluations/sec:</TextBlock>
    97                 <TextBlock Grid.Row="5" Grid.Column="1" Text="{Binding EvaluationsPerSec}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
    98                 <TextBlock Grid.Row="6" Grid.Column="0">BestSolutionFoundAt:</TextBlock>
    99                 <TextBlock Grid.Row="6" Grid.Column="1" Text="{Binding BestSolutionFoundAt}" Margin="5,0,0,0" HorizontalAlignment="Right"/>
     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"/>
    100236            </Grid>
    101 
    102             <ComboBox Name="ComboBoxHorizontalAxis" Grid.Row="1" Grid.Column="1" Width="100" HorizontalAlignment="Center" VerticalAlignment="Center"></ComboBox>
    103             <StackPanel Grid.Column="2" Grid.Row="1" Orientation="Horizontal">
    104                 <Button Margin="2">Load</Button>
    105                 <Button Margin="2">Save</Button>
    106             </StackPanel>
    107237        </Grid>
    108238    </Grid>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/MainWindow.xaml.cs

    r12503 r12762  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Diagnostics;
    5 using System.Linq;
    6 using System.Text;
    7 using System.Threading.Tasks;
    8 using System.Windows;
    9 using System.Windows.Controls;
    10 using System.Windows.Data;
    11 using System.Windows.Documents;
    12 using System.Windows.Input;
    13 using System.Windows.Media;
    14 using System.Windows.Media.Imaging;
    15 using System.Windows.Navigation;
    16 using System.Windows.Shapes;
    17 using System.Windows.Threading;
     1using System.Collections.ObjectModel;
     2using System.Threading;
     3using System.Xml.Serialization;
    184using Evaluation.ViewModel;
    195using HeuristicLab.Algorithms.Bandits;
     
    2612using Microsoft.Research.DynamicDataDisplay;
    2713using Microsoft.Research.DynamicDataDisplay.DataSources;
     14using System;
     15using System.Collections.Generic;
     16using System.ComponentModel;
     17using System.Diagnostics;
     18using System.IO;
     19using System.Windows;
     20using System.Windows.Controls;
     21using System.Windows.Threading;
     22using Microsoft.Win32;
     23using WpfTestSvgSample;
    2824
    2925namespace Evaluation
     
    3632        private BackgroundWorker worker = new BackgroundWorker();
    3733        private EvaluationViewModel vm;
    38         private List<EvaluationStat> stats = new List<EvaluationStat>();
    39 
    40         private Stack<EvaluationStat> newStats = new Stack<EvaluationStat>();
     34
    4135        private DispatcherTimer updateCollectionTimer;
    4236
     37        private DrawingPage treeDrawingPage;
     38
    4339        public MainWindow()
    4440        {
    4541            InitializeComponent();
     42            CenterWindowOnScreen();
    4643            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;
     49            vm.VerticalAxisString = "SolutionQuality";
     50            vm.HorizontalAxisString = "Iteration";
    4751            this.worker.WorkerSupportsCancellation = true;
    4852            this.worker.DoWork += worker_DoWork;
     
    5458            ////updateCollectionTimer.Tick += updateCollectionTimer_Tick;
    5559            ////updateCollectionTimer.Start();
    56 
    57             vm.HorizontalAxisString = "Evaluations";
    58             vm.VerticalAxisString = "BestKnownQuality";
    59 
     60        }
     61
     62        private void CenterWindowOnScreen()
     63        {
     64            double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
     65            double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
     66            double windowWidth = this.Width;
     67            double windowHeight = this.Height;
     68            this.Left = (screenWidth / 2) - (windowWidth / 2);
     69            this.Top = (screenHeight / 2) - (windowHeight / 2);
    6070        }
    6171
     
    7181        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    7282        {
    73             if (stats.Count > 0)
    74             {
    75                 TimeSpan timeNeeded = stats[stats.Count - 1].Time - stats[0].Time;
    76                 vm.EvaluationsPerSec = Math.Round(vm.Evaluations / timeNeeded.TotalSeconds, 2);
    77             }
    78             var ds = new EnumerableDataSource<EvaluationStat>(stats);
     83            ButtonRun.IsEnabled = true;
     84            TextBoxMaxEvaluations.IsEnabled = true;
     85            TextBoxMaxLen.IsEnabled = true;
     86            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);
    7995            ds.SetXMapping(x => x.Iteration);
    8096            ds.SetYMapping(y => y.CurrentBestQuality);
     
    85101            graph.AddToPlotter(ChartPlotter);
    86102
    87             Debug.WriteLine("DONE");
    88             ButtonRun.IsEnabled = true;
    89         }
     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
    90115        void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    91116        {
     
    95120        void worker_DoWork(object sender, DoWorkEventArgs e)
    96121        {
     122
    97123            Type algorithmType = vm.SelectedAlgorithm;
    98124
     
    108134                policyInstance = new UCTPolicy();
    109135            }
    110             else if (policy == typeof (ThresholdAscentPolicy))
     136            else if (policy == typeof(ThresholdAscentPolicy))
    111137            {
    112138                policyInstance = new ThresholdAscentPolicy();
     
    117143            }
    118144
    119             vm.MaxLen = 1000;
    120             vm.MaxEvaluations = 250000;
    121 
    122145            vm.BestKnownQuality = problem.BestKnownQuality(vm.MaxLen);
    123146
    124             vm.Evaluations = 0;
    125             vm.CurrentBestQuality = 0;
    126 
    127             stats.Clear();
    128 
    129             SolverBase solver = null;
    130 
    131             if (algorithmType == typeof(MonteCarloTreeSearch))
    132             {
    133                 solver = new MonteCarloTreeSearch(problem, vm.MaxLen, random, policyInstance, new RandomSimulation(problem, random, vm.MaxLen));
    134             }
    135             else if (algorithmType == typeof(SequentialSearch))
    136             {
    137                 solver = new SequentialSearch(problem, vm.MaxLen, random, 0,
    138                     new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, policyInstance));
    139             }
    140             else if (algorithmType == typeof(RandomSearch))
    141             {
    142                 solver = new RandomSearch(problem, random, vm.MaxLen);
    143             }
    144             else if (algorithmType == typeof(StandardGP))
    145             {
    146                 solver = new StandardGP(problem, random);
    147             }
    148             else if (algorithmType == typeof(OffspringSelectionGP))
    149             {
    150                 solver = new OffspringSelectionGP(problem, random);
    151             }
    152 
    153             solver.FoundNewBestSolution += (sentence, quality) => vm.BestSolutionFoundAt = vm.Evaluations;
    154             solver.SolutionEvaluated += (sentence, quality) =>
    155             {
    156                 vm.Evaluations++;
    157                 if (vm.CurrentBestQuality < quality)
    158                 {
    159                     vm.CurrentBestQuality = quality;
    160                 }
    161                 stats.Add(new EvaluationStat(DateTime.Now, vm.Evaluations, quality, vm.CurrentBestQuality));
    162             };
    163 
    164             solver.Run(vm.MaxEvaluations);
     147            for (int i = 0; i < vm.NrRuns; i++)
     148            {
     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
     155                ISolver solver = null;
     156
     157                if (algorithmType == typeof(MonteCarloTreeSearch))
     158                {
     159                    solver = new MonteCarloTreeSearch(problem, vm.MaxLen, random, policyInstance, new RandomSimulation(problem, random, vm.MaxLen));
     160                }
     161                else if (algorithmType == typeof(SequentialSearch))
     162                {
     163                    solver = new SequentialSearch(problem, vm.MaxLen, random, 0,
     164                        new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, policyInstance));
     165                }
     166                else if (algorithmType == typeof(RandomSearch))
     167                {
     168                    solver = new RandomSearch(problem, random, vm.MaxLen);
     169                }
     170                else if (algorithmType == typeof(StandardGP))
     171                {
     172                    solver = new StandardGP(problem, random);
     173                }
     174                else if (algorithmType == typeof(OffspringSelectionGP))
     175                {
     176                    solver = new OffspringSelectionGP(problem, random);
     177                }
     178
     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()
     230        {
     231            ChartPlotter.Children.RemoveAll<LineGraph>();
    165232        }
    166233
    167234        private void ButtonRun_OnClick(object sender, RoutedEventArgs e)
    168235        {
    169             ChartPlotter.Children.RemoveAll<LineGraph>();
     236            ClearChart();
     237            vm.Runs.Clear();
     238            vm.CurrentRun = null;
    170239            ButtonRun.IsEnabled = false;
     240            TextBoxMaxEvaluations.IsEnabled = false;
     241            TextBoxMaxLen.IsEnabled = false;
     242            TextBoxRuns.IsEnabled = false;
     243            TextBoxThreads.IsEnabled = false;
    171244            worker.RunWorkerAsync();
    172245        }
     
    174247        private void ButtonPause_OnClick(object sender, RoutedEventArgs e)
    175248        {
     249            //if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch))
     250            //{
     251            //    MonteCarloTreeSearch mcts = (MonteCarloTreeSearch)solver;
     252            //    mcts.PauseContinue();
     253            //    if (mcts.IsPaused)
     254            //    {
     255            //        ButtonPause.Content = "Continue";
     256            //    }
     257            //    else
     258            //    {
     259            //        ButtonPause.Content = "Pause";
     260            //    }
     261            //}
    176262        }
    177263
     
    183269        private void ComboBoxAlgorithms_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    184270        {
    185             if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch)
    186                 || vm.SelectedAlgorithm == typeof(SequentialSearch))
     271            if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch))
    187272            {
    188273                ComboBoxPolicies.IsEnabled = true;
     274                TabItemTree.IsEnabled = true;
     275            }
     276            else if (vm.SelectedAlgorithm == typeof(SequentialSearch))
     277            {
     278                ComboBoxPolicies.IsEnabled = true;
     279                TabItemTree.IsEnabled = false;
    189280            }
    190281            else
    191282            {
    192283                ComboBoxPolicies.IsEnabled = false;
    193             }
     284                TabItemTree.IsEnabled = false;
     285            }
     286        }
     287
     288        private void Window_Loaded(object sender, RoutedEventArgs e)
     289        {
     290            treeDrawingPage = treeDrawing.Content as DrawingPage;
     291        }
     292
     293        private void ListBoxRuns_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
     294        {
     295            if (ListBoxRuns.SelectedItem != null)
     296            {
     297                vm.CurrentRun = (Run)ListBoxRuns.SelectedItem;
     298                DrawCharts(vm.CurrentRun);
     299            }
     300        }
     301
     302        public void SaveToFile()
     303        {
     304            SaveFileDialog dlg = new SaveFileDialog();
     305            dlg.FileName = "runs"; // Default file name
     306            dlg.DefaultExt = ".xml"; // Default file extension
     307
     308            // Show save file dialog box
     309            Nullable<bool> result = dlg.ShowDialog();
     310
     311            // Process save file dialog box results
     312            if (result == true)
     313            {
     314                // Save document
     315                string filename = dlg.FileName;
     316
     317                XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<Run>));
     318                using (TextWriter writer = new StreamWriter(filename))
     319                {
     320                    serializer.Serialize(writer, vm.Runs);
     321                }
     322            }
     323
     324        }
     325
     326        public void LoadFromFile()
     327        {
     328            OpenFileDialog dlg = new OpenFileDialog();
     329
     330            // Show save file dialog box
     331            Nullable<bool> result = dlg.ShowDialog();
     332
     333            // Process save file dialog box results
     334            if (result == true)
     335            {
     336                // Load document
     337                string filename = dlg.FileName;
     338
     339                XmlSerializer deserializer = new XmlSerializer(typeof(ObservableCollection<Run>));
     340                using (TextReader reader = new StreamReader(filename))
     341                {
     342                    object obj = deserializer.Deserialize(reader);
     343                    vm.Runs = (ObservableCollection<Run>)obj;
     344
     345                }
     346            }
     347        }
     348
     349        private void LoadButton_OnClick(object sender, RoutedEventArgs e)
     350        {
     351           LoadFromFile();
     352        }
     353
     354        private void SaveButton_OnClick(object sender, RoutedEventArgs e)
     355        {
     356            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            ////}
    194375        }
    195376    }
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/ViewModel/EvaluationViewModel.cs

    r12503 r12762  
    1 using HeuristicLab.Algorithms.Bandits.BanditPolicies;
     1using System.Collections.ObjectModel;
     2using HeuristicLab.Algorithms.Bandits.BanditPolicies;
    23using HeuristicLab.Algorithms.GeneticProgramming;
    34using HeuristicLab.Algorithms.GrammaticalOptimization;
     
    108109        }
    109110
    110         private long evaluations;
    111 
    112         public long Evaluations
     111        private int evaluations;
     112
     113        public int Evaluations
    113114        {
    114115            get { return this.evaluations; }
     
    120121        }
    121122
     123        private int nrRuns;
     124
     125        public int NrRuns
     126        {
     127            get { return this.nrRuns; }
     128            set { this.nrRuns = value; this.OnPropertyChanged("NrRuns"); }
     129        }
     130
     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
    122139        private int maxLen;
    123140
     
    176193        }
    177194
     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
    178207        private double evaluationsPerSec;
    179208
     
    188217        }
    189218
    190         private long bestSolutionFoundAt;
    191 
    192         public long BestSolutionFoundAt
     219        private int bestSolutionFoundAt;
     220
     221        public int BestSolutionFoundAt
    193222        {
    194223            get { return this.bestSolutionFoundAt; }
     
    197226                bestSolutionFoundAt = value;
    198227                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
     243        private ObservableCollection<Run> runs = new ObservableCollection<Run>();
     244
     245        public ObservableCollection<Run> Runs
     246        {
     247            get { return this.runs; }
     248            set
     249            {
     250                runs = value;
     251                this.OnPropertyChanged("Runs");
     252            }
     253        }
     254
     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");
    199271            }
    200272        }
  • branches/HeuristicLab.Problems.GrammaticalOptimization/GrammaticalOptimization.sln

    r12503 r12762  
    7272Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicDataDisplay", "DynamicDataDisplay\DynamicDataDisplay.csproj", "{ECD37682-DF7E-409F-912D-0965634556B5}"
    7373EndProject
     74Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphVizWrapper", "GraphVizWrapper\GraphVizWrapper.csproj", "{CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}"
     75EndProject
     76Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Converters", "SharpVectorConverters\SharpVectors.Converters.csproj", "{E8056611-E49C-4BC3-A682-A629D5CEC11C}"
     77EndProject
     78Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Core", "SharpVectorCore\SharpVectors.Core.csproj", "{D6BB65FC-240E-4241-B2ED-A7FB3F13E978}"
     79EndProject
     80Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Css", "SharpVectorCss\SharpVectors.Css.csproj", "{351B0A6E-2F6B-497A-844B-DCB5A502FB0D}"
     81EndProject
     82Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Dom", "SharpVectorDom\SharpVectors.Dom.csproj", "{FE34CBC0-D23C-4A95-BA64-83A031814010}"
     83EndProject
     84Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Model", "SharpVectorModel\SharpVectors.Model.csproj", "{5D336F48-3FB9-4382-B4B9-06974C764007}"
     85EndProject
     86Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Rendering.Gdi", "SharpVectorRenderingGdi\SharpVectors.Rendering.Gdi.csproj", "{0AD99D97-24ED-484D-9430-9905811F8A4F}"
     87EndProject
     88Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Rendering.Wpf", "SharpVectorRenderingWpf\SharpVectors.Rendering.Wpf.csproj", "{A2576CE0-E492-490F-97E9-C0E7ABAFAF27}"
     89EndProject
     90Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Runtime", "SharpVectorRuntime\SharpVectors.Runtime.csproj", "{2CD52982-A1C2-4A14-9D69-D64719357216}"
     91EndProject
     92Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfTestSvgSample", "WpfTestSvgSample\WpfTestSvgSample.csproj", "{514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}"
     93EndProject
    7494Global
    7595  GlobalSection(SolutionConfigurationPlatforms) = preSolution
    7696    Debug|Any CPU = Debug|Any CPU
     97    Documentation|Any CPU = Documentation|Any CPU
    7798    Release|Any CPU = Release|Any CPU
    7899    ReleaseXBAP|Any CPU = ReleaseXBAP|Any CPU
     
    81102    {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    82103    {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Debug|Any CPU.Build.0 = Debug|Any CPU
     104    {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     105    {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    83106    {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Release|Any CPU.ActiveCfg = Release|Any CPU
    84107    {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Release|Any CPU.Build.0 = Release|Any CPU
     
    87110    {EEA07488-1A51-412A-A52C-53B754A628B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    88111    {EEA07488-1A51-412A-A52C-53B754A628B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
     112    {EEA07488-1A51-412A-A52C-53B754A628B3}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     113    {EEA07488-1A51-412A-A52C-53B754A628B3}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    89114    {EEA07488-1A51-412A-A52C-53B754A628B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
    90115    {EEA07488-1A51-412A-A52C-53B754A628B3}.Release|Any CPU.Build.0 = Release|Any CPU
     
    93118    {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    94119    {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Debug|Any CPU.Build.0 = Debug|Any CPU
     120    {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     121    {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    95122    {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Release|Any CPU.ActiveCfg = Release|Any CPU
    96123    {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Release|Any CPU.Build.0 = Release|Any CPU
     
    99126    {24408F7D-EE0F-4886-A08B-EC324D662E47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    100127    {24408F7D-EE0F-4886-A08B-EC324D662E47}.Debug|Any CPU.Build.0 = Debug|Any CPU
     128    {24408F7D-EE0F-4886-A08B-EC324D662E47}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     129    {24408F7D-EE0F-4886-A08B-EC324D662E47}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    101130    {24408F7D-EE0F-4886-A08B-EC324D662E47}.Release|Any CPU.ActiveCfg = Release|Any CPU
    102131    {24408F7D-EE0F-4886-A08B-EC324D662E47}.Release|Any CPU.Build.0 = Release|Any CPU
     
    105134    {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    106135    {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
     136    {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     137    {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    107138    {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
    108139    {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Release|Any CPU.Build.0 = Release|Any CPU
     
    111142    {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    112143    {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
     144    {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     145    {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    113146    {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
    114147    {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Release|Any CPU.Build.0 = Release|Any CPU
     
    117150    {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    118151    {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Debug|Any CPU.Build.0 = Debug|Any CPU
     152    {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     153    {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    119154    {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Release|Any CPU.ActiveCfg = Release|Any CPU
    120155    {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Release|Any CPU.Build.0 = Release|Any CPU
     
    123158    {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    124159    {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
     160    {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     161    {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    125162    {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
    126163    {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Release|Any CPU.Build.0 = Release|Any CPU
     
    129166    {E8138227-0C64-4E85-B676-21D3B97F254F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    130167    {E8138227-0C64-4E85-B676-21D3B97F254F}.Debug|Any CPU.Build.0 = Debug|Any CPU
     168    {E8138227-0C64-4E85-B676-21D3B97F254F}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     169    {E8138227-0C64-4E85-B676-21D3B97F254F}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    131170    {E8138227-0C64-4E85-B676-21D3B97F254F}.Release|Any CPU.ActiveCfg = Release|Any CPU
    132171    {E8138227-0C64-4E85-B676-21D3B97F254F}.Release|Any CPU.Build.0 = Release|Any CPU
     
    135174    {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    136175    {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Debug|Any CPU.Build.0 = Debug|Any CPU
     176    {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     177    {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    137178    {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Release|Any CPU.ActiveCfg = Release|Any CPU
    138179    {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Release|Any CPU.Build.0 = Release|Any CPU
     
    141182    {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    142183    {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
     184    {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     185    {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    143186    {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
    144187    {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Release|Any CPU.Build.0 = Release|Any CPU
     
    147190    {D043325A-097F-4512-A8FC-CF706577FA46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    148191    {D043325A-097F-4512-A8FC-CF706577FA46}.Debug|Any CPU.Build.0 = Debug|Any CPU
     192    {D043325A-097F-4512-A8FC-CF706577FA46}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     193    {D043325A-097F-4512-A8FC-CF706577FA46}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    149194    {D043325A-097F-4512-A8FC-CF706577FA46}.Release|Any CPU.ActiveCfg = Release|Any CPU
    150195    {D043325A-097F-4512-A8FC-CF706577FA46}.Release|Any CPU.Build.0 = Release|Any CPU
     
    153198    {ECD37682-DF7E-409F-912D-0965634556B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    154199    {ECD37682-DF7E-409F-912D-0965634556B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
     200    {ECD37682-DF7E-409F-912D-0965634556B5}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     201    {ECD37682-DF7E-409F-912D-0965634556B5}.Documentation|Any CPU.Build.0 = Debug|Any CPU
    155202    {ECD37682-DF7E-409F-912D-0965634556B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
    156203    {ECD37682-DF7E-409F-912D-0965634556B5}.Release|Any CPU.Build.0 = Release|Any CPU
    157204    {ECD37682-DF7E-409F-912D-0965634556B5}.ReleaseXBAP|Any CPU.ActiveCfg = ReleaseXBAP|Any CPU
    158205    {ECD37682-DF7E-409F-912D-0965634556B5}.ReleaseXBAP|Any CPU.Build.0 = ReleaseXBAP|Any CPU
     206    {CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     207    {CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
     208    {CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     209    {CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}.Documentation|Any CPU.Build.0 = Debug|Any CPU
     210    {CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
     211    {CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}.Release|Any CPU.Build.0 = Release|Any CPU
     212    {CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     213    {CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     214    {E8056611-E49C-4BC3-A682-A629D5CEC11C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     215    {E8056611-E49C-4BC3-A682-A629D5CEC11C}.Debug|Any CPU.Build.0 = Debug|Any CPU
     216    {E8056611-E49C-4BC3-A682-A629D5CEC11C}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     217    {E8056611-E49C-4BC3-A682-A629D5CEC11C}.Documentation|Any CPU.Build.0 = Debug|Any CPU
     218    {E8056611-E49C-4BC3-A682-A629D5CEC11C}.Release|Any CPU.ActiveCfg = Release|Any CPU
     219    {E8056611-E49C-4BC3-A682-A629D5CEC11C}.Release|Any CPU.Build.0 = Release|Any CPU
     220    {E8056611-E49C-4BC3-A682-A629D5CEC11C}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     221    {E8056611-E49C-4BC3-A682-A629D5CEC11C}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     222    {D6BB65FC-240E-4241-B2ED-A7FB3F13E978}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     223    {D6BB65FC-240E-4241-B2ED-A7FB3F13E978}.Debug|Any CPU.Build.0 = Debug|Any CPU
     224    {D6BB65FC-240E-4241-B2ED-A7FB3F13E978}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
     225    {D6BB65FC-240E-4241-B2ED-A7FB3F13E978}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
     226    {D6BB65FC-240E-4241-B2ED-A7FB3F13E978}.Release|Any CPU.ActiveCfg = Release|Any CPU
     227    {D6BB65FC-240E-4241-B2ED-A7FB3F13E978}.Release|Any CPU.Build.0 = Release|Any CPU
     228    {D6BB65FC-240E-4241-B2ED-A7FB3F13E978}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     229    {D6BB65FC-240E-4241-B2ED-A7FB3F13E978}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     230    {351B0A6E-2F6B-497A-844B-DCB5A502FB0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     231    {351B0A6E-2F6B-497A-844B-DCB5A502FB0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
     232    {351B0A6E-2F6B-497A-844B-DCB5A502FB0D}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
     233    {351B0A6E-2F6B-497A-844B-DCB5A502FB0D}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
     234    {351B0A6E-2F6B-497A-844B-DCB5A502FB0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
     235    {351B0A6E-2F6B-497A-844B-DCB5A502FB0D}.Release|Any CPU.Build.0 = Release|Any CPU
     236    {351B0A6E-2F6B-497A-844B-DCB5A502FB0D}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     237    {351B0A6E-2F6B-497A-844B-DCB5A502FB0D}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     238    {FE34CBC0-D23C-4A95-BA64-83A031814010}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     239    {FE34CBC0-D23C-4A95-BA64-83A031814010}.Debug|Any CPU.Build.0 = Debug|Any CPU
     240    {FE34CBC0-D23C-4A95-BA64-83A031814010}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
     241    {FE34CBC0-D23C-4A95-BA64-83A031814010}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
     242    {FE34CBC0-D23C-4A95-BA64-83A031814010}.Release|Any CPU.ActiveCfg = Release|Any CPU
     243    {FE34CBC0-D23C-4A95-BA64-83A031814010}.Release|Any CPU.Build.0 = Release|Any CPU
     244    {FE34CBC0-D23C-4A95-BA64-83A031814010}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     245    {FE34CBC0-D23C-4A95-BA64-83A031814010}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     246    {5D336F48-3FB9-4382-B4B9-06974C764007}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     247    {5D336F48-3FB9-4382-B4B9-06974C764007}.Debug|Any CPU.Build.0 = Debug|Any CPU
     248    {5D336F48-3FB9-4382-B4B9-06974C764007}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
     249    {5D336F48-3FB9-4382-B4B9-06974C764007}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
     250    {5D336F48-3FB9-4382-B4B9-06974C764007}.Release|Any CPU.ActiveCfg = Release|Any CPU
     251    {5D336F48-3FB9-4382-B4B9-06974C764007}.Release|Any CPU.Build.0 = Release|Any CPU
     252    {5D336F48-3FB9-4382-B4B9-06974C764007}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     253    {5D336F48-3FB9-4382-B4B9-06974C764007}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     254    {0AD99D97-24ED-484D-9430-9905811F8A4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     255    {0AD99D97-24ED-484D-9430-9905811F8A4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
     256    {0AD99D97-24ED-484D-9430-9905811F8A4F}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
     257    {0AD99D97-24ED-484D-9430-9905811F8A4F}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
     258    {0AD99D97-24ED-484D-9430-9905811F8A4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
     259    {0AD99D97-24ED-484D-9430-9905811F8A4F}.Release|Any CPU.Build.0 = Release|Any CPU
     260    {0AD99D97-24ED-484D-9430-9905811F8A4F}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     261    {0AD99D97-24ED-484D-9430-9905811F8A4F}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     262    {A2576CE0-E492-490F-97E9-C0E7ABAFAF27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     263    {A2576CE0-E492-490F-97E9-C0E7ABAFAF27}.Debug|Any CPU.Build.0 = Debug|Any CPU
     264    {A2576CE0-E492-490F-97E9-C0E7ABAFAF27}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
     265    {A2576CE0-E492-490F-97E9-C0E7ABAFAF27}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
     266    {A2576CE0-E492-490F-97E9-C0E7ABAFAF27}.Release|Any CPU.ActiveCfg = Release|Any CPU
     267    {A2576CE0-E492-490F-97E9-C0E7ABAFAF27}.Release|Any CPU.Build.0 = Release|Any CPU
     268    {A2576CE0-E492-490F-97E9-C0E7ABAFAF27}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     269    {A2576CE0-E492-490F-97E9-C0E7ABAFAF27}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     270    {2CD52982-A1C2-4A14-9D69-D64719357216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     271    {2CD52982-A1C2-4A14-9D69-D64719357216}.Debug|Any CPU.Build.0 = Debug|Any CPU
     272    {2CD52982-A1C2-4A14-9D69-D64719357216}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     273    {2CD52982-A1C2-4A14-9D69-D64719357216}.Documentation|Any CPU.Build.0 = Debug|Any CPU
     274    {2CD52982-A1C2-4A14-9D69-D64719357216}.Release|Any CPU.ActiveCfg = Release|Any CPU
     275    {2CD52982-A1C2-4A14-9D69-D64719357216}.Release|Any CPU.Build.0 = Release|Any CPU
     276    {2CD52982-A1C2-4A14-9D69-D64719357216}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     277    {2CD52982-A1C2-4A14-9D69-D64719357216}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
     278    {514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     279    {514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
     280    {514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
     281    {514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}.Documentation|Any CPU.Build.0 = Debug|Any CPU
     282    {514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
     283    {514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}.Release|Any CPU.Build.0 = Release|Any CPU
     284    {514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}.ReleaseXBAP|Any CPU.ActiveCfg = Release|Any CPU
     285    {514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}.ReleaseXBAP|Any CPU.Build.0 = Release|Any CPU
    159286  EndGlobalSection
    160287  GlobalSection(SolutionProperties) = preSolution
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/Base/TreeNode.cs

    r12503 r12762  
    1616        public List<TreeNode> children;
    1717        public IBanditPolicyActionInfo actionInfo;
     18        public int level;
    1819
    19         public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo)
     20        public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo, int level)
    2021        {
    2122            this.parent = parent;
    2223            this.phrase = phrase;
    2324            this.actionInfo = actionInfo;
     25            this.level = level;
    2426        }
    2527        public bool IsLeaf()
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/HeuristicLab.Algorithms.MonteCarloTreeSearch.csproj

    r12098 r12762  
    3333    <Reference Include="System" />
    3434    <Reference Include="System.Core" />
     35    <Reference Include="System.Drawing" />
    3536    <Reference Include="System.Xml.Linq" />
    3637    <Reference Include="System.Data.DataSetExtensions" />
     
    4041  </ItemGroup>
    4142  <ItemGroup>
     43    <Compile Include="Base\TreeInfos.cs" />
    4244    <Compile Include="Simulation\ISimulation.cs" />
    4345    <Compile Include="MonteCarloTreeSearch.cs" />
     
    4749  </ItemGroup>
    4850  <ItemGroup>
     51    <ProjectReference Include="..\GraphVizWrapper\GraphVizWrapper.csproj">
     52      <Project>{cfec60dc-14e0-47e4-a60e-8919fb5fef5d}</Project>
     53      <Name>GraphVizWrapper</Name>
     54    </ProjectReference>
    4955    <ProjectReference Include="..\HeuristicLab.Algorithms.Bandits\HeuristicLab.Algorithms.Bandits.csproj">
    5056      <Project>{24408f7d-ee0f-4886-a08b-ec324d662e47}</Project>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/MonteCarloTreeSearch.cs

    r12503 r12762  
    11using System;
    22using System.Collections.Generic;
     3using System.Drawing;
    34using System.Linq;
     5using System.Net.Mail;
     6using System.Text;
     7using System.Threading;
     8using GraphVizWrapper;
     9using GraphVizWrapper.Commands;
     10using GraphVizWrapper.Queries;
    411using HeuristicLab.Algorithms.Bandits;
    512using HeuristicLab.Algorithms.GrammaticalOptimization;
     
    2027        private readonly ISimulation simulation;
    2128        private TreeNode rootNode;
    22 
    23         public MonteCarloTreeSearch(IProblem problem, int maxLen, Random random, IBanditPolicy behaviourPolicy, ISimulation simulationPolicy)
     29        private bool isPaused = false;
     30        private object pauseLock = new object();
     31
     32        public MonteCarloTreeSearch(IProblem problem, int maxLen, Random random, IBanditPolicy behaviourPolicy,
     33            ISimulation simulationPolicy)
    2434        {
    2535            this.problem = problem;
     
    3141        }
    3242
    33         public bool StopRequested
    34         {
    35             get;
    36             set;
     43        public bool StopRequested { get; set; }
     44
     45        public bool IsPaused
     46        {
     47            get { return this.isPaused; }
    3748        }
    3849
     
    4253            for (int i = 0; !StopRequested && i < maxIterations; i++)
    4354            {
     55                lock (pauseLock)
     56                {
     57                    if (isPaused)
     58                    {
     59                        Monitor.Wait(pauseLock);
     60                    }
     61                }
    4462                TreeNode currentNode = rootNode;
    4563
     
    5371                string phrase = currentNode.phrase;
    5472
    55                 if (!grammar.IsTerminal(phrase) && phrase.Length <= maxLen)
    56                 {
     73                if (phrase.Length <= maxLen)
     74                {
     75                    // Version 2:
     76                    if (currentNode.children != null && !currentNode.children.Any())
     77                    {
     78                        // already removed all child nodes so remove it too..
     79                        currentNode.parent.children.Remove(currentNode);
     80                        continue;
     81                    }
    5782                    ExpandTreeNode(currentNode);
    58 
    59                     currentNode =
    60                         currentNode.children[behaviourPolicy.SelectAction(random, currentNode.GetChildActionInfos())];
     83                    if (currentNode.children.Any())
     84                    {
     85                        currentNode =
     86                            currentNode.children[behaviourPolicy.SelectAction(random, currentNode.GetChildActionInfos())
     87                                ];
     88                    }
     89                    else
     90                    {
     91                        // Version 2:
     92                        // remove currentNode from tree..
     93                        currentNode.parent.children.Remove(currentNode);
     94                    }
    6195                }
    6296                if (currentNode.phrase.Length <= maxLen)
    6397                {
    64                     double quality = simulation.Simulate(currentNode);
    65                     OnSolutionEvaluated(phrase, quality);
     98                    string simulatedPhrase;
     99                    double quality = simulation.Simulate(currentNode, out simulatedPhrase);
     100                    OnSolutionEvaluated(simulatedPhrase, quality);
    66101
    67102                    Propagate(currentNode, quality);
    68                 }
    69             }
     103
     104                }
     105            }
     106        }
     107
     108        private bool HasNonTerminal(string phrase)
     109        {
     110            foreach (char symbol in phrase)
     111            {
     112                if (grammar.IsNonTerminal(symbol))
     113                {
     114                    return true;
     115                }
     116            }
     117
     118            return false;
    70119        }
    71120
     
    91140                            if (newSequence.Length <= maxLen)
    92141                            {
    93                                 TreeNode childNode = new TreeNode(treeNode, newSequence.ToString(), behaviourPolicy.CreateActionInfo());
     142                                TreeNode childNode = new TreeNode(treeNode, newSequence.ToString(),
     143                                    behaviourPolicy.CreateActionInfo(), treeNode.level + 1);
    94144                                treeNode.children.Add(childNode);
    95145                            }
     
    104154            StopRequested = false;
    105155            bestQuality = 0.0;
    106             rootNode = new TreeNode(null, grammar.SentenceSymbol.ToString(), behaviourPolicy.CreateActionInfo());
     156            rootNode = new TreeNode(null, grammar.SentenceSymbol.ToString(), behaviourPolicy.CreateActionInfo(), 0);
    107157        }
    108158
     
    117167        }
    118168
    119         public void PrintStats()
    120         {
    121             //Console.WriteLine("depth: {0,5} tries: {1,5} best phrase {2,50} bestQ {3:F3}", maxSearchDepth, tries, bestPhrase, bestQuality);
    122 
    123             //// use behaviour strategy to generate the currently prefered sentence
    124             //var policy = behaviourPolicy;
    125 
    126             //var n = rootNode;
    127 
    128             //while (n != null)
    129             //{
    130             //    var phrase = n.phrase;
    131             //    Console.ForegroundColor = ConsoleColor.White;
    132             //    Console.WriteLine("{0,-30}", phrase);
    133             //    var children = n.children;
    134             //    if (children == null || !children.Any()) break;
    135             //    var values = children.Select(ch => policy.GetValue(ch.phrase));
    136             //    var maxValue = values.Max();
    137             //    if (maxValue == 0) maxValue = 1.0;
    138 
    139             //    // write phrases
    140             //    foreach (var ch in children)
    141             //    {
    142             //        SetColorForValue(policy.GetValue(ch.phrase) / maxValue);
    143             //        Console.Write(" {0,-4}", ch.phrase.Substring(Math.Max(0, ch.phrase.Length - 3), Math.Min(3, ch.phrase.Length)));
    144             //    }
    145             //    Console.WriteLine();
    146 
    147             //    // write values
    148             //    foreach (var ch in children)
    149             //    {
    150             //        SetColorForValue(policy.GetValue(ch.phrase) / maxValue);
    151             //        Console.Write(" {0:F2}", policy.GetValue(ch.phrase) * 10.0);
    152             //    }
    153             //    Console.WriteLine();
    154 
    155             //    // write tries
    156             //    foreach (var ch in children)
    157             //    {
    158             //        SetColorForValue(policy.GetValue(ch.phrase) / maxValue);
    159             //        Console.Write(" {0,4}", policy.GetTries(ch.phrase));
    160             //    }
    161             //    Console.WriteLine();
    162             //    int selectedChildIdx;
    163             //    if (!policy.TrySelect(random, phrase, children.Select(ch => ch.phrase), out selectedChildIdx))
    164             //    {
    165             //        break;
    166             //    }
    167             //    n = n.children[selectedChildIdx];
    168             //}
    169 
    170             //Console.ForegroundColor = ConsoleColor.White;
    171             //Console.WriteLine("-------------------");
    172         }
    173 
    174         private void SetColorForValue(double v)
    175         {
    176             Console.ForegroundColor = ConsoleEx.ColorForValue(v);
     169        public TreeInfos GetTreeInfos()
     170        {
     171            int totalNodes = 0;
     172            int unexpandedNodes = 0;
     173            int expandedNodes = 0;
     174            int leaveNodes = 0;
     175            int deepestLevel = 0;
     176            int totalLevel = 0;
     177            int totalChildren = 0;
     178
     179            List<TreeNode> toDoNodes = new List<TreeNode>();
     180            if (rootNode != null)
     181            {
     182                toDoNodes.Add(rootNode);
     183            }
     184            while (toDoNodes.Any())
     185            {
     186                TreeNode currentNode = toDoNodes[0];
     187                toDoNodes.RemoveAt(0);
     188                totalNodes++;
     189                if (currentNode.level > deepestLevel)
     190                {
     191                    deepestLevel = currentNode.level;
     192                }
     193                totalLevel += currentNode.level;
     194
     195                if (currentNode.children != null)
     196                {
     197                    totalChildren += currentNode.children.Count;
     198                    toDoNodes.AddRange(currentNode.children);
     199                    expandedNodes++;
     200                }
     201                else
     202                {
     203                    if (!HasNonTerminal(currentNode.phrase))
     204                    {
     205                        leaveNodes++;
     206                    }
     207                    else
     208                    {
     209                        unexpandedNodes++;
     210                    }
     211                }
     212            }
     213            return new TreeInfos(totalNodes, unexpandedNodes, expandedNodes, leaveNodes, deepestLevel,
     214                totalLevel / totalNodes, totalChildren / expandedNodes);
     215        }
     216
     217        public byte[] GenerateSvg()
     218        {
     219            IGetStartProcessQuery getStartProcessQuery = new GetStartProcessQuery();
     220            IGetProcessStartInfoQuery getProcessStartInfoQuery = new GetProcessStartInfoQuery();
     221            IRegisterLayoutPluginCommand registerLayoutPluginCommand =
     222                new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
     223
     224            GraphGeneration wrapper = new GraphGeneration(getStartProcessQuery,
     225                getProcessStartInfoQuery,
     226                registerLayoutPluginCommand);
     227            wrapper.GraphvizPath = @"../../../Graphviz2.38/bin";
     228            StringBuilder dotFile = new StringBuilder("digraph {");
     229            dotFile.AppendLine();
     230            dotFile.AppendLine("splines=ortho;");
     231            dotFile.AppendLine("concentrate=true;");
     232            dotFile.AppendLine("ranksep=1.2;");
     233
     234            List<TreeNode> toDoNodes = new List<TreeNode>();
     235            if (rootNode != null)
     236            {
     237                toDoNodes.Add(rootNode);
     238                // declare node
     239                string hexColor = GetHexNodeColor(Color.White, Color.OrangeRed, rootNode.actionInfo.Value);
     240
     241                dotFile.AppendLine(string.Format("{0} [label=\"{1}\\n{2:0.00}/{3}\", style=filled, fillcolor=\"{4}\"]",
     242                    rootNode.GetHashCode(),
     243                    rootNode.phrase, rootNode.actionInfo.Value, rootNode.actionInfo.Tries, hexColor));
     244            }
     245
     246            // to put nodes on the same level in graph
     247            Dictionary<int, List<TreeNode>> levelMap = new Dictionary<int, List<TreeNode>>();
     248
     249            List<TreeNode> sameLevelNodes;
     250
     251            while (toDoNodes.Any())
     252            {
     253                TreeNode currentNode = toDoNodes[0];
     254                toDoNodes.RemoveAt(0);
     255                // put currentNode into levelMap
     256                if (levelMap.TryGetValue(currentNode.level, out sameLevelNodes))
     257                {
     258                    sameLevelNodes.Add(currentNode);
     259                }
     260                else
     261                {
     262                    sameLevelNodes = new List<TreeNode>();
     263                    sameLevelNodes.Add(currentNode);
     264                    levelMap.Add(currentNode.level, sameLevelNodes);
     265                }
     266
     267                // draw line from current node to all its children
     268                if (currentNode.children != null)
     269                {
     270                    foreach (TreeNode childNode in currentNode.children)
     271                    {
     272                        toDoNodes.Add(childNode);
     273                        // declare node
     274
     275                        string hexColor = GetHexNodeColor(Color.White, Color.OrangeRed, childNode.actionInfo.Value);
     276                        dotFile.AppendLine(
     277                            string.Format("{0} [label=\"{1}\\n{2:0.00}/{3}\", style=filled, fillcolor=\"{4}\"]",
     278                                childNode.GetHashCode(),
     279                                childNode.phrase, childNode.actionInfo.Value, childNode.actionInfo.Tries, hexColor));
     280                        // add edge
     281                        dotFile.AppendLine(string.Format("{0} -> {1}", currentNode.GetHashCode(),
     282                            childNode.GetHashCode()));
     283                    }
     284                }
     285            }
     286
     287            // set same level ranks..
     288            foreach (KeyValuePair<int, List<TreeNode>> entry in levelMap)
     289            {
     290                dotFile.Append("{rank = same;");
     291                foreach (TreeNode node in entry.Value)
     292                {
     293                    dotFile.Append(string.Format(" {0};", node.GetHashCode()));
     294                }
     295                dotFile.AppendLine("}");
     296            }
     297
     298            dotFile.Append(" }");
     299            byte[] output = wrapper.GenerateGraph(dotFile.ToString(), Enums.GraphReturnType.Svg);
     300            return output;
     301        }
     302
     303        private String HexConverter(Color c)
     304        {
     305            return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
     306        }
     307
     308        private String GetHexNodeColor(Color weakColor, Color strongColor, double quality)
     309        {
     310            // convert quality to value between 0 and 1
     311            double bestKnownQuality = problem.BestKnownQuality(this.maxLen);
     312            double q = quality / bestKnownQuality;
     313
     314            // calculate difference between colors
     315            byte rDiff = (byte)Math.Abs(weakColor.R - strongColor.R);
     316            byte bDiff = (byte)Math.Abs(weakColor.B - strongColor.B);
     317            byte gDiff = (byte)Math.Abs(weakColor.G - strongColor.G);
     318
     319            byte newR = weakColor.R > strongColor.R
     320                ? Convert.ToByte(weakColor.R - Math.Round(rDiff * q))
     321                : Convert.ToByte(weakColor.R + Math.Round(rDiff * q));
     322
     323            byte newB = weakColor.B > strongColor.B
     324                ? Convert.ToByte(weakColor.B - Math.Round(bDiff * q))
     325                : Convert.ToByte(weakColor.B + Math.Round(bDiff * q));
     326
     327            byte newG = weakColor.G > strongColor.G
     328                ? Convert.ToByte(weakColor.G - Math.Round(gDiff * q))
     329                : Convert.ToByte(weakColor.G + Math.Round(gDiff * q));
     330
     331            return HexConverter(Color.FromArgb(newR, newG, newB));
     332        }
     333
     334        public void PauseContinue()
     335        {
     336            lock (pauseLock)
     337            {
     338                if (isPaused)
     339                {
     340                    isPaused = false;
     341                    Monitor.Pulse(pauseLock);
     342                }
     343                else
     344                {
     345                    isPaused = true;
     346                }
     347            }
    177348        }
    178349    }
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/Simulation/ISimulation.cs

    r12098 r12762  
    1010    public interface ISimulation
    1111    {
    12         double Simulate(TreeNode node);
     12        double Simulate(TreeNode node, out string simulatedPhrase);
    1313    }
    1414}
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/Simulation/RandomSimulation.cs

    r12098 r12762  
    2222        }
    2323
    24         public double Simulate(TreeNode node)
     24        public double Simulate(TreeNode node, out string simulatedPhrase)
    2525        {
    2626            Sequence sequence = new Sequence(node.phrase);
     
    4848                }
    4949            }
     50            simulatedPhrase = sequence.ToString();
    5051            return problem.Evaluate(sequence.ToString());
    5152        }
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs

    r12503 r12762  
    5555    }
    5656
    57       // changed stopAfterFirst to true..
    58     private static void Run(Ant ant, string sentence, ref int p, bool stopAfterFirst = true) {
     57    private static void Run(Ant ant, string sentence, ref int p, bool stopAfterFirst = false) {
    5958      while (!ant.Done()) {
    6059        if (p >= sentence.Length) {
Note: See TracChangeset for help on using the changeset viewer.