Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceOverhaul/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Script Sources/GUIAutomationScriptSource.cs @ 14712

Last change on this file since 14712 was 14712, checked in by gkronber, 7 years ago

#2520 added GUIDs for (almost) all interface types (probably still too many) also added newlines at end of all files

File size: 1.7 KB
Line 
1using System;
2using System.Linq;
3using System.Threading;
4using System.Windows.Forms;
5
6using HeuristicLab.Algorithms.GeneticAlgorithm;
7using HeuristicLab.Core;
8using HeuristicLab.MainForm;
9using HeuristicLab.MainForm.WindowsForms;
10using HeuristicLab.Optimization;
11using HeuristicLab.Optimization.Views;
12using HeuristicLab.Problems.TravelingSalesman;
13
14public class GUIAutomationScript : HeuristicLab.Scripting.CSharpScriptBase {
15  readonly ManualResetEvent mutex = new ManualResetEvent(false);
16
17  public override void Main() {
18    var ga = new GeneticAlgorithm {
19      MaximumGenerations = { Value = 50 },
20      PopulationSize = { Value = 10 },
21      Problem = new TravelingSalesmanProblem()
22    };
23
24    var experiment = new Experiment();
25    for (int i = 0; i < 5; i++) {
26      experiment.Optimizers.Add(new BatchRun() { Optimizer = (IOptimizer)ga.Clone(), Repetitions = 10 });
27      ga.PopulationSize.Value *= 2;
28    }
29
30    experiment.ExecutionStateChanged += OnExecutionStateChanged;
31    experiment.Start();
32    mutex.WaitOne();
33
34    vars.experiment = experiment;
35    MainFormManager.MainForm.ShowContent(experiment);
36    var viewHost = (ViewHost)MainFormManager.MainForm.ShowContent(experiment.Runs, typeof(RunCollectionBubbleChartView));
37    var bubbleChart = (UserControl)(viewHost.ActiveView);
38    bubbleChart.Controls.OfType<ComboBox>().Single(x => x.Name == "yAxisComboBox").SelectedItem = "BestQuality";
39    bubbleChart.Controls.OfType<ComboBox>().Single(x => x.Name == "xAxisComboBox").SelectedItem = "PopulationSize";
40  }
41
42  private void OnExecutionStateChanged(object sender, EventArgs e) {
43    if (((IExecutable)sender).ExecutionState == ExecutionState.Stopped)
44      mutex.Set();
45  }
46}
Note: See TracBrowser for help on using the repository browser.