Changeset 2675 for trunk/sources/HeuristicLab.GP/3.3/BaseClasses
- Timestamp:
- 01/22/10 16:12:26 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs
r2222 r2675 27 27 using System.Diagnostics; 28 28 using HeuristicLab.GP.Interfaces; 29 using System.Linq; 29 30 30 31 namespace HeuristicLab.GP { … … 72 73 get { 73 74 if (minTreeSize <= 0) RecalculateMinimalTreeSize(); 75 Debug.Assert(minTreeSize > 0); 74 76 return minTreeSize; 75 77 } … … 79 81 get { 80 82 if (minTreeHeight <= 0) RecalculateMinimalTreeHeight(); 83 Debug.Assert(minTreeHeight > 0); 81 84 return minTreeHeight; 82 85 } … … 130 133 131 134 private void RecalculateMinimalTreeSize() { 132 minTreeSize = int.MaxValue; 133 int sum = 1; 134 int minSize = int.MaxValue; 135 for (int i = 0; i < MinSubTrees; i++) { 136 foreach (IFunction subFun in GetAllowedSubFunctions(i)) { 137 minSize = Math.Min(minSize, subFun.MinTreeSize); 138 } 139 sum += minSize; 140 } 141 minTreeSize = sum; 135 if (MinSubTrees == 0) minTreeSize = 1; 136 else { 137 minTreeSize = int.MaxValue; // prevent infinite recursion 138 minTreeSize = 1 + (from slot in Enumerable.Range(0, MinSubTrees) 139 let minForSlot = (from function in GetAllowedSubFunctions(slot) 140 where function != this 141 select function.MinTreeSize).Min() 142 select minForSlot).Sum(); 143 } 142 144 } 143 145 144 146 private void RecalculateMinimalTreeHeight() { 145 minTreeHeight = int.MaxValue; 146 int height = 0; 147 int minHeight = int.MaxValue; 148 for (int i = 0; i < MinSubTrees; i++) { 149 foreach (IFunction subFun in GetAllowedSubFunctions(i)) { 150 minHeight = Math.Min(minHeight, subFun.MinTreeHeight); 151 } 152 height = Math.Max(height, minHeight); 153 } 154 minTreeHeight = height + 1; 147 if (MinSubTrees == 0) minTreeHeight = 1; 148 else { 149 minTreeHeight = int.MaxValue; 150 minTreeHeight = 1 + (from slot in Enumerable.Range(0, MinSubTrees) 151 let minForSlot = (from function in GetAllowedSubFunctions(slot) 152 where function != this 153 select function.MinTreeHeight).Min() 154 select minForSlot).Max(); 155 } 155 156 } 156 157
Note: See TracChangeset
for help on using the changeset viewer.