Changeset 12762
- Timestamp:
- 07/14/15 20:42:55 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization
- Files:
-
- 808 added
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/Evaluation.csproj ¶
r12503 r12762 54 54 <SubType>Designer</SubType> 55 55 </ApplicationDefinition> 56 <Compile Include="ViewModel\EvaluationStat.cs" /> 56 <Compile Include="EvaluationStat.cs" /> 57 <Compile Include="Run.cs" /> 57 58 <Compile Include="ViewModel\EvaluationViewModel.cs" /> 58 59 <Page Include="MainWindow.xaml"> … … 137 138 <Name>HeuristicLab.Problems.GrammaticalOptimization</Name> 138 139 </ProjectReference> 140 <ProjectReference Include="..\WpfTestSvgSample\WpfTestSvgSample.csproj"> 141 <Project>{514a1e9d-0900-46a5-8073-f3c9cb2aaee3}</Project> 142 <Name>WpfTestSvgSample</Name> 143 </ProjectReference> 139 144 </ItemGroup> 140 145 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/MainWindow.xaml ¶
r12503 r12762 5 5 xmlns:charts="http://research.microsoft.com/DynamicDataDisplay/1.0" 6 6 7 Title="MainWindow" Height=" 576" Width="768">7 Title="MainWindow" Height="900" Width="1600" Loaded="Window_Loaded"> 8 8 <Grid Margin="10"> 9 9 <Grid.RowDefinitions> … … 22 22 <Grid.ColumnDefinitions> 23 23 <ColumnDefinition Width="Auto" /> 24 <ColumnDefinition Width="Auto" /> 24 25 <ColumnDefinition Width="*" /> 25 26 </Grid.ColumnDefinitions> … … 30 31 SelectedValue="{Binding SelectedProblem}" 31 32 HorizontalAlignment="Left" Grid.Column="1" Grid.Row="0" Width="200" Margin="2"> 32 33 33 34 </ComboBox> 34 35 <TextBlock VerticalAlignment="Center" Grid.Column="0" Grid.Row="1">Algorithm:</TextBlock> … … 47 48 Width="200" Margin="5,0,0,0"></ComboBox> 48 49 <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> 51 56 </StackPanel> 52 57 </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> 54 81 <Grid Grid.Row="2"> 55 82 <Grid.RowDefinitions> 56 83 <RowDefinition Height="*" /> 57 <RowDefinition Height="Auto" />58 84 </Grid.RowDefinitions> 59 85 <Grid.ColumnDefinitions> 60 <ColumnDefinition Width="Auto" />61 86 <ColumnDefinition Width="*" /> 62 87 <ColumnDefinition Width="Auto" /> 63 88 </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"> 73 203 <Grid.RowDefinitions> 204 <RowDefinition Height="Auto" /> 205 <RowDefinition Height="Auto" /> 74 206 <RowDefinition Height="Auto" /> 75 207 <RowDefinition Height="Auto" /> … … 84 216 <ColumnDefinition Width="*" /> 85 217 </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"/> 100 236 </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>107 237 </Grid> 108 238 </Grid> -
TabularUnified 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; 1 using System.Collections.ObjectModel; 2 using System.Threading; 3 using System.Xml.Serialization; 18 4 using Evaluation.ViewModel; 19 5 using HeuristicLab.Algorithms.Bandits; … … 26 12 using Microsoft.Research.DynamicDataDisplay; 27 13 using Microsoft.Research.DynamicDataDisplay.DataSources; 14 using System; 15 using System.Collections.Generic; 16 using System.ComponentModel; 17 using System.Diagnostics; 18 using System.IO; 19 using System.Windows; 20 using System.Windows.Controls; 21 using System.Windows.Threading; 22 using Microsoft.Win32; 23 using WpfTestSvgSample; 28 24 29 25 namespace Evaluation … … 36 32 private BackgroundWorker worker = new BackgroundWorker(); 37 33 private EvaluationViewModel vm; 38 private List<EvaluationStat> stats = new List<EvaluationStat>(); 39 40 private Stack<EvaluationStat> newStats = new Stack<EvaluationStat>(); 34 41 35 private DispatcherTimer updateCollectionTimer; 42 36 37 private DrawingPage treeDrawingPage; 38 43 39 public MainWindow() 44 40 { 45 41 InitializeComponent(); 42 CenterWindowOnScreen(); 46 43 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"; 47 51 this.worker.WorkerSupportsCancellation = true; 48 52 this.worker.DoWork += worker_DoWork; … … 54 58 ////updateCollectionTimer.Tick += updateCollectionTimer_Tick; 55 59 ////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); 60 70 } 61 71 … … 71 81 void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 72 82 { 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); 79 95 ds.SetXMapping(x => x.Iteration); 80 96 ds.SetYMapping(y => y.CurrentBestQuality); … … 85 101 graph.AddToPlotter(ChartPlotter); 86 102 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 90 115 void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) 91 116 { … … 95 120 void worker_DoWork(object sender, DoWorkEventArgs e) 96 121 { 122 97 123 Type algorithmType = vm.SelectedAlgorithm; 98 124 … … 108 134 policyInstance = new UCTPolicy(); 109 135 } 110 else if (policy == typeof 136 else if (policy == typeof(ThresholdAscentPolicy)) 111 137 { 112 138 policyInstance = new ThresholdAscentPolicy(); … … 117 143 } 118 144 119 vm.MaxLen = 1000;120 vm.MaxEvaluations = 250000;121 122 145 vm.BestKnownQuality = problem.BestKnownQuality(vm.MaxLen); 123 146 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>(); 165 232 } 166 233 167 234 private void ButtonRun_OnClick(object sender, RoutedEventArgs e) 168 235 { 169 ChartPlotter.Children.RemoveAll<LineGraph>(); 236 ClearChart(); 237 vm.Runs.Clear(); 238 vm.CurrentRun = null; 170 239 ButtonRun.IsEnabled = false; 240 TextBoxMaxEvaluations.IsEnabled = false; 241 TextBoxMaxLen.IsEnabled = false; 242 TextBoxRuns.IsEnabled = false; 243 TextBoxThreads.IsEnabled = false; 171 244 worker.RunWorkerAsync(); 172 245 } … … 174 247 private void ButtonPause_OnClick(object sender, RoutedEventArgs e) 175 248 { 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 //} 176 262 } 177 263 … … 183 269 private void ComboBoxAlgorithms_OnSelectionChanged(object sender, SelectionChangedEventArgs e) 184 270 { 185 if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch) 186 || vm.SelectedAlgorithm == typeof(SequentialSearch)) 271 if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch)) 187 272 { 188 273 ComboBoxPolicies.IsEnabled = true; 274 TabItemTree.IsEnabled = true; 275 } 276 else if (vm.SelectedAlgorithm == typeof(SequentialSearch)) 277 { 278 ComboBoxPolicies.IsEnabled = true; 279 TabItemTree.IsEnabled = false; 189 280 } 190 281 else 191 282 { 192 283 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 ////} 194 375 } 195 376 } -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation/ViewModel/EvaluationViewModel.cs ¶
r12503 r12762 1 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 1 using System.Collections.ObjectModel; 2 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 2 3 using HeuristicLab.Algorithms.GeneticProgramming; 3 4 using HeuristicLab.Algorithms.GrammaticalOptimization; … … 108 109 } 109 110 110 private longevaluations;111 112 public longEvaluations111 private int evaluations; 112 113 public int Evaluations 113 114 { 114 115 get { return this.evaluations; } … … 120 121 } 121 122 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 122 139 private int maxLen; 123 140 … … 176 193 } 177 194 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 178 207 private double evaluationsPerSec; 179 208 … … 188 217 } 189 218 190 private longbestSolutionFoundAt;191 192 public longBestSolutionFoundAt219 private int bestSolutionFoundAt; 220 221 public int BestSolutionFoundAt 193 222 { 194 223 get { return this.bestSolutionFoundAt; } … … 197 226 bestSolutionFoundAt = value; 198 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 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"); 199 271 } 200 272 } -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/GrammaticalOptimization.sln ¶
r12503 r12762 72 72 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicDataDisplay", "DynamicDataDisplay\DynamicDataDisplay.csproj", "{ECD37682-DF7E-409F-912D-0965634556B5}" 73 73 EndProject 74 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphVizWrapper", "GraphVizWrapper\GraphVizWrapper.csproj", "{CFEC60DC-14E0-47E4-A60E-8919FB5FEF5D}" 75 EndProject 76 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Converters", "SharpVectorConverters\SharpVectors.Converters.csproj", "{E8056611-E49C-4BC3-A682-A629D5CEC11C}" 77 EndProject 78 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Core", "SharpVectorCore\SharpVectors.Core.csproj", "{D6BB65FC-240E-4241-B2ED-A7FB3F13E978}" 79 EndProject 80 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Css", "SharpVectorCss\SharpVectors.Css.csproj", "{351B0A6E-2F6B-497A-844B-DCB5A502FB0D}" 81 EndProject 82 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Dom", "SharpVectorDom\SharpVectors.Dom.csproj", "{FE34CBC0-D23C-4A95-BA64-83A031814010}" 83 EndProject 84 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Model", "SharpVectorModel\SharpVectors.Model.csproj", "{5D336F48-3FB9-4382-B4B9-06974C764007}" 85 EndProject 86 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Rendering.Gdi", "SharpVectorRenderingGdi\SharpVectors.Rendering.Gdi.csproj", "{0AD99D97-24ED-484D-9430-9905811F8A4F}" 87 EndProject 88 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Rendering.Wpf", "SharpVectorRenderingWpf\SharpVectors.Rendering.Wpf.csproj", "{A2576CE0-E492-490F-97E9-C0E7ABAFAF27}" 89 EndProject 90 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpVectors.Runtime", "SharpVectorRuntime\SharpVectors.Runtime.csproj", "{2CD52982-A1C2-4A14-9D69-D64719357216}" 91 EndProject 92 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfTestSvgSample", "WpfTestSvgSample\WpfTestSvgSample.csproj", "{514A1E9D-0900-46A5-8073-F3C9CB2AAEE3}" 93 EndProject 74 94 Global 75 95 GlobalSection(SolutionConfigurationPlatforms) = preSolution 76 96 Debug|Any CPU = Debug|Any CPU 97 Documentation|Any CPU = Documentation|Any CPU 77 98 Release|Any CPU = Release|Any CPU 78 99 ReleaseXBAP|Any CPU = ReleaseXBAP|Any CPU … … 81 102 {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 82 103 {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 83 106 {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Release|Any CPU.ActiveCfg = Release|Any CPU 84 107 {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Release|Any CPU.Build.0 = Release|Any CPU … … 87 110 {EEA07488-1A51-412A-A52C-53B754A628B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 88 111 {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 89 114 {EEA07488-1A51-412A-A52C-53B754A628B3}.Release|Any CPU.ActiveCfg = Release|Any CPU 90 115 {EEA07488-1A51-412A-A52C-53B754A628B3}.Release|Any CPU.Build.0 = Release|Any CPU … … 93 118 {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 94 119 {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 95 122 {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Release|Any CPU.ActiveCfg = Release|Any CPU 96 123 {524CBD70-6F99-46AF-AD00-A0BC9FD1175B}.Release|Any CPU.Build.0 = Release|Any CPU … … 99 126 {24408F7D-EE0F-4886-A08B-EC324D662E47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 100 127 {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 101 130 {24408F7D-EE0F-4886-A08B-EC324D662E47}.Release|Any CPU.ActiveCfg = Release|Any CPU 102 131 {24408F7D-EE0F-4886-A08B-EC324D662E47}.Release|Any CPU.Build.0 = Release|Any CPU … … 105 134 {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 106 135 {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 107 138 {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Release|Any CPU.ActiveCfg = Release|Any CPU 108 139 {3A2FBBCB-F9DF-4970-87F3-F13337D941AD}.Release|Any CPU.Build.0 = Release|Any CPU … … 111 142 {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 112 143 {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 113 146 {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Release|Any CPU.ActiveCfg = Release|Any CPU 114 147 {17A7A380-86CE-482D-8D22-CBD70CC97F0D}.Release|Any CPU.Build.0 = Release|Any CPU … … 117 150 {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 118 151 {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 119 154 {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Release|Any CPU.ActiveCfg = Release|Any CPU 120 155 {14BEC23F-63FD-4954-B8AE-E2F4962E9B57}.Release|Any CPU.Build.0 = Release|Any CPU … … 123 158 {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 124 159 {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 125 162 {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Release|Any CPU.ActiveCfg = Release|Any CPU 126 163 {31171165-E16F-4A1A-A8AB-25C6AB3A71B9}.Release|Any CPU.Build.0 = Release|Any CPU … … 129 166 {E8138227-0C64-4E85-B676-21D3B97F254F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 130 167 {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 131 170 {E8138227-0C64-4E85-B676-21D3B97F254F}.Release|Any CPU.ActiveCfg = Release|Any CPU 132 171 {E8138227-0C64-4E85-B676-21D3B97F254F}.Release|Any CPU.Build.0 = Release|Any CPU … … 135 174 {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 136 175 {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 137 178 {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Release|Any CPU.ActiveCfg = Release|Any CPU 138 179 {8B4C199E-C08B-479E-9B82-6AE5B113459E}.Release|Any CPU.Build.0 = Release|Any CPU … … 141 182 {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 142 183 {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 143 186 {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Release|Any CPU.ActiveCfg = Release|Any CPU 144 187 {2C115235-8FA9-4F7F-B3A0-A0144F8A35CA}.Release|Any CPU.Build.0 = Release|Any CPU … … 147 190 {D043325A-097F-4512-A8FC-CF706577FA46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 148 191 {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 149 194 {D043325A-097F-4512-A8FC-CF706577FA46}.Release|Any CPU.ActiveCfg = Release|Any CPU 150 195 {D043325A-097F-4512-A8FC-CF706577FA46}.Release|Any CPU.Build.0 = Release|Any CPU … … 153 198 {ECD37682-DF7E-409F-912D-0965634556B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 154 199 {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 155 202 {ECD37682-DF7E-409F-912D-0965634556B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 156 203 {ECD37682-DF7E-409F-912D-0965634556B5}.Release|Any CPU.Build.0 = Release|Any CPU 157 204 {ECD37682-DF7E-409F-912D-0965634556B5}.ReleaseXBAP|Any CPU.ActiveCfg = ReleaseXBAP|Any CPU 158 205 {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 159 286 EndGlobalSection 160 287 GlobalSection(SolutionProperties) = preSolution -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/Base/TreeNode.cs ¶
r12503 r12762 16 16 public List<TreeNode> children; 17 17 public IBanditPolicyActionInfo actionInfo; 18 public int level; 18 19 19 public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo )20 public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo, int level) 20 21 { 21 22 this.parent = parent; 22 23 this.phrase = phrase; 23 24 this.actionInfo = actionInfo; 25 this.level = level; 24 26 } 25 27 public bool IsLeaf() -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/HeuristicLab.Algorithms.MonteCarloTreeSearch.csproj ¶
r12098 r12762 33 33 <Reference Include="System" /> 34 34 <Reference Include="System.Core" /> 35 <Reference Include="System.Drawing" /> 35 36 <Reference Include="System.Xml.Linq" /> 36 37 <Reference Include="System.Data.DataSetExtensions" /> … … 40 41 </ItemGroup> 41 42 <ItemGroup> 43 <Compile Include="Base\TreeInfos.cs" /> 42 44 <Compile Include="Simulation\ISimulation.cs" /> 43 45 <Compile Include="MonteCarloTreeSearch.cs" /> … … 47 49 </ItemGroup> 48 50 <ItemGroup> 51 <ProjectReference Include="..\GraphVizWrapper\GraphVizWrapper.csproj"> 52 <Project>{cfec60dc-14e0-47e4-a60e-8919fb5fef5d}</Project> 53 <Name>GraphVizWrapper</Name> 54 </ProjectReference> 49 55 <ProjectReference Include="..\HeuristicLab.Algorithms.Bandits\HeuristicLab.Algorithms.Bandits.csproj"> 50 56 <Project>{24408f7d-ee0f-4886-a08b-ec324d662e47}</Project> -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/MonteCarloTreeSearch.cs ¶
r12503 r12762 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Drawing; 3 4 using System.Linq; 5 using System.Net.Mail; 6 using System.Text; 7 using System.Threading; 8 using GraphVizWrapper; 9 using GraphVizWrapper.Commands; 10 using GraphVizWrapper.Queries; 4 11 using HeuristicLab.Algorithms.Bandits; 5 12 using HeuristicLab.Algorithms.GrammaticalOptimization; … … 20 27 private readonly ISimulation simulation; 21 28 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) 24 34 { 25 35 this.problem = problem; … … 31 41 } 32 42 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; } 37 48 } 38 49 … … 42 53 for (int i = 0; !StopRequested && i < maxIterations; i++) 43 54 { 55 lock (pauseLock) 56 { 57 if (isPaused) 58 { 59 Monitor.Wait(pauseLock); 60 } 61 } 44 62 TreeNode currentNode = rootNode; 45 63 … … 53 71 string phrase = currentNode.phrase; 54 72 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 } 57 82 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 } 61 95 } 62 96 if (currentNode.phrase.Length <= maxLen) 63 97 { 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); 66 101 67 102 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; 70 119 } 71 120 … … 91 140 if (newSequence.Length <= maxLen) 92 141 { 93 TreeNode childNode = new TreeNode(treeNode, newSequence.ToString(), behaviourPolicy.CreateActionInfo()); 142 TreeNode childNode = new TreeNode(treeNode, newSequence.ToString(), 143 behaviourPolicy.CreateActionInfo(), treeNode.level + 1); 94 144 treeNode.children.Add(childNode); 95 145 } … … 104 154 StopRequested = false; 105 155 bestQuality = 0.0; 106 rootNode = new TreeNode(null, grammar.SentenceSymbol.ToString(), behaviourPolicy.CreateActionInfo() );156 rootNode = new TreeNode(null, grammar.SentenceSymbol.ToString(), behaviourPolicy.CreateActionInfo(), 0); 107 157 } 108 158 … … 117 167 } 118 168 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 } 177 348 } 178 349 } -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/Simulation/ISimulation.cs ¶
r12098 r12762 10 10 public interface ISimulation 11 11 { 12 double Simulate(TreeNode node );12 double Simulate(TreeNode node, out string simulatedPhrase); 13 13 } 14 14 } -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/Simulation/RandomSimulation.cs ¶
r12098 r12762 22 22 } 23 23 24 public double Simulate(TreeNode node )24 public double Simulate(TreeNode node, out string simulatedPhrase) 25 25 { 26 26 Sequence sequence = new Sequence(node.phrase); … … 48 48 } 49 49 } 50 simulatedPhrase = sequence.ToString(); 50 51 return problem.Evaluate(sequence.ToString()); 51 52 } -
TabularUnified branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs ¶
r12503 r12762 55 55 } 56 56 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) { 59 58 while (!ant.Done()) { 60 59 if (p >= sentence.Length) {
Note: See TracChangeset
for help on using the changeset viewer.