[11514] | 1 | using System;
|
---|
| 2 | using System.Linq;
|
---|
| 3 | using System.Threading;
|
---|
| 4 | using System.Windows.Forms;
|
---|
| 5 |
|
---|
| 6 | using HeuristicLab.Algorithms.GeneticAlgorithm;
|
---|
| 7 | using HeuristicLab.Core;
|
---|
| 8 | using HeuristicLab.MainForm;
|
---|
| 9 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 10 | using HeuristicLab.Optimization;
|
---|
| 11 | using HeuristicLab.Optimization.Views;
|
---|
| 12 | using HeuristicLab.Problems.TravelingSalesman;
|
---|
| 13 |
|
---|
| 14 | public 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 | } |
---|