[12762] | 1 | using System.Collections.ObjectModel;
|
---|
[13518] | 2 | using System.Globalization;
|
---|
[12815] | 3 | using System.Security.AccessControl;
|
---|
[12824] | 4 | using System.Text;
|
---|
[12762] | 5 | using System.Threading;
|
---|
[12832] | 6 | using System.Threading.Tasks;
|
---|
[12824] | 7 | using System.Windows.Documents;
|
---|
[12840] | 8 | using System.Windows.Media;
|
---|
[12762] | 9 | using System.Xml.Serialization;
|
---|
[12503] | 10 | using Evaluation.ViewModel;
|
---|
| 11 | using HeuristicLab.Algorithms.Bandits;
|
---|
| 12 | using HeuristicLab.Algorithms.Bandits.BanditPolicies;
|
---|
| 13 | using HeuristicLab.Algorithms.GeneticProgramming;
|
---|
| 14 | using HeuristicLab.Algorithms.GrammaticalOptimization;
|
---|
| 15 | using HeuristicLab.Algorithms.MonteCarloTreeSearch;
|
---|
| 16 | using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation;
|
---|
| 17 | using HeuristicLab.Problems.GrammaticalOptimization;
|
---|
| 18 | using Microsoft.Research.DynamicDataDisplay;
|
---|
| 19 | using Microsoft.Research.DynamicDataDisplay.DataSources;
|
---|
[12762] | 20 | using System;
|
---|
| 21 | using System.Collections.Generic;
|
---|
| 22 | using System.ComponentModel;
|
---|
| 23 | using System.Diagnostics;
|
---|
| 24 | using System.IO;
|
---|
| 25 | using System.Windows;
|
---|
| 26 | using System.Windows.Controls;
|
---|
| 27 | using System.Windows.Threading;
|
---|
| 28 | using Microsoft.Win32;
|
---|
| 29 | using WpfTestSvgSample;
|
---|
[12503] | 30 |
|
---|
| 31 | namespace Evaluation
|
---|
| 32 | {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// Interaction logic for MainWindow.xaml
|
---|
| 35 | /// </summary>
|
---|
| 36 | public partial class MainWindow : Window
|
---|
| 37 | {
|
---|
| 38 | private EvaluationViewModel vm;
|
---|
| 39 |
|
---|
[12762] | 40 | private DrawingPage treeDrawingPage;
|
---|
| 41 |
|
---|
[12503] | 42 | public MainWindow()
|
---|
| 43 | {
|
---|
| 44 | InitializeComponent();
|
---|
[12762] | 45 | CenterWindowOnScreen();
|
---|
[12503] | 46 | this.DataContext = vm = new EvaluationViewModel();
|
---|
[12840] | 47 | vm.MaxLen = 17;
|
---|
| 48 | vm.MaxIterations = 300000;
|
---|
[12829] | 49 | vm.NrRuns = 20;
|
---|
[12840] | 50 | vm.MaxThreads = 10;
|
---|
[12762] | 51 | }
|
---|
[12503] | 52 |
|
---|
[12762] | 53 | private void CenterWindowOnScreen()
|
---|
| 54 | {
|
---|
| 55 | double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
|
---|
| 56 | double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
|
---|
| 57 | double windowWidth = this.Width;
|
---|
| 58 | double windowHeight = this.Height;
|
---|
| 59 | this.Left = (screenWidth / 2) - (windowWidth / 2);
|
---|
| 60 | this.Top = (screenHeight / 2) - (windowHeight / 2);
|
---|
[12503] | 61 | }
|
---|
| 62 |
|
---|
[12815] | 63 | private void DrawQualityChart(Run run)
|
---|
[12503] | 64 | {
|
---|
[12781] | 65 | List<FoundSolution> solutions = new List<FoundSolution>(run.FoundSolutions);
|
---|
[12762] | 66 |
|
---|
[12781] | 67 | if (run.BestSolutionFoundAt < run.Evaluations)
|
---|
| 68 | {
|
---|
| 69 | solutions.Add(new FoundSolution(run.EndTime, run.Evaluations, run.BestQuality, run.BestSolution));
|
---|
| 70 | }
|
---|
[12762] | 71 |
|
---|
[13533] | 72 | // insert point between two solutions, with the result that there is no direct line from solutionpoint to solutionpoint
|
---|
| 73 |
|
---|
| 74 | for (int i = 1; i < solutions.Count; i++)
|
---|
| 75 | {
|
---|
| 76 | FoundSolution previousSolution = solutions[i - 1];
|
---|
| 77 | FoundSolution currentSolution = solutions[i];
|
---|
| 78 | // insert point
|
---|
| 79 | solutions.Insert(i, new FoundSolution(currentSolution.Time, currentSolution.Iteration, previousSolution.Quality, "placeholder"));
|
---|
| 80 | i++;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[12781] | 83 | var ds = new EnumerableDataSource<FoundSolution>(solutions);
|
---|
| 84 |
|
---|
| 85 |
|
---|
[12503] | 86 | ds.SetXMapping(x => x.Iteration);
|
---|
[12840] | 87 | ds.SetYMapping(y => y.Quality / run.BestKnownQuality);
|
---|
[12503] | 88 |
|
---|
| 89 | LineGraph graph = new LineGraph(ds);
|
---|
| 90 |
|
---|
| 91 | graph.StrokeThickness = 2;
|
---|
[12815] | 92 | graph.AddToPlotter(QualityChartPlotter);
|
---|
[12503] | 93 | }
|
---|
[12762] | 94 |
|
---|
[12815] | 95 | private void DrawSelectionChart(Run run)
|
---|
| 96 | {
|
---|
[12840] | 97 | // quality line
|
---|
| 98 | List<FoundSolution> solutions = new List<FoundSolution>(run.FoundSolutions);
|
---|
[12815] | 99 |
|
---|
[12840] | 100 | if (run.BestSolutionFoundAt < run.Evaluations)
|
---|
| 101 | {
|
---|
| 102 | solutions.Add(new FoundSolution(run.EndTime, run.Evaluations, run.BestQuality, run.BestSolution));
|
---|
| 103 | }
|
---|
[13533] | 104 | // insert point between two solutions, with the result that there is no direct line from solutionpoint to solutionpoint
|
---|
[12815] | 105 |
|
---|
[13533] | 106 | for (int i = 1; i < solutions.Count; i++)
|
---|
| 107 | {
|
---|
| 108 | FoundSolution previousSolution = solutions[i - 1];
|
---|
| 109 | FoundSolution currentSolution = solutions[i];
|
---|
| 110 | // insert point
|
---|
| 111 | solutions.Insert(i, new FoundSolution(currentSolution.Time, currentSolution.Iteration, previousSolution.Quality, "placeholder"));
|
---|
| 112 | i++;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[12840] | 115 | var ds = new EnumerableDataSource<FoundSolution>(solutions);
|
---|
[12815] | 116 |
|
---|
[12840] | 117 |
|
---|
| 118 | ds.SetXMapping(x => x.Iteration);
|
---|
| 119 | ds.SetYMapping(y => y.Quality / run.BestKnownQuality);
|
---|
| 120 |
|
---|
[12815] | 121 | LineGraph graph = new LineGraph(ds);
|
---|
[12840] | 122 | graph.StrokeThickness = 2;
|
---|
| 123 | graph.AddToPlotter(SelectionChartPlotter);
|
---|
[12815] | 124 |
|
---|
[12840] | 125 | // selection indicator line
|
---|
| 126 | List<SelectionIndicator> selectionIndicators = new List<SelectionIndicator>(run.SelectionIndicators);
|
---|
| 127 |
|
---|
| 128 | var dssi = new EnumerableDataSource<SelectionIndicator>(selectionIndicators);
|
---|
| 129 |
|
---|
| 130 | dssi.SetXMapping(x => x.Evaluation);
|
---|
| 131 | dssi.SetYMapping(y => y.Indicator);
|
---|
| 132 |
|
---|
| 133 | graph = new LineGraph(dssi);
|
---|
[12815] | 134 | graph.StrokeThickness = 2;
|
---|
[12840] | 135 | graph.Stroke = Brushes.Red;
|
---|
[12815] | 136 | graph.AddToPlotter(SelectionChartPlotter);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[12762] | 139 | private void DrawTreeChart(Run run)
|
---|
| 140 | {
|
---|
| 141 | if (!string.IsNullOrEmpty(run.SvgFile))
|
---|
| 142 | {
|
---|
| 143 | treeDrawingPage.LoadDocument(run.SvgFile);
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[12781] | 147 | private void DoRun(Object threadContext)
|
---|
| 148 | {
|
---|
| 149 | Run run = (Run)threadContext;
|
---|
| 150 | run.RunState = RunState.Running;
|
---|
| 151 | run.StartTime = DateTime.Now;
|
---|
[12762] | 152 |
|
---|
[12815] | 153 | run.Solver.Run(run.MaxIterations);
|
---|
[12781] | 154 |
|
---|
| 155 | run.EndTime = DateTime.Now;
|
---|
| 156 | run.RunState = RunState.Analyzing;
|
---|
| 157 |
|
---|
| 158 | if (run.FoundSolutions.Count > 0)
|
---|
| 159 | {
|
---|
| 160 | if (run.Solver is MonteCarloTreeSearch)
|
---|
| 161 | {
|
---|
| 162 | MonteCarloTreeSearch mctsSolver = (MonteCarloTreeSearch)run.Solver;
|
---|
| 163 |
|
---|
| 164 | run.TreeInfos = mctsSolver.GetTreeInfos();
|
---|
| 165 |
|
---|
[13533] | 166 | // svg-tree ->
|
---|
| 167 | //byte[] output = mctsSolver.GenerateSvg();
|
---|
| 168 | //if (output != null && output.Length > 0)
|
---|
| 169 | //{
|
---|
| 170 | // run.SvgFile = string.Format("MCTS_SVG_#{0}_{1}.svg", run.RunNumber, DateTime.Now.Ticks);
|
---|
| 171 | // File.WriteAllBytes(run.SvgFile, output);
|
---|
| 172 | //}
|
---|
[12832] | 173 | mctsSolver.FreeAll();
|
---|
[12781] | 174 | }
|
---|
| 175 | }
|
---|
| 176 | run.RunState = RunState.Finished;
|
---|
| 177 | lock (vm.CompletedRuns)
|
---|
| 178 | {
|
---|
| 179 | int completed = 0;
|
---|
| 180 | foreach (Run r in vm.Runs)
|
---|
| 181 | {
|
---|
| 182 | if (r.RunState == RunState.Finished)
|
---|
| 183 | {
|
---|
| 184 | completed++;
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
| 187 | vm.CompletedRuns = string.Format("{0}/{1}", completed, vm.Runs.Count);
|
---|
| 188 | if (completed == vm.NrRuns)
|
---|
| 189 | {
|
---|
| 190 | Dispatcher.Invoke(AllRunsFinished);
|
---|
| 191 | }
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | private void AllRunsFinished()
|
---|
[12503] | 196 | {
|
---|
[12781] | 197 | ButtonRun.IsEnabled = true;
|
---|
[12815] | 198 | TextBoxMaxIterations.IsEnabled = true;
|
---|
[12781] | 199 | TextBoxMaxLen.IsEnabled = true;
|
---|
| 200 | TextBoxRuns.IsEnabled = true;
|
---|
[12833] | 201 | TextBoxMaxThreads.IsEnabled = true;
|
---|
[12503] | 202 | }
|
---|
| 203 |
|
---|
[12781] | 204 | private void StartRuns()
|
---|
[12503] | 205 | {
|
---|
[12781] | 206 | vm.CompletedRuns = string.Format("0/{0}", vm.NrRuns);
|
---|
[12762] | 207 |
|
---|
[12503] | 208 | Type algorithmType = vm.SelectedAlgorithm;
|
---|
| 209 |
|
---|
| 210 | ISymbolicExpressionTreeProblem problem = vm.SelectedProblem;
|
---|
| 211 |
|
---|
| 212 | Type policy = vm.SelectedPolicy;
|
---|
| 213 | IBanditPolicy policyInstance = null;
|
---|
| 214 |
|
---|
| 215 | if (policy == typeof(UCTPolicy))
|
---|
| 216 | {
|
---|
[13518] | 217 | policyInstance = new UCTPolicy(vm.PolicyParameter);
|
---|
[12503] | 218 | }
|
---|
[12762] | 219 | else if (policy == typeof(ThresholdAscentPolicy))
|
---|
[12503] | 220 | {
|
---|
| 221 | policyInstance = new ThresholdAscentPolicy();
|
---|
| 222 | }
|
---|
[12815] | 223 | else if (policy == typeof(BoltzmannExplorationPolicy))
|
---|
| 224 | {
|
---|
| 225 | policyInstance = new BoltzmannExplorationPolicy(2);
|
---|
| 226 | }
|
---|
[12840] | 227 | else if (policy == typeof(EpsGreedyPolicy))
|
---|
[12833] | 228 | {
|
---|
[13518] | 229 | policyInstance = new EpsGreedyPolicy(vm.PolicyParameter);
|
---|
[12833] | 230 | }
|
---|
[12503] | 231 | else
|
---|
| 232 | {
|
---|
| 233 | policyInstance = (IBanditPolicy)Activator.CreateInstance(policy);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
[12762] | 236 | for (int i = 0; i < vm.NrRuns; i++)
|
---|
| 237 | {
|
---|
| 238 | ISolver solver = null;
|
---|
[12830] | 239 |
|
---|
[12828] | 240 | Random random = new Random(Guid.NewGuid().GetHashCode());
|
---|
[12503] | 241 |
|
---|
[12781] | 242 | if (algorithmType == typeof(MonteCarloTreeSearch_PruneLeaves))
|
---|
[12762] | 243 | {
|
---|
[12781] | 244 | solver = new MonteCarloTreeSearch_PruneLeaves(problem, vm.MaxLen, random, policyInstance, new RandomSimulation(problem, random, vm.MaxLen));
|
---|
| 245 | }
|
---|
| 246 | else if (algorithmType == typeof(MonteCarloTreeSearch))
|
---|
| 247 | {
|
---|
[12762] | 248 | solver = new MonteCarloTreeSearch(problem, vm.MaxLen, random, policyInstance, new RandomSimulation(problem, random, vm.MaxLen));
|
---|
| 249 | }
|
---|
| 250 | else if (algorithmType == typeof(SequentialSearch))
|
---|
| 251 | {
|
---|
| 252 | solver = new SequentialSearch(problem, vm.MaxLen, random, 0,
|
---|
| 253 | new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, policyInstance));
|
---|
| 254 | }
|
---|
| 255 | else if (algorithmType == typeof(RandomSearch))
|
---|
| 256 | {
|
---|
| 257 | solver = new RandomSearch(problem, random, vm.MaxLen);
|
---|
| 258 | }
|
---|
| 259 | else if (algorithmType == typeof(StandardGP))
|
---|
| 260 | {
|
---|
| 261 | solver = new StandardGP(problem, random);
|
---|
| 262 | }
|
---|
| 263 | else if (algorithmType == typeof(OffspringSelectionGP))
|
---|
| 264 | {
|
---|
| 265 | solver = new OffspringSelectionGP(problem, random);
|
---|
| 266 | }
|
---|
[12503] | 267 |
|
---|
[12815] | 268 | Run run = new Run(problem, policyInstance, solver, i + 1, vm.MaxIterations, vm.MaxLen);
|
---|
[12762] | 269 |
|
---|
[12781] | 270 | vm.Runs.Add(run);
|
---|
[12762] | 271 | }
|
---|
[12832] | 272 | Task.Run(() =>
|
---|
[12840] | 273 | Parallel.For(0, vm.NrRuns, new ParallelOptions { MaxDegreeOfParallelism = vm.MaxThreads },
|
---|
[12832] | 274 | i => DoRun(vm.Runs[i])));
|
---|
[12762] | 275 | }
|
---|
[12503] | 276 |
|
---|
[12815] | 277 | private void ClearQualityChart()
|
---|
[12762] | 278 | {
|
---|
[12815] | 279 | QualityChartPlotter.Children.RemoveAll<LineGraph>();
|
---|
[12503] | 280 | }
|
---|
| 281 |
|
---|
[12781] | 282 | private void ClearComparisonChart()
|
---|
| 283 | {
|
---|
| 284 | ComparisonChartPlotter.Children.RemoveAll<LineGraph>();
|
---|
| 285 | }
|
---|
| 286 |
|
---|
[12815] | 287 | private void ClearSelectionChart()
|
---|
| 288 | {
|
---|
| 289 | SelectionChartPlotter.Children.RemoveAll<LineGraph>();
|
---|
| 290 | }
|
---|
| 291 |
|
---|
[12503] | 292 | private void ButtonRun_OnClick(object sender, RoutedEventArgs e)
|
---|
| 293 | {
|
---|
[12815] | 294 | ClearQualityChart();
|
---|
[12781] | 295 | ClearComparisonChart();
|
---|
[12815] | 296 | ClearSelectionChart();
|
---|
[12781] | 297 |
|
---|
[12762] | 298 | vm.Runs.Clear();
|
---|
[12781] | 299 | vm.SelectedRun = null;
|
---|
[12503] | 300 | ButtonRun.IsEnabled = false;
|
---|
[12815] | 301 | TextBoxMaxIterations.IsEnabled = false;
|
---|
[12762] | 302 | TextBoxMaxLen.IsEnabled = false;
|
---|
| 303 | TextBoxRuns.IsEnabled = false;
|
---|
[12781] | 304 | StartRuns();
|
---|
[12503] | 305 | }
|
---|
| 306 |
|
---|
| 307 | private void ButtonPause_OnClick(object sender, RoutedEventArgs e)
|
---|
| 308 | {
|
---|
[12762] | 309 | //if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch))
|
---|
| 310 | //{
|
---|
| 311 | // MonteCarloTreeSearch mcts = (MonteCarloTreeSearch)solver;
|
---|
| 312 | // mcts.PauseContinue();
|
---|
| 313 | // if (mcts.IsPaused)
|
---|
| 314 | // {
|
---|
| 315 | // ButtonPause.Content = "Continue";
|
---|
| 316 | // }
|
---|
| 317 | // else
|
---|
| 318 | // {
|
---|
| 319 | // ButtonPause.Content = "Pause";
|
---|
| 320 | // }
|
---|
| 321 | //}
|
---|
[12503] | 322 | }
|
---|
| 323 |
|
---|
| 324 | private void ButtonStop_OnClick(object sender, RoutedEventArgs e)
|
---|
| 325 | {
|
---|
[12781] | 326 | //worker.CancelAsync();
|
---|
[12503] | 327 | }
|
---|
| 328 |
|
---|
| 329 | private void ComboBoxAlgorithms_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
---|
| 330 | {
|
---|
[12781] | 331 | if (vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch) || vm.SelectedAlgorithm == typeof(MonteCarloTreeSearch_PruneLeaves))
|
---|
[12503] | 332 | {
|
---|
| 333 | ComboBoxPolicies.IsEnabled = true;
|
---|
[12762] | 334 | TabItemTree.IsEnabled = true;
|
---|
[12503] | 335 | }
|
---|
[12762] | 336 | else if (vm.SelectedAlgorithm == typeof(SequentialSearch))
|
---|
| 337 | {
|
---|
| 338 | ComboBoxPolicies.IsEnabled = true;
|
---|
| 339 | TabItemTree.IsEnabled = false;
|
---|
| 340 | }
|
---|
[12503] | 341 | else
|
---|
| 342 | {
|
---|
| 343 | ComboBoxPolicies.IsEnabled = false;
|
---|
[12762] | 344 | TabItemTree.IsEnabled = false;
|
---|
[12503] | 345 | }
|
---|
| 346 | }
|
---|
[12762] | 347 |
|
---|
| 348 | private void Window_Loaded(object sender, RoutedEventArgs e)
|
---|
| 349 | {
|
---|
| 350 | treeDrawingPage = treeDrawing.Content as DrawingPage;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | private void ListBoxRuns_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
---|
| 354 | {
|
---|
[12781] | 355 | if (vm.SelectedRun != null)
|
---|
| 356 | {
|
---|
| 357 | vm.SelectedRun.Solver.FoundNewBestSolution -= SelectedRun_FoundNewBestSolution;
|
---|
| 358 | }
|
---|
[12762] | 359 | if (ListBoxRuns.SelectedItem != null)
|
---|
| 360 | {
|
---|
[12781] | 361 | vm.SelectedRun = (Run)ListBoxRuns.SelectedItem;
|
---|
| 362 |
|
---|
| 363 | vm.SelectedRun.Solver.FoundNewBestSolution += SelectedRun_FoundNewBestSolution;
|
---|
| 364 |
|
---|
[12815] | 365 | ClearQualityChart();
|
---|
| 366 | DrawQualityChart(vm.SelectedRun);
|
---|
| 367 |
|
---|
| 368 | if (vm.SelectedRun.RunState == RunState.Finished)
|
---|
| 369 | {
|
---|
| 370 | ClearSelectionChart();
|
---|
| 371 | DrawSelectionChart(vm.SelectedRun);
|
---|
| 372 | }
|
---|
[12781] | 373 | //DrawTreeChart(vm.SelectedRun);
|
---|
[12762] | 374 | }
|
---|
[12781] | 375 | else
|
---|
| 376 | {
|
---|
| 377 | vm.SelectedRun = null;
|
---|
| 378 | }
|
---|
[12762] | 379 | }
|
---|
| 380 |
|
---|
[12781] | 381 | void SelectedRun_FoundNewBestSolution(string arg1, double arg2)
|
---|
| 382 | {
|
---|
| 383 | Dispatcher.BeginInvoke(new Action(() =>
|
---|
| 384 | {
|
---|
[12815] | 385 | ClearQualityChart();
|
---|
| 386 | DrawQualityChart(vm.SelectedRun);
|
---|
[12781] | 387 | }));
|
---|
| 388 | }
|
---|
| 389 |
|
---|
[12762] | 390 | public void SaveToFile()
|
---|
| 391 | {
|
---|
| 392 | SaveFileDialog dlg = new SaveFileDialog();
|
---|
| 393 | dlg.FileName = "runs"; // Default file name
|
---|
| 394 | dlg.DefaultExt = ".xml"; // Default file extension
|
---|
| 395 |
|
---|
| 396 | // Show save file dialog box
|
---|
| 397 | Nullable<bool> result = dlg.ShowDialog();
|
---|
| 398 |
|
---|
| 399 | // Process save file dialog box results
|
---|
| 400 | if (result == true)
|
---|
| 401 | {
|
---|
| 402 | // Save document
|
---|
| 403 | string filename = dlg.FileName;
|
---|
| 404 |
|
---|
| 405 | XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<Run>));
|
---|
| 406 | using (TextWriter writer = new StreamWriter(filename))
|
---|
| 407 | {
|
---|
| 408 | serializer.Serialize(writer, vm.Runs);
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | public void LoadFromFile()
|
---|
| 415 | {
|
---|
| 416 | OpenFileDialog dlg = new OpenFileDialog();
|
---|
| 417 |
|
---|
| 418 | // Show save file dialog box
|
---|
| 419 | Nullable<bool> result = dlg.ShowDialog();
|
---|
| 420 |
|
---|
| 421 | // Process save file dialog box results
|
---|
| 422 | if (result == true)
|
---|
| 423 | {
|
---|
| 424 | // Load document
|
---|
| 425 | string filename = dlg.FileName;
|
---|
| 426 |
|
---|
| 427 | XmlSerializer deserializer = new XmlSerializer(typeof(ObservableCollection<Run>));
|
---|
| 428 | using (TextReader reader = new StreamReader(filename))
|
---|
| 429 | {
|
---|
| 430 | object obj = deserializer.Deserialize(reader);
|
---|
| 431 | vm.Runs = (ObservableCollection<Run>)obj;
|
---|
| 432 |
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | private void LoadButton_OnClick(object sender, RoutedEventArgs e)
|
---|
| 438 | {
|
---|
[12781] | 439 | LoadFromFile();
|
---|
[12762] | 440 | }
|
---|
| 441 |
|
---|
| 442 | private void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
---|
| 443 | {
|
---|
| 444 | SaveToFile();
|
---|
| 445 | }
|
---|
[12824] | 446 |
|
---|
| 447 | private void MenuItemCopyToClipboard_OnClick(object sender, RoutedEventArgs e)
|
---|
| 448 | {
|
---|
| 449 | StringBuilder tableExport = new StringBuilder();
|
---|
[12827] | 450 | tableExport.Append(
|
---|
[12824] | 451 | "Run\tMaxIterations\tEvaluations\tBestKnownQuality\tQuality\tQuality %\tFoundAt\tTotalTime\tSolutionTime\tEvaluationsPerSecond\tSolution");
|
---|
[12830] | 452 | if (ListViewRuns.Items.Count > 0 && ((Run)ListViewRuns.Items[0]).TreeInfos != null)
|
---|
[12827] | 453 | {
|
---|
| 454 | tableExport.Append("\tTotalNodes\tUnexpandedNodes\tExpandedNodes\tLeaveNodes\tDeepestLevel");
|
---|
| 455 | }
|
---|
| 456 | tableExport.AppendLine();
|
---|
[12824] | 457 | for (int i = 0; i < ListViewRuns.Items.Count; i++)
|
---|
| 458 | {
|
---|
| 459 | Run run = (Run)ListViewRuns.Items[i];
|
---|
[12827] | 460 | tableExport.Append(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}", run.RunNumber,
|
---|
[12824] | 461 | run.MaxIterations, run.Evaluations, run.BestKnownQuality, run.BestQuality,
|
---|
| 462 | run.BestQuality / run.BestKnownQuality, run.BestSolutionFoundAt, run.TotalTime, run.BestSolutionTime,
|
---|
| 463 | run.EvaluationsPerSecond, run.BestSolution));
|
---|
[12827] | 464 |
|
---|
| 465 | if (run.TreeInfos != null)
|
---|
| 466 | {
|
---|
| 467 | tableExport.Append(string.Format("\t{0}\t{1}\t{2}\t{3}\t{4}", run.TreeInfos.TotalNodes,
|
---|
| 468 | run.TreeInfos.UnexpandedNodes, run.TreeInfos.ExpandedNodes, run.TreeInfos.LeaveNodes,
|
---|
| 469 | run.TreeInfos.DeepestLevel));
|
---|
| 470 | }
|
---|
| 471 |
|
---|
| 472 | tableExport.AppendLine();
|
---|
[12824] | 473 | }
|
---|
| 474 | Clipboard.SetData(DataFormats.Text, tableExport.ToString());
|
---|
| 475 | }
|
---|
[12833] | 476 |
|
---|
| 477 | private void ComboBoxPolicies_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
---|
| 478 | {
|
---|
[12840] | 479 | if (vm.SelectedPolicy == typeof(EpsGreedyPolicy))
|
---|
[12833] | 480 | {
|
---|
| 481 | TextBoxEpsylon.Visibility = Visibility.Visible;
|
---|
[13533] | 482 | vm.PolicyParameter = 0.5;
|
---|
[13518] | 483 | TextBlockEpsylon.Text = "Epsilon";
|
---|
[12833] | 484 | TextBlockEpsylon.Visibility = Visibility.Visible;
|
---|
| 485 | }
|
---|
[13533] | 486 | else if (vm.SelectedPolicy == typeof(UCTPolicy))
|
---|
[13492] | 487 | {
|
---|
| 488 | TextBoxEpsylon.Visibility = Visibility.Visible;
|
---|
[13518] | 489 | vm.PolicyParameter = Math.Sqrt(2);
|
---|
[13492] | 490 | TextBlockEpsylon.Text = "c";
|
---|
| 491 | TextBlockEpsylon.Visibility = Visibility.Visible;
|
---|
| 492 | }
|
---|
[12833] | 493 | else
|
---|
| 494 | {
|
---|
| 495 | TextBoxEpsylon.Visibility = Visibility.Hidden;
|
---|
| 496 | TextBlockEpsylon.Visibility = Visibility.Hidden;
|
---|
| 497 | }
|
---|
| 498 | }
|
---|
[12840] | 499 |
|
---|
| 500 | private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
---|
| 501 | {
|
---|
[13492] | 502 | if (vm.SelectedRun != null && vm.SelectedRun.RunState == RunState.Finished)
|
---|
[12840] | 503 | {
|
---|
[13492] | 504 |
|
---|
| 505 | if (ChartSelector.SelectedItem == TabSelectionIndicator)
|
---|
[12840] | 506 | {
|
---|
[13492] | 507 |
|
---|
| 508 | ClearSelectionChart();
|
---|
| 509 | DrawSelectionChart(vm.SelectedRun);
|
---|
[12840] | 510 | }
|
---|
[13492] | 511 | else if (ChartSelector.SelectedItem == TabQualityChart)
|
---|
[12840] | 512 | {
|
---|
[13492] | 513 |
|
---|
| 514 | ClearQualityChart();
|
---|
| 515 | DrawQualityChart(vm.SelectedRun);
|
---|
[12840] | 516 | }
|
---|
[13492] | 517 | else if (ChartSelector.SelectedItem == TabItemTree)
|
---|
| 518 | {
|
---|
| 519 | DrawTreeChart(vm.SelectedRun);
|
---|
| 520 | }
|
---|
[12840] | 521 | }
|
---|
| 522 | }
|
---|
[12503] | 523 | }
|
---|
| 524 | }
|
---|