Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/GpdlEditor.cs @ 9928

Last change on this file since 9928 was 9846, checked in by gkronber, 11 years ago

#2026 added lawn mower problem. create a OSGA for solving the compiled problem directly

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.IO;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
27using HeuristicLab.MainForm.WindowsForms;
28using HeuristicLab.Optimization;
29using HeuristicLab.Problems.Instances;
30using HeuristicLab.Problems.Instances.Views;
31
32namespace HeuristicLab.Problems.GPDL.Views {
33  public partial class GpdlEditor : AsynchronousContentView, IProblemInstanceConsumer<string> {
34    public GpdlEditor() {
35      InitializeComponent();
36
37      viewHost.Content = null; //necessary to enable the change of the ViewType
38      viewHost.ViewType = typeof(GpdlProblemInstanceConsumerView);
39      viewHost.Content = this;
40      ProblemInstanceConsumerView view = (ProblemInstanceConsumerView)viewHost.ActiveView;
41      splitContainer.Panel1Collapsed = !view.ProblemInstanceProviders.Any();
42    }
43
44    private void compileButton_Click(object sender, EventArgs e) {
45
46      using (var src = new MemoryStream(Encoding.UTF8.GetBytes(codeEditor.textEditor.Text))) {
47        Scanner scanner = new Scanner(src);
48        Parser parser = new Parser(scanner);
49        parser.Parse();
50
51        // generate an OSGA to solve the problem
52        var osga = new OffspringSelectionGeneticAlgorithm();
53        osga.Problem = parser.problem;
54        osga.Engine = new SequentialEngine.SequentialEngine();
55        osga.PopulationSize.Value = 500;
56        osga.MutationProbability.Value = 0.15;
57        osga.ComparisonFactorUpperBound.Value = 1.0;
58        osga.ComparisonFactorLowerBound.Value = 1.0;
59        osga.MutatorParameter.Value =
60          osga.MutatorParameter.ValidValues.First(o => o.Name.Contains("MultiSymbolicExpressionTreeManipulator"));
61        osga.SelectorParameter.Value =
62          osga.SelectorParameter.ValidValues.First(o => o.Name.Contains("GenderSpecific"));
63        osga.MaximumSelectionPressure.Value = 500;
64        osga.MaximumGenerations.Value = 100;
65        MainForm.MainFormManager.MainForm.ShowContent(osga);
66      }
67
68      codeEditor.ClearErrors();
69
70      // TODO adapt to Coco/R error handling to show errors in the GUI
71
72      //if (Errors.NumOfErrors() == 0) {
73      //  GPDefLex.InitLex();
74      //  GPDefSyn.Interpret();
75
76      //} else {
77      //  int nLexErrors = Errors.NumOfLexErrors();
78      //  for (int i = 0; i < nLexErrors; i++) {
79      //    var lexErr = Errors.GetLexError(i == 0);
80      //    codeEditor.SetLexError(lexErr.msg, lexErr.line, lexErr.col);
81      //  }
82      //  int nSynErrors = Errors.NumOfSynErrors();
83      //  for (int i = 0; i < nSynErrors; i++) {
84      //    var synErr = Errors.GetSynError(i == 0);
85      //    codeEditor.SetLexError(synErr.msg, synErr.line, synErr.col);
86      //  }
87      //}
88    }
89
90
91    void IProblemInstanceConsumer<string>.Load(string data) {
92      codeEditor.textEditor.Text = data;
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.