- Timestamp:
- 07/14/15 20:42:55 (9 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization/Evaluation
- Files:
-
- 2 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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" /> -
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> -
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 } -
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 }
Note: See TracChangeset
for help on using the changeset viewer.