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

Last change on this file since 9926 was 9926, checked in by ascheibe, 6 years ago

#2069

  • renamed path parameter to robocode path
  • made number of rounds configurable
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 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 = "RobocodePath";
38    private const string NrOfRoundsParameterName = "NrOfRounds";
39
40    #region Parameters
41    public ILookupParameter<DoubleValue> QualityParameter {
42      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
43    }
44    public ILookupParameter<ISymbolicExpressionTree> TankProgramParameter {
45      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[TankProgramParameterName]; }
46    }
47    public ILookupParameter<DirectoryValue> RobocodePathParameter {
48      get { return (ILookupParameter<DirectoryValue>)Parameters[RobocodePathParamaterName]; }
49    }
50    public ILookupParameter<IntValue> NrOfRoundsParameter {
51      get { return (ILookupParameter<IntValue>)Parameters[NrOfRoundsParameterName]; }
52    }
53    #endregion
54
55    [StorableConstructor]
56    protected RobocodeEvaluator(bool deserializing) : base(deserializing) { }
57    protected RobocodeEvaluator(RobocodeEvaluator original, Cloner cloner)
58      : base(original, cloner) { }
59
60    public RobocodeEvaluator() {
61      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The solution quality of the Robocode tank program."));
62      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(TankProgramParameterName, "The Robocode tank program to evaluate represented as a symbolic expression tree."));
63      Parameters.Add(new LookupParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation."));
64      Parameters.Add(new LookupParameter<IntValue>(NrOfRoundsParameterName, "Nr. of Rounds a Robot has to fight against each opponent."));
65    }
66
67    public override IOperation Apply() {
68      ISymbolicExpressionTree tree = TankProgramParameter.ActualValue;
69      string path = RobocodePathParameter.ActualValue.Value;
70      QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path, null, false, NrOfRoundsParameter.ActualValue.Value));
71
72      return base.Apply();
73    }
74
75    public override IDeepCloneable Clone(Cloner cloner) {
76      return new RobocodeEvaluator(this, cloner);
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.