- Timestamp:
- 03/31/10 14:26:45 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
r3237 r3239 32 32 [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed size")] 33 33 public class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator { 34 private const int MAX_TRIES = 100;35 34 public ProbabilisticTreeCreator() 36 35 : base() { … … 48 47 int treeSize = random.Next(allowedMinSize, allowedMaxSize); 49 48 SymbolicExpressionTree tree = new SymbolicExpressionTree(); 50 int tries = 0;51 49 do { 52 50 try { 53 tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize+1, maxTreeHeight+1); 54 //// determine possible root symbols to create a tree of the target size 55 //var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0) 56 // where treeSize <= grammar.MaximalExpressionLength(symbol) 57 // where treeSize >= grammar.MinimalExpressionLength(symbol) 58 // select symbol; 59 //Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols); 60 //tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight); 51 tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize + 1, maxTreeHeight + 1); 61 52 } 62 53 catch (ArgumentException) { 63 54 // try a different size 64 55 treeSize = random.Next(allowedMinSize, allowedMaxSize); 65 tries = 0;66 }67 if (tries++ >= MAX_TRIES) {68 // try a different size69 treeSize = random.Next(allowedMinSize, allowedMaxSize);70 tries = 0;71 56 } 72 57 } while (tree.Root == null || tree.Size > maxTreeSize || tree.Height > maxTreeHeight); … … 191 176 return tree; 192 177 } 193 194 //private bool IsRecursiveExpansionPossible(Symbol symbol) {195 // return FindCycle(function, new Stack<IFunction>());196 //}197 198 //private Dictionary<IFunction, bool> inCycle = new Dictionary<IFunction, bool>();199 //private bool FindCycle(IFunction function, Stack<IFunction> functionChain) {200 // if (inCycle.ContainsKey(function)) {201 // return inCycle[function];202 // } else if (IsTerminal(function)) {203 // inCycle[function] = false;204 // return false;205 // } else if (functionChain.Contains(function)) {206 // inCycle[function] = true;207 // return true;208 // } else {209 // functionChain.Push(function);210 // bool result = false;211 // // all slot indexes212 // for (int i = 0; i < function.MaxSubTrees; i++) {213 // foreach (IFunction subFunction in GetAllowedSubFunctions(function, i)) {214 // result |= FindCycle(subFunction, functionChain);215 // }216 // }217 218 // functionChain.Pop();219 // inCycle[function] = result;220 // return result;221 // }222 //}223 224 178 } 225 179 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj
r3237 r3239 87 87 <Compile Include="Creators\ProbabilisticTreeCreator.cs" /> 88 88 <Compile Include="HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs" /> 89 <Compile Include="Interfaces\ISymbolicExpressionTreeOperator.cs" /> 89 90 <Compile Include="SymbolicExpressionGrammar.cs" /> 90 91 <Compile Include="SymbolicExpressionTreeCreator.cs" /> -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCreator.cs
r3223 r3239 33 33 [Item("SymbolicExpressionTreeCreator", "A base class for operators creating symbolic expression trees.")] 34 34 [StorableClass] 35 public abstract class SymbolicExpressionTreeCreator : SingleSuccessorOperator, ISolutionCreator, IStochasticOperator {35 public abstract class SymbolicExpressionTreeCreator : SingleSuccessorOperator, ISolutionCreator, IStochasticOperator, ISymbolicExpressionTreeOperator { 36 36 private const string RandomParameterName = "Random"; 37 37 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCrossover.cs
r3237 r3239 35 35 [Item("SymbolicExpressionTreeCrossover", "A base class for operators that perform a crossover of symbolic expression trees.")] 36 36 [StorableClass] 37 public abstract class SymbolicExpressionTreeCrossover : SingleSuccessorOperator, ICrossover, IStochasticOperator {37 public abstract class SymbolicExpressionTreeCrossover : SingleSuccessorOperator, ICrossover, IStochasticOperator, ISymbolicExpressionTreeOperator { 38 38 public override bool CanChangeName { 39 39 get { return false; } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeManipulator.cs
r3223 r3239 33 33 [Item("RealVectorManipulator", "A base class for operators that manipulate real-valued vectors.")] 34 34 [StorableClass] 35 public abstract class RealVectorManipulator : SingleSuccessorOperator, IRealVectorManipulator, IStochasticOperator {35 public abstract class RealVectorManipulator : SingleSuccessorOperator, IRealVectorManipulator, IStochasticOperator, ISymbolicExpressionTreeOperator { 36 36 public override bool CanChangeName { 37 37 get { return false; }
Note: See TracChangeset
for help on using the changeset viewer.