Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeEvaluator.cs @ 9891

Last change on this file since 9891 was 9881, checked in by ascheibe, 11 years ago

#2069 improved interpreter

File size: 3.2 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.Robocode {
32  [StorableClass]
33  [Item("Robocode Evaluator", "Evaluator for the Robocode GP problem.")]
34  public class RobocodeEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluator {
35    private const string QualityParameterName = "Quality";
36    private const string TankProgramParameterName = "TankProgram";
37    private const string RobocodePathParamaterName = "Path";
38
39    #region Parameters
40    public ILookupParameter<DoubleValue> QualityParameter {
41      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
42    }
43    public ILookupParameter<ISymbolicExpressionTree> TankProgramParameter {
44      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[TankProgramParameterName]; }
45    }
46    public ILookupParameter<StringValue> RobocodePathParameter {
47      get { return (ILookupParameter<StringValue>)Parameters[RobocodePathParamaterName]; }
48    }
49    #endregion
50
51    [StorableConstructor]
52    protected RobocodeEvaluator(bool deserializing) : base(deserializing) { }
53    protected RobocodeEvaluator(RobocodeEvaluator original, Cloner cloner)
54      : base(original, cloner) { }
55
56    public RobocodeEvaluator() {
57      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The solution quality of the Robocode tank program."));
58      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(TankProgramParameterName, "The Robocode tank program to evaluate represented as a symbolic expression tree."));
59      Parameters.Add(new LookupParameter<StringValue>(RobocodePathParamaterName, "Path of the Robocode installation."));
60    }
61
62    public override IOperation Apply() {
63      ISymbolicExpressionTree tree = TankProgramParameter.ActualValue;
64      string path = RobocodePathParameter.ActualValue.Value;
65      QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path));
66
67      return base.Apply();
68    }
69
70    public override IDeepCloneable Clone(Cloner cloner) {
71      return new RobocodeEvaluator(this, cloner);
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.