Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/31/10 14:26:45 (14 years ago)
Author:
gkronber
Message:

Extracted view for artificial ant problem into a separate plugin/project. #952 (Artificial Ant Problem for 3.3)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs

    r3237 r3239  
    3232  [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed size")]
    3333  public class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator {
    34     private const int MAX_TRIES = 100;
    3534    public ProbabilisticTreeCreator()
    3635      : base() {
     
    4847      int treeSize = random.Next(allowedMinSize, allowedMaxSize);
    4948      SymbolicExpressionTree tree = new SymbolicExpressionTree();
    50       int tries = 0;
    5149      do {
    5250        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);
    6152        }
    6253        catch (ArgumentException) {
    6354          // try a different size
    6455          treeSize = random.Next(allowedMinSize, allowedMaxSize);
    65           tries = 0;
    66         }
    67         if (tries++ >= MAX_TRIES) {
    68           // try a different size
    69           treeSize = random.Next(allowedMinSize, allowedMaxSize);
    70           tries = 0;
    7156        }
    7257      } while (tree.Root == null || tree.Size > maxTreeSize || tree.Height > maxTreeHeight);
     
    191176      return tree;
    192177    }
    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 indexes
    212     //    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 
    224178  }
    225179}
Note: See TracChangeset for help on using the changeset viewer.