Index: trunk/sources/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.GrammaticalEvolution/3.3/ArtificialAnt/GEArtificialAntProblem.cs	(revision 12504)
+++ trunk/sources/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs	(revision 12915)
@@ -22,6 +22,5 @@
 #endregion
 
-using System;
-using System.Collections.Generic;
+using System.Diagnostics.Contracts;
 using System.Linq;
 using HeuristicLab.Common;
@@ -29,11 +28,8 @@
 using HeuristicLab.Data;
 using HeuristicLab.Encodings.IntegerVectorEncoding;
-using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
 using HeuristicLab.Optimization;
 using HeuristicLab.Parameters;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.PluginInfrastructure;
-using HeuristicLab.Problems.ArtificialAnt;
-using HeuristicLab.Problems.ArtificialAnt.Analyzers;
+using HeuristicLab.Problems.GeneticProgramming.ArtificialAnt;
 using HeuristicLab.Problems.GrammaticalEvolution.Mappers;
 
@@ -42,59 +38,13 @@
   [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 170)]
   [StorableClass]
-  public sealed class GEArtificialAntProblem : SingleObjectiveHeuristicOptimizationProblem<GEArtificialAntEvaluator, IIntegerVectorCreator>, IStorableContent {
+  public sealed class GEArtificialAntProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding>, IStorableContent {
     public string Filename { get; set; }
 
-    #region constant for default world (Santa Fe)
-    private readonly bool[,] santaFeAntTrail = new bool[,] {
-      {false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, false, false, false, false}, 
-      {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false}, 
-      {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false}, 
-      {false, false, false, true, true, true, true, false, true, true, true, true, true, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, true, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, true, true, true, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false}, 
-      {false, false, false, true, true, false, false, true, true, true, true, true, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, true, false, false, false, false, false, false, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 
-      {false, false, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false },
-      {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }
-    };
-    #endregion
-
     #region Parameter Properties
-    public IValueParameter<ISymbolicExpressionGrammar> ArtificialAntExpressionGrammarParameter {
-      get { return (IValueParameter<ISymbolicExpressionGrammar>)Parameters["ArtificialAntExpressionGrammar"]; }
-    }
-    public IValueParameter<IntValue> MaxExpressionLengthParameter {
-      get { return (IValueParameter<IntValue>)Parameters["MaximumExpressionLength"]; }
-    }
     public IValueParameter<BoolMatrix> WorldParameter {
       get { return (IValueParameter<BoolMatrix>)Parameters["World"]; }
     }
-    public IValueParameter<IntValue> MaxTimeStepsParameter {
-      get { return (IValueParameter<IntValue>)Parameters["MaximumTimeSteps"]; }
-    }
-    public IValueParameter<IntMatrix> BoundsParameter {
-      get { return (IValueParameter<IntMatrix>)Parameters["Bounds"]; }
+    public IFixedValueParameter<IntValue> MaxTimeStepsParameter {
+      get { return (IFixedValueParameter<IntValue>)Parameters["MaximumTimeSteps"]; }
     }
     public IValueParameter<IGenotypeToPhenotypeMapper> GenotypeToPhenotypeMapperParameter {
@@ -108,21 +58,7 @@
       set { WorldParameter.Value = value; }
     }
-    public IntValue MaxTimeSteps {
-      get { return MaxTimeStepsParameter.Value; }
-      set { MaxTimeStepsParameter.Value = value; }
-    }
-    public IntValue MaxExpressionLength {
-      get { return MaxExpressionLengthParameter.Value; }
-      set { MaxExpressionLengthParameter.Value = value; }
-    }
-    public ArtificialAntExpressionGrammar ArtificialAntExpressionGrammar {
-      get { return (ArtificialAntExpressionGrammar)ArtificialAntExpressionGrammarParameter.Value; }
-    }
-    public IEnumerable<IAntTrailAnalyzer> AntTrailAnalyzers {
-      get { return Operators.OfType<IAntTrailAnalyzer>(); }
-    }
-    public IntMatrix Bounds {
-      get { return BoundsParameter.Value; }
-      set { BoundsParameter.Value = value; }
+    public int MaxTimeSteps {
+      get { return MaxTimeStepsParameter.Value.Value; }
+      set { MaxTimeStepsParameter.Value.Value = value; }
     }
     #endregion
@@ -131,11 +67,17 @@
     private GEArtificialAntProblem(bool deserializing) : base(deserializing) { }
     [StorableHook(HookType.AfterDeserialization)]
-    private void AfterDeserialization() {
-      RegisterEventHandlers();
+    private void AfterDeserialization() { }
+
+    public override bool Maximization {
+      get { return true; }
     }
+
+    [Storable]
+    // parameters of the wrapped problem cannot be changed therefore it is not strictly necessary to clone and store it
+    private readonly HeuristicLab.Problems.GeneticProgramming.ArtificialAnt.Problem wrappedAntProblem;
 
     private GEArtificialAntProblem(GEArtificialAntProblem original, Cloner cloner)
       : base(original, cloner) {
-      RegisterEventHandlers();
+      this.wrappedAntProblem = cloner.Clone(original.wrappedAntProblem);
     }
 
@@ -145,127 +87,43 @@
 
     public GEArtificialAntProblem()
-      : base(new GEArtificialAntEvaluator(), new UniformRandomIntegerVectorCreator()) {
-      BoolMatrix world = new BoolMatrix(santaFeAntTrail);
-      Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant (genotype length).", new IntValue(30)));
-      Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", new ArtificialAntExpressionGrammar()));
-      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
-      Parameters.Add(new ValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
-      IntMatrix m = new IntMatrix(new int[,] { { 0, 100 } });
-      Parameters.Add(new ValueParameter<IntMatrix>("Bounds", "The integer number range in which the single genomes of a genotype are created.", m));
+      : base() {
+      wrappedAntProblem = new HeuristicLab.Problems.GeneticProgramming.ArtificialAnt.Problem();
+      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", wrappedAntProblem.World));
+      Parameters.Add(new FixedValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
       Parameters.Add(new ValueParameter<IGenotypeToPhenotypeMapper>("GenotypeToPhenotypeMapper", "Maps the genotype (an integer vector) to the phenotype (a symbolic expression tree).", new DepthFirstMapper()));
 
-      Maximization.Value = true;
-      MaximizationParameter.Hidden = true;
-      BestKnownQuality = new DoubleValue(89);
+      Encoding = new IntegerVectorEncoding(30) { Bounds = new IntMatrix(new int[,] { { 0, 100 } }) };
 
-      SolutionCreator.IntegerVectorParameter.ActualName = "AntTrailSolutionIntegerVector";
-      Evaluator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolutionTree";
-      Evaluator.SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar";
-      Evaluator.QualityParameter.ActualName = "FoodEaten";
-
-      InitializeOperators();
-      RegisterEventHandlers();
+      BestKnownQuality = wrappedAntProblem.BestKnownQuality;
     }
 
-    #region Events
-    protected override void OnSolutionCreatorChanged() {
-      base.OnSolutionCreatorChanged();
+    public override double Evaluate(Individual individual, IRandom random) {
+      var vector = individual.IntegerVector();
 
-      SolutionCreator.IntegerVectorParameter.ActualName = "AntTrailSolutionIntegerVector";
-      SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
+      var bounds = Encoding.Bounds;
+      var len = Encoding.Length;
+      var grammar = wrappedAntProblem.Encoding.Grammar;
+      var mapper = GenotypeToPhenotypeMapperParameter.Value;
 
-      ParameterizeAnalyzers();
-      ParameterizeOperators();
+      var tree = mapper.Map(random, bounds, len, grammar, vector);
+
+      Interpreter interpreter = new Interpreter(tree, World, MaxTimeSteps);
+      interpreter.Run();
+
+      return interpreter.FoodEaten;
     }
 
-    protected override void OnEvaluatorChanged() {
-      base.OnEvaluatorChanged();
+    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
+      var bounds = Encoding.Bounds;
+      var len = Encoding.Length;
+      var grammar = wrappedAntProblem.Encoding.Grammar;
+      var mapper = GenotypeToPhenotypeMapperParameter.Value;
 
-      Evaluator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolutionTree";
-      Evaluator.SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar";
-      Evaluator.QualityParameter.ActualName = "FoodEaten";
+      var trees = individuals
+        .Select(ind => mapper.Map(random, bounds, len, grammar, ind.IntegerVector()))
+        .ToArray();
 
-      Evaluator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(Evaluator_SymbolicExpressionTreeParameter_ActualNameChanged);
-      Evaluator.SymbolicExpressionTreeGrammarParameter.ActualNameChanged += new EventHandler(Evaluator_SymbolicExpressionTreeGrammarParameter_ActualNameChanged);
-      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
-
-      ParameterizeAnalyzers();
-      ParameterizeOperators();
+      wrappedAntProblem.Analyze(trees, qualities, results, random);
     }
-
-    private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) {
-      ParameterizeAnalyzers();
-      ParameterizeOperators();
-    }
-
-    private void Evaluator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
-      ParameterizeAnalyzers();
-      ParameterizeOperators();
-    }
-
-    private void Evaluator_SymbolicExpressionTreeGrammarParameter_ActualNameChanged(object sender, EventArgs e) {
-      ParameterizeAnalyzers();
-      ParameterizeOperators();
-    }
-
-    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
-      ParameterizeAnalyzers();
-      ParameterizeOperators();
-    }
-    #endregion
-
-    #region Helpers
-    private void RegisterEventHandlers() {
-      SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
-      Evaluator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(Evaluator_SymbolicExpressionTreeParameter_ActualNameChanged);
-      Evaluator.SymbolicExpressionTreeGrammarParameter.ActualNameChanged += new EventHandler(Evaluator_SymbolicExpressionTreeGrammarParameter_ActualNameChanged);
-      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
-    }
-
-    private void InitializeOperators() {
-      Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>().OfType<IOperator>());
-      Operators.Add(new BestAntTrailAnalyzer());
-      Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer());
-      Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
-      ParameterizeAnalyzers();
-      ParameterizeOperators();
-    }
-
-    private void ParameterizeAnalyzers() {
-      foreach (IAntTrailAnalyzer analyzer in AntTrailAnalyzers) {
-        analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
-        analyzer.SymbolicExpressionTreeParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName;
-        analyzer.WorldParameter.ActualName = WorldParameter.Name;
-        analyzer.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
-      }
-      foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
-        analyzer.SymbolicExpressionTreeParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName;
-      }
-    }
-
-    private void ParameterizeOperators() {
-      var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
-
-      foreach (ISymbolicExpressionTreeGrammarBasedOperator op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
-        op.SymbolicExpressionTreeGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name;
-      }
-      foreach (GEArtificialAntEvaluator op in operators.OfType<GEArtificialAntEvaluator>()) {
-        op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
-        op.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
-        op.WorldParameter.ActualName = WorldParameter.Name;
-      }
-      foreach (IIntegerVectorCrossover op in operators.OfType<IIntegerVectorCrossover>()) {
-        op.ParentsParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
-        op.ChildParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
-      }
-      foreach (IIntegerVectorManipulator op in operators.OfType<IIntegerVectorManipulator>()) {
-        op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
-      }
-      foreach (IIntegerVectorCreator op in operators.OfType<IIntegerVectorCreator>()) {
-        op.BoundsParameter.ActualName = BoundsParameter.Name;
-        op.LengthParameter.ActualName = MaxExpressionLengthParameter.Name;
-      }
-    }
-    #endregion
   }
 }
