Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2026: worked on plugin for grammars and made some changes for compatibility with the latest stable version of HL

File size: 3.5 KB
RevLine 
[9842]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;
[9519]23using System.IO;
24using System.Linq;
[9724]25using System.Text;
[9846]26using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
[9519]27using HeuristicLab.MainForm.WindowsForms;
[9846]28using HeuristicLab.Optimization;
[9519]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    }
41
42    private void compileButton_Click(object sender, EventArgs e) {
43
[9724]44      using (var src = new MemoryStream(Encoding.UTF8.GetBytes(codeEditor.textEditor.Text))) {
45        Scanner scanner = new Scanner(src);
46        Parser parser = new Parser(scanner);
47        parser.Parse();
[9846]48
49        // generate an OSGA to solve the problem
50        var osga = new OffspringSelectionGeneticAlgorithm();
51        osga.Problem = parser.problem;
52        osga.Engine = new SequentialEngine.SequentialEngine();
53        osga.PopulationSize.Value = 500;
54        osga.MutationProbability.Value = 0.15;
55        osga.ComparisonFactorUpperBound.Value = 1.0;
56        osga.ComparisonFactorLowerBound.Value = 1.0;
57        osga.MutatorParameter.Value =
58          osga.MutatorParameter.ValidValues.First(o => o.Name.Contains("MultiSymbolicExpressionTreeManipulator"));
59        osga.SelectorParameter.Value =
60          osga.SelectorParameter.ValidValues.First(o => o.Name.Contains("GenderSpecific"));
61        osga.MaximumSelectionPressure.Value = 500;
62        osga.MaximumGenerations.Value = 100;
63        MainForm.MainFormManager.MainForm.ShowContent(osga);
[9519]64      }
65
[9674]66      codeEditor.ClearErrors();
[9519]67
[9843]68      // TODO adapt to Coco/R error handling to show errors in the GUI
69
[9724]70      //if (Errors.NumOfErrors() == 0) {
71      //  GPDefLex.InitLex();
72      //  GPDefSyn.Interpret();
[9674]73
[9724]74      //} else {
75      //  int nLexErrors = Errors.NumOfLexErrors();
76      //  for (int i = 0; i < nLexErrors; i++) {
77      //    var lexErr = Errors.GetLexError(i == 0);
78      //    codeEditor.SetLexError(lexErr.msg, lexErr.line, lexErr.col);
79      //  }
80      //  int nSynErrors = Errors.NumOfSynErrors();
81      //  for (int i = 0; i < nSynErrors; i++) {
82      //    var synErr = Errors.GetSynError(i == 0);
83      //    codeEditor.SetLexError(synErr.msg, synErr.line, synErr.col);
84      //  }
85      //}
[9519]86    }
87
88
89    void IProblemInstanceConsumer<string>.Load(string data) {
[9674]90      codeEditor.textEditor.Text = data;
[9519]91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.