Changeset 5567 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests
- Timestamp:
- 02/28/11 17:11:56 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ChangeNodeTypeManipulationTest.cs
r5549 r5567 53 53 var grammar = Grammars.CreateArithmeticAndAdfGrammar(); 54 54 var random = new MersenneTwister(31415); 55 int failedEvents = 0; 55 56 for (int i = 0; i < POPULATION_SIZE; i++) { 56 57 var tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_LENGTH, MAX_TREE_DEPTH, 3, 3); … … 58 59 ChangeNodeTypeManipulation.ChangeNodeType(random, tree); 59 60 string manipulatedTree = formatter.Format(tree); 60 Assert.IsFalse(originalTree == manipulatedTree);61 if (originalTree == manipulatedTree) failedEvents++; 61 62 Util.IsValid(tree); 62 63 trees.Add(tree); 63 64 } 64 65 Console.WriteLine("ChangeNodeTypeManipulation: " + Environment.NewLine + 66 "Failed events: " + failedEvents * 100.0 / POPULATION_SIZE + " %" + Environment.NewLine + 65 67 Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine + 66 68 Util.GetFunctionDistributionString(trees) + Environment.NewLine + … … 68 70 Util.GetTerminalDistributionString(trees) + Environment.NewLine 69 71 ); 72 Assert.IsTrue(failedEvents * 100.0 / POPULATION_SIZE < 5.0); // only max 5% failed mutations are allowed 70 73 } 71 74 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Grammars.cs
r5549 r5567 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 26 26 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._4.Tests { … … 59 60 public override IDeepCloneable Clone(Cloner cloner) { 60 61 return new Terminal(this, cloner); 62 } 63 64 public override ISymbolicExpressionTreeNode CreateTreeNode() { 65 return new TerminalNode(this); 66 } 67 } 68 69 private class TerminalNode : SymbolicExpressionTreeTerminalNode { 70 public override bool HasLocalParameters { get { return true; } } 71 private double value; 72 protected TerminalNode(TerminalNode original, Cloner cloner) 73 : base(original, cloner) { 74 this.value = original.value; 75 } 76 [StorableConstructor] 77 protected TerminalNode(bool deserializing) : base(deserializing) { } 78 public TerminalNode(Terminal symbol) : base(symbol) { } 79 80 public override IDeepCloneable Clone(Cloner cloner) { 81 return new TerminalNode(this, cloner); 82 } 83 public override void ResetLocalParameters(Core.IRandom random) { 84 base.ResetLocalParameters(random); 85 value = random.NextDouble(); 86 } 87 public override void ShakeLocalParameters(Core.IRandom random, double shakingFactor) { 88 base.ShakeLocalParameters(random, shakingFactor); 89 value = random.NextDouble(); 90 } 91 public override string ToString() { 92 return value.ToString("E4"); 61 93 } 62 94 }
Note: See TracChangeset
for help on using the changeset viewer.