#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.Robocode { [StorableClass] [Item("Robocode Evaluator", "Evaluator for the Robocode GP problem.")] public class RobocodeEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluator { private const string QualityParameterName = "Quality"; private const string TankProgramParameterName = "TankProgram"; private const string RobocodePathParamaterName = "RobocodePath"; private const string NrOfRoundsParameterName = "NrOfRounds"; private const string EnemiesParameterName = "Enemies"; #region Parameters public ILookupParameter QualityParameter { get { return (ILookupParameter)Parameters[QualityParameterName]; } } public ILookupParameter TankProgramParameter { get { return (ILookupParameter)Parameters[TankProgramParameterName]; } } public ILookupParameter RobocodePathParameter { get { return (ILookupParameter)Parameters[RobocodePathParamaterName]; } } public ILookupParameter NrOfRoundsParameter { get { return (ILookupParameter)Parameters[NrOfRoundsParameterName]; } } public ILookupParameter EnemiesParameter { get { return (ILookupParameter)Parameters[EnemiesParameterName]; } } #endregion [StorableConstructor] protected RobocodeEvaluator(bool deserializing) : base(deserializing) { } protected RobocodeEvaluator(RobocodeEvaluator original, Cloner cloner) : base(original, cloner) { } public RobocodeEvaluator() { Parameters.Add(new LookupParameter(QualityParameterName, "The solution quality of the Robocode tank program.")); Parameters.Add(new LookupParameter(TankProgramParameterName, "The Robocode tank program to evaluate represented as a symbolic expression tree.")); Parameters.Add(new LookupParameter(RobocodePathParamaterName, "Path of the Robocode installation.")); Parameters.Add(new LookupParameter(NrOfRoundsParameterName, "Nr. of Rounds a Robot has to fight against each opponent.")); Parameters.Add(new LookupParameter(EnemiesParameterName, "The enemies that should be battled.")); } public override IOperation Apply() { ISymbolicExpressionTree tree = TankProgramParameter.ActualValue; string path = RobocodePathParameter.ActualValue.Value; QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path, EnemiesParameter.ActualValue, null, false, NrOfRoundsParameter.ActualValue.Value)); return base.Apply(); } public override IDeepCloneable Clone(Cloner cloner) { return new RobocodeEvaluator(this, cloner); } } }