#region License Information
/* HeuristicLab
* Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.IO;
using System.Linq;
using System.Text;
using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
using HeuristicLab.MainForm.WindowsForms;
using HeuristicLab.Optimization;
using HeuristicLab.Problems.GPDL.CodeGen;
using HeuristicLab.Problems.Instances;
using HeuristicLab.Problems.Instances.Views;
namespace HeuristicLab.Problems.GPDL.Views {
public partial class GpdlEditor : AsynchronousContentView, IProblemInstanceConsumer {
public GpdlEditor() {
InitializeComponent();
viewHost.Content = null; //necessary to enable the change of the ViewType
viewHost.ViewType = typeof(GpdlProblemInstanceConsumerView);
viewHost.Content = this;
}
private void compileButton_Click(object sender, EventArgs e) {
using (var src = new MemoryStream(Encoding.UTF8.GetBytes(codeEditor.textEditor.Text))) {
Scanner scanner = new Scanner(src);
Parser parser = new Parser(scanner);
parser.Parse();
// generate an OSGA to solve the problem
var osga = new OffspringSelectionGeneticAlgorithm();
var problemGenerator = new ProblemGenerator();
osga.Problem = problemGenerator.GenerateFromAst(parser.AbstractSyntaxTree);
osga.Engine = new SequentialEngine.SequentialEngine();
osga.PopulationSize.Value = 500;
osga.MutationProbability.Value = 0.15;
osga.ComparisonFactorUpperBound.Value = 1.0;
osga.ComparisonFactorLowerBound.Value = 1.0;
osga.MutatorParameter.Value =
osga.MutatorParameter.ValidValues.First(o => o.Name.Contains("MultiSymbolicExpressionTreeManipulator"));
osga.SelectorParameter.Value =
osga.SelectorParameter.ValidValues.First(o => o.Name.Contains("GenderSpecific"));
osga.MaximumSelectionPressure.Value = 500;
osga.MaximumGenerations.Value = 100;
MainForm.MainFormManager.MainForm.ShowContent(osga);
}
codeEditor.ClearErrors();
// TODO adapt to Coco/R error handling to show errors in the GUI
//if (Errors.NumOfErrors() == 0) {
// GPDefLex.InitLex();
// GPDefSyn.Interpret();
//} else {
// int nLexErrors = Errors.NumOfLexErrors();
// for (int i = 0; i < nLexErrors; i++) {
// var lexErr = Errors.GetLexError(i == 0);
// codeEditor.SetLexError(lexErr.msg, lexErr.line, lexErr.col);
// }
// int nSynErrors = Errors.NumOfSynErrors();
// for (int i = 0; i < nSynErrors; i++) {
// var synErr = Errors.GetSynError(i == 0);
// codeEditor.SetLexError(synErr.msg, synErr.line, synErr.col);
// }
//}
}
void IProblemInstanceConsumer.Load(string data) {
codeEditor.textEditor.Text = data;
}
}
}