Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/13/13 12:11:18 (11 years ago)
Author:
ascheibe
Message:

#2069 removed dead code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeEvaluator.cs

    r9879 r9880  
    2020#endregion
    2121
    22 
    23 using System;
    2422using System.Threading;
    25 using System.Xml;
    2623using HeuristicLab.Common;
    2724using HeuristicLab.Core;
     
    3633  [StorableClass]
    3734  [Item("Robocode Evaluator", "Evaluator for the Robocode GP problem.")]
    38   public class RobocodeEvaluator : SingleSuccessorOperator,
    39     ISingleObjectiveEvaluator {
    40     #region parameter names
     35  public class RobocodeEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluator {
    4136    private const string QualityParameterName = "Quality";
    4237    private const string TankProgramParameterName = "TankProgram";
    4338    private const string RobocodePathParamaterName = "Path";
    44     private const string CoevolutionParameterName = "Coevolution";
    4539
     40    //TODO: this should be removed
     41    public static SemaphoreSlim semaphore = new SemaphoreSlim(10);
    4642
    47     private static string solutionTemplatePath = "";
    48     public static string SolutionTemplate {
    49       get { return solutionTemplatePath; }
    50       set {
    51         solutionTemplatePath = value;
    52       }
    53     }
    54 
    55     public static SemaphoreSlim semaphore = new SemaphoreSlim(10);
    56     #endregion
    57 
    58 
    59     #region parameters
     43    #region Parameters
    6044    public ILookupParameter<DoubleValue> QualityParameter {
    61       get {
    62         return (ILookupParameter<DoubleValue>)
    63                  Parameters[QualityParameterName];
    64       }
     45      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
    6546    }
    6647    public ILookupParameter<ISymbolicExpressionTree> TankProgramParameter {
    67       get {
    68         return (ILookupParameter<ISymbolicExpressionTree>)
    69                  Parameters[TankProgramParameterName];
    70       }
     48      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[TankProgramParameterName]; }
    7149    }
    7250    public ILookupParameter<StringValue> RobocodePathParameter {
    73       get {
    74         return (ILookupParameter<StringValue>)
    75             Parameters[RobocodePathParamaterName];
    76       }
    77     }
    78     public ILookupParameter<BoolValue> CoevolutionParameter {
    79       get {
    80         return (ILookupParameter<BoolValue>)
    81             Parameters[CoevolutionParameterName];
    82       }
     51      get { return (ILookupParameter<StringValue>)Parameters[RobocodePathParamaterName]; }
    8352    }
    8453    #endregion
    85 
    8654
    8755    [StorableConstructor]
    8856    protected RobocodeEvaluator(bool deserializing) : base(deserializing) { }
    8957    protected RobocodeEvaluator(RobocodeEvaluator original, Cloner cloner)
    90       : base(original, 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."));
    9164    }
    9265
    93     // default constructor for the evaluator
    94     public RobocodeEvaluator() {
    95       Parameters.Add(
    96         new LookupParameter<DoubleValue>(
    97           QualityParameterName,
    98           "The solution quality of the Robocode tank program."));
    99       Parameters.Add(
    100         new LookupParameter<ISymbolicExpressionTree>(
    101           TankProgramParameterName,
    102           "The Robocode tank program to evaluate represented as a " +
    103           "symbolic expression tree."));
    104       Parameters.Add(
    105         new LookupParameter<StringValue>(
    106           RobocodePathParamaterName,
    107           "Path of the Robocode installation."));
    108       Parameters.Add(
    109           new LookupParameter<BoolValue>(
    110               CoevolutionParameterName,
    111               "Use Coevolution"));
    112 
    113       SolutionTemplate = "../tank.xml";
    114     }
    115 
    116     // override the apply method to change the behaviour of the operator
    117     // here we take trees as inputs and calculate qualities
    118     // (fitness evaluation)
    11966    public override IOperation Apply() {
    12067      semaphore.Wait();
    12168
    12269      ISymbolicExpressionTree tree = TankProgramParameter.ActualValue;
    123       //XmlDocument doc = new XmlDocument();
    124       //doc.Load("../tank.xml");
    125       XmlNode node = null;
    12670      string path = RobocodePathParameter.ActualValue.Value;
    127 
    128       if (CoevolutionParameter.ActualValue.Value) {
    129         var trees = ExecutionContext.Parent.Scope.SubScopes;//SymbolicExpressionTreeParameter.ActualValue;
    130         if (trees.Count == 2) {
    131           trees = trees[0].SubScopes;
    132           //treeCount = trees[0].SubScopes.Count;
    133           //int selTreeCount = trees[1].SubScopes.Count;
    134         }
    135 
    136         Random random = new Random();
    137         ScopeList chosenScopes = new ScopeList(5);
    138         for (int i = 0; i < 5; i++) {
    139           var newScope = trees.ToArray()[random.Next(0, trees.Count - 1)];
    140           chosenScopes.Add(newScope);
    141         }
    142 
    143         //if (evaluations % 99 == 0)
    144         //    evaluations = evaluations;
    145 
    146         QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, chosenScopes, node, path));
    147       } else
    148         QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, node, path));
     71      QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path));
    14972
    15073      semaphore.Release();
    15174
    152       // important: return base.Apply() to make sure that the
    153       // next operator is queued for execution
    15475      return base.Apply();
    15576    }
     
    15879      return new RobocodeEvaluator(this, cloner);
    15980    }
    160 
    161     public bool EnabledByDefault {
    162       get { return true; }
    163     }
    16481  }
    16582}
Note: See TracChangeset for help on using the changeset viewer.