Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 12209 was 9971, checked in by ascheibe, 11 years ago

#2069 added a view for displaying/reloading enemies

File size: 4.0 KB
RevLine 
[9879]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.")]
[9880]34  public class RobocodeEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluator {
[9879]35    private const string QualityParameterName = "Quality";
36    private const string TankProgramParameterName = "TankProgram";
[9926]37    private const string RobocodePathParamaterName = "RobocodePath";
38    private const string NrOfRoundsParameterName = "NrOfRounds";
[9947]39    private const string EnemiesParameterName = "Enemies";
[9879]40
[9880]41    #region Parameters
[9879]42    public ILookupParameter<DoubleValue> QualityParameter {
[9880]43      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
[9879]44    }
45    public ILookupParameter<ISymbolicExpressionTree> TankProgramParameter {
[9880]46      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[TankProgramParameterName]; }
[9879]47    }
[9892]48    public ILookupParameter<DirectoryValue> RobocodePathParameter {
49      get { return (ILookupParameter<DirectoryValue>)Parameters[RobocodePathParamaterName]; }
[9879]50    }
[9926]51    public ILookupParameter<IntValue> NrOfRoundsParameter {
52      get { return (ILookupParameter<IntValue>)Parameters[NrOfRoundsParameterName]; }
53    }
[9971]54    public ILookupParameter<EnemyCollection> EnemiesParameter {
55      get { return (ILookupParameter<EnemyCollection>)Parameters[EnemiesParameterName]; }
[9947]56    }
[9879]57    #endregion
58
59    [StorableConstructor]
60    protected RobocodeEvaluator(bool deserializing) : base(deserializing) { }
61    protected RobocodeEvaluator(RobocodeEvaluator original, Cloner cloner)
[9880]62      : base(original, cloner) { }
[9879]63
64    public RobocodeEvaluator() {
[9880]65      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The solution quality of the Robocode tank program."));
66      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(TankProgramParameterName, "The Robocode tank program to evaluate represented as a symbolic expression tree."));
[9892]67      Parameters.Add(new LookupParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation."));
[9926]68      Parameters.Add(new LookupParameter<IntValue>(NrOfRoundsParameterName, "Nr. of Rounds a Robot has to fight against each opponent."));
[9971]69      Parameters.Add(new LookupParameter<EnemyCollection>(EnemiesParameterName, "The enemies that should be battled."));
[9879]70    }
71
72    public override IOperation Apply() {
73      ISymbolicExpressionTree tree = TankProgramParameter.ActualValue;
74      string path = RobocodePathParameter.ActualValue.Value;
[9947]75      QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path, EnemiesParameter.ActualValue, null, false, NrOfRoundsParameter.ActualValue.Value));
[9879]76
77      return base.Apply();
78    }
79
80    public override IDeepCloneable Clone(Cloner cloner) {
81      return new RobocodeEvaluator(this, cloner);
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.