Changeset 9880 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/BestSolutionAnalyzer.cs
- Timestamp:
- 08/13/13 12:11:18 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/BestSolutionAnalyzer.cs
r9790 r9880 20 20 #endregion 21 21 22 23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 32 31 namespace HeuristicLab.Problems.Robocode { 33 32 [StorableClass] 34 [Item("Best Tank program Analyzer",33 [Item("Best Tank Program Analyzer", 35 34 "Analyzer that stores the best tank program.")] 36 public class BestSolutionAnalyzer : SingleSuccessorOperator, 37 ISymbolicExpressionTreeAnalyzer { 38 #region parameter names 35 public class BestSolutionAnalyzer : SingleSuccessorOperator, ISymbolicExpressionTreeAnalyzer { 39 36 private const string QualityParameterName = "Quality"; 40 private const string SymbolicExpressionTreeParameterName = 41 "TankProgram"; 42 private const string MovesParameterName = "Moves"; 43 private const string ShotsParameterName = "Shots"; 37 private const string SymbolicExpressionTreeParameterName = "TankProgram"; 44 38 private const string BestSolutionParameterName = "Best solution"; 45 39 private const string ResultsParameterName = "Results"; 46 40 private const string RobocodePathParamaterName = "Path"; 47 private const string CoevolutionParameterName = "Coevolution";48 #endregion49 41 42 public bool EnabledByDefault { 43 get { return true; } 44 } 50 45 51 #region parameters46 #region Parameters 52 47 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 53 get { 54 return (IScopeTreeLookupParameter<DoubleValue>) 55 Parameters[QualityParameterName]; 56 } 48 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters[QualityParameterName]; } 57 49 } 58 50 public IScopeTreeLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 59 get { 60 return (IScopeTreeLookupParameter<ISymbolicExpressionTree>) 61 Parameters[SymbolicExpressionTreeParameterName]; 62 } 51 get { return (IScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 63 52 } 64 //public ILookupParameter<IntValue> MovesParameter65 //{66 // get67 // {68 // return (ILookupParameter<IntValue>)69 // Parameters[MovesParameterName];70 // }71 //}72 //public ILookupParameter<IntValue> ShotsParameter73 //{74 // get75 // {76 // return (ILookupParameter<IntValue>)77 // Parameters[ShotsParameterName];78 // }79 //}80 53 public ILookupParameter<Solution> BestSolutionParameter { 81 get { 82 return (ILookupParameter<Solution>) 83 Parameters[BestSolutionParameterName]; 84 } 54 get { return (ILookupParameter<Solution>)Parameters[BestSolutionParameterName]; } 85 55 } 86 56 public ILookupParameter<ResultCollection> ResultParameter { 87 get { 88 return (ILookupParameter<ResultCollection>) 89 Parameters[ResultsParameterName]; 90 } 57 get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; } 91 58 } 92 59 public ILookupParameter<StringValue> RobocodePathParameter { 93 get { 94 return (ILookupParameter<StringValue>) 95 Parameters[RobocodePathParamaterName]; 96 } 97 } 98 public ILookupParameter<BoolValue> CoevolutionParameter { 99 get { 100 return (ILookupParameter<BoolValue>) 101 Parameters[CoevolutionParameterName]; 102 } 60 get { return (ILookupParameter<StringValue>)Parameters[RobocodePathParamaterName]; } 103 61 } 104 62 #endregion … … 106 64 [StorableConstructor] 107 65 protected BestSolutionAnalyzer(bool deserializing) : base(deserializing) { } 108 protected BestSolutionAnalyzer(BestSolutionAnalyzer original, 109 Cloner cloner) 110 : base(original, cloner) { 111 } 66 protected BestSolutionAnalyzer(BestSolutionAnalyzer original, Cloner cloner) 67 : base(original, cloner) { } 112 68 113 69 public BestSolutionAnalyzer() { 114 Parameters.Add( 115 new ScopeTreeLookupParameter<DoubleValue>( 116 QualityParameterName, 117 "The solution quality of the tank program.")); 118 Parameters.Add( 119 new ScopeTreeLookupParameter<ISymbolicExpressionTree>( 120 SymbolicExpressionTreeParameterName, 121 "The tank program to evaluate represented " + 122 "as symbolic expression tree.")); 123 Parameters.Add( 124 new LookupParameter<Solution>( 125 BestSolutionParameterName, "The best tank program.")); 126 //Parameters.Add( 127 // new LookupParameter<IntValue>( 128 // MovesParameterName, "The number of moves made.")); 129 //Parameters.Add( 130 // new LookupParameter<IntValue>( 131 // ShotsParameterName, "The shots made.")); 132 Parameters.Add( 133 new LookupParameter<ResultCollection>( 134 ResultsParameterName, "The result collection of the algorithm.")); 135 Parameters.Add( 136 new LookupParameter<StringValue>( 137 RobocodePathParamaterName, 138 "Path of the Robocode installation.")); 139 Parameters.Add( 140 new LookupParameter<BoolValue>( 141 CoevolutionParameterName, 142 "Use Coevolution")); 70 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The solution quality of the tank program.")); 71 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The tank program to evaluate represented as symbolic expression tree.")); 72 Parameters.Add(new LookupParameter<Solution>(BestSolutionParameterName, "The best tank program.")); 73 Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection of the algorithm.")); 74 Parameters.Add(new LookupParameter<StringValue>(RobocodePathParamaterName, "Path of the Robocode installation.")); 143 75 } 144 76 … … 159 91 } 160 92 161 var coevolution = CoevolutionParameter.ActualValue.Value;162 double actualQuality = 0;163 164 if (coevolution)165 actualQuality = Interpreter.EvaluateTankProgram(bestTree, null, RobocodePathParameter.ActualValue.Value);166 167 93 // create a solution instance 168 //int shots = ShotsParameter.ActualValue.Value; 169 //int moves = MovesParameter.ActualValue.Value; 170 var bestSolution = new Solution(bestTree, RobocodePathParameter.ActualValue.Value);//, moves, shots); 94 var bestSolution = new Solution(bestTree, RobocodePathParameter.ActualValue.Value); 171 95 // store the new solution in the best solution parameter 172 96 BestSolutionParameter.ActualValue = bestSolution; … … 176 100 var resultCollection = ResultParameter.ActualValue; 177 101 if (!resultCollection.ContainsKey(BestSolutionParameterName)) { 178 resultCollection.Add( 179 new Result(BestSolutionParameterName, 180 "The best tank program", bestSolution)); 181 //if(coevolution) 182 // resultCollection.Add( 183 // new Result("Actual Quality", 184 // "The actual quality of the best program", new DoubleValue(actualQuality))); 102 resultCollection.Add(new Result(BestSolutionParameterName, "The best tank program", bestSolution)); 185 103 } else { 186 104 resultCollection[BestSolutionParameterName].Value = bestSolution; 187 105 } 188 106 189 if (coevolution) {190 if (!resultCollection.ContainsKey("Actual Quality")) {191 resultCollection.Add(192 new Result("Actual Quality",193 "The actual quality of the best program", new DoubleValue(actualQuality)));194 } else {195 resultCollection["Actual Quality"].Value = new DoubleValue(actualQuality);196 }197 }198 199 // important return base.Apply() to make sure the200 // next operator is queued for execution201 107 return base.Apply(); 202 108 } … … 205 111 return new BestSolutionAnalyzer(this, cloner); 206 112 } 207 208 // override this property to indicate that this analyzer209 // should be enabled by default in the algorithm210 public bool EnabledByDefault {211 get { return true; }212 }213 113 } 214 114 }
Note: See TracChangeset
for help on using the changeset viewer.