Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2026 created a separate plugin for the classes for the GPDL code generation backend. To remove references to HL code from the core compiler code.

File size: 3.6 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.GPDL.CodeGen;
30using HeuristicLab.Problems.Instances;
31using HeuristicLab.Problems.Instances.Views;
32
33namespace HeuristicLab.Problems.GPDL.Views {
34  public partial class GpdlEditor : AsynchronousContentView, IProblemInstanceConsumer<string> {
35    public GpdlEditor() {
36      InitializeComponent();
37
38      viewHost.Content = null; //necessary to enable the change of the ViewType
39      viewHost.ViewType = typeof(GpdlProblemInstanceConsumerView);
40      viewHost.Content = this;
41    }
42
43    private void compileButton_Click(object sender, EventArgs e) {
44
45      using (var src = new MemoryStream(Encoding.UTF8.GetBytes(codeEditor.textEditor.Text))) {
46        Scanner scanner = new Scanner(src);
47        Parser parser = new Parser(scanner);
48        parser.Parse();
49
50        // generate an OSGA to solve the problem
51        var osga = new OffspringSelectionGeneticAlgorithm();
52        var problemGenerator = new ProblemGenerator();
53        osga.Problem = problemGenerator.GenerateFromAst(parser.AbstractSyntaxTree);
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.