[10071] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10071] | 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/>.
|
---|
[10968] | 19 | *
|
---|
| 20 | * Author: Sabine Winkler
|
---|
[10071] | 21 | */
|
---|
| 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 28 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 29 | using HeuristicLab.Operators;
|
---|
| 30 | using HeuristicLab.Optimization;
|
---|
| 31 | using HeuristicLab.Parameters;
|
---|
| 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 33 | using HeuristicLab.Problems.ArtificialAnt;
|
---|
| 34 | using HeuristicLab.Problems.GrammaticalEvolution.Mappers;
|
---|
| 35 |
|
---|
| 36 | namespace HeuristicLab.Problems.GrammaticalEvolution {
|
---|
[10974] | 37 | [Item("GEArtificialAntEvaluator", "Evaluates an artificial ant solution for grammatical evolution.")]
|
---|
[10071] | 38 | [StorableClass]
|
---|
| 39 | public class GEArtificialAntEvaluator : SingleSuccessorOperator,
|
---|
| 40 | ISingleObjectiveEvaluator, ISymbolicExpressionTreeGrammarBasedOperator {
|
---|
| 41 |
|
---|
| 42 | #region Parameter Properties
|
---|
| 43 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
| 44 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 45 | }
|
---|
| 46 | // genotype:
|
---|
| 47 | public ILookupParameter<IntegerVector> IntegerVectorParameter {
|
---|
| 48 | get { return (ILookupParameter<IntegerVector>)Parameters["IntegerVector"]; }
|
---|
| 49 | }
|
---|
| 50 | // phenotype:
|
---|
| 51 | public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
| 52 | get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
|
---|
| 53 | }
|
---|
| 54 | public ILookupParameter<BoolMatrix> WorldParameter {
|
---|
| 55 | get { return (ILookupParameter<BoolMatrix>)Parameters["World"]; }
|
---|
| 56 | }
|
---|
| 57 | public ILookupParameter<IntValue> MaxTimeStepsParameter {
|
---|
| 58 | get { return (ILookupParameter<IntValue>)Parameters["MaxTimeSteps"]; }
|
---|
| 59 | }
|
---|
| 60 | public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
|
---|
| 61 | get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters["SymbolicExpressionTreeGrammar"]; }
|
---|
| 62 | }
|
---|
| 63 | // genotype-to-phenotype-mapper:
|
---|
| 64 | public ILookupParameter<IGenotypeToPhenotypeMapper> GenotypeToPhenotypeMapperParameter {
|
---|
| 65 | get { return (ILookupParameter<IGenotypeToPhenotypeMapper>)Parameters["GenotypeToPhenotypeMapper"]; }
|
---|
| 66 | }
|
---|
[10280] | 67 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 68 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 69 | }
|
---|
[10290] | 70 | public ILookupParameter<IntMatrix> BoundsParameter {
|
---|
| 71 | get { return (ILookupParameter<IntMatrix>)Parameters["Bounds"]; }
|
---|
| 72 | }
|
---|
| 73 | public ILookupParameter<IntValue> MaxExpressionLengthParameter {
|
---|
| 74 | get { return (ILookupParameter<IntValue>)Parameters["MaximumExpressionLength"]; }
|
---|
| 75 | }
|
---|
[10071] | 76 | #endregion
|
---|
| 77 |
|
---|
| 78 | [StorableConstructor]
|
---|
| 79 | protected GEArtificialAntEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 80 | protected GEArtificialAntEvaluator(GEArtificialAntEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
| 81 | public override IDeepCloneable Clone(Cloner cloner) { return new GEArtificialAntEvaluator(this, cloner); }
|
---|
| 82 | public GEArtificialAntEvaluator()
|
---|
| 83 | : base() {
|
---|
| 84 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the evaluated artificial ant solution."));
|
---|
| 85 | Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The artificial ant solution encoded as an integer vector genome."));
|
---|
| 86 | Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The artificial ant solution encoded as a symbolic expression tree that should be evaluated"));
|
---|
| 87 | Parameters.Add(new LookupParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items."));
|
---|
| 88 | Parameters.Add(new LookupParameter<IntValue>("MaxTimeSteps", "The maximal number of time steps that the artificial ant should be simulated."));
|
---|
| 89 | Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>("SymbolicExpressionTreeGrammar", "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
|
---|
| 90 | Parameters.Add(new LookupParameter<IGenotypeToPhenotypeMapper>("GenotypeToPhenotypeMapper", "Maps the genotype (an integer vector) to the phenotype (a symbolic expression tree)."));
|
---|
[10280] | 91 | Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator for the genotype creation and the genotype-to-phenotype mapping."));
|
---|
[10290] | 92 |
|
---|
| 93 | Parameters.Add(new LookupParameter<IntMatrix>("Bounds", "The integer number range in which the single genomes of a genotype are created."));
|
---|
[10328] | 94 | Parameters.Add(new LookupParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant (genotype length)."));
|
---|
[10071] | 95 | }
|
---|
| 96 |
|
---|
| 97 | public sealed override IOperation Apply() {
|
---|
[10280] | 98 | SymbolicExpressionTree tree = GenotypeToPhenotypeMapperParameter.ActualValue.Map(
|
---|
| 99 | RandomParameter.ActualValue,
|
---|
[10290] | 100 | BoundsParameter.ActualValue,
|
---|
| 101 | MaxExpressionLengthParameter.ActualValue.Value,
|
---|
[10071] | 102 | SymbolicExpressionTreeGrammarParameter.ActualValue,
|
---|
| 103 | IntegerVectorParameter.ActualValue
|
---|
| 104 | );
|
---|
[10280] | 105 | SymbolicExpressionTreeParameter.ActualValue = tree;
|
---|
[10071] | 106 | BoolMatrix world = WorldParameter.ActualValue;
|
---|
| 107 | IntValue maxTimeSteps = MaxTimeStepsParameter.ActualValue;
|
---|
| 108 |
|
---|
| 109 | AntInterpreter interpreter = new AntInterpreter();
|
---|
| 110 | interpreter.MaxTimeSteps = maxTimeSteps.Value;
|
---|
| 111 | interpreter.World = world;
|
---|
[10280] | 112 | interpreter.Expression = tree;
|
---|
[10071] | 113 | interpreter.Run();
|
---|
| 114 |
|
---|
| 115 | QualityParameter.ActualValue = new DoubleValue(interpreter.FoodEaten);
|
---|
| 116 | return null;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | } |
---|