Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2069 removed dead code

File size: 3.4 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 System.Threading;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Problems.Robocode {
33  [StorableClass]
34  [Item("Robocode Evaluator", "Evaluator for the Robocode GP problem.")]
35  public class RobocodeEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluator {
36    private const string QualityParameterName = "Quality";
37    private const string TankProgramParameterName = "TankProgram";
38    private const string RobocodePathParamaterName = "Path";
39
40    //TODO: this should be removed
41    public static SemaphoreSlim semaphore = new SemaphoreSlim(10);
42
43    #region Parameters
44    public ILookupParameter<DoubleValue> QualityParameter {
45      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
46    }
47    public ILookupParameter<ISymbolicExpressionTree> TankProgramParameter {
48      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[TankProgramParameterName]; }
49    }
50    public ILookupParameter<StringValue> RobocodePathParameter {
51      get { return (ILookupParameter<StringValue>)Parameters[RobocodePathParamaterName]; }
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<StringValue>(RobocodePathParamaterName, "Path of the Robocode installation."));
64    }
65
66    public override IOperation Apply() {
67      semaphore.Wait();
68
69      ISymbolicExpressionTree tree = TankProgramParameter.ActualValue;
70      string path = RobocodePathParameter.ActualValue.Value;
71      QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path));
72
73      semaphore.Release();
74
75      return base.Apply();
76    }
77
78    public override IDeepCloneable Clone(Cloner cloner) {
79      return new RobocodeEvaluator(this, cloner);
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.