Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/10/17 00:27:31 (8 years ago)
Author:
pkimmesw
Message:

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ManagedPoolProvider.cs

    r14777 r14834  
    55  using System.Collections.Concurrent;
    66  using System.IO;
    7   using System.Linq;
     7  using System.Reflection;
    88  using System.Runtime.Serialization.Formatters.Binary;
    99
     
    1818    private byte[] dummyPartition;
    1919
     20    private static readonly FieldInfo InternalListArrayProperty = typeof(List<T[]>).GetField(
     21      "_items",
     22      BindingFlags.NonPublic | BindingFlags.Instance);
     23
    2024    private readonly Func<T> factory;
    2125
     
    2933      this.factory = factory;
    3034
    31       managedPools = new ObjectPool<IManagedPool<T>>(() => new ManagedPool<T>(this), MaxParitionCount);
     35      managedPools = new ObjectPool<IManagedPool<T>>(() => new ManagedPool(this));
    3236    }
    3337    public int InstanceCount { get { return partitions.Count * PartitionSize; } }
     
    4650    }
    4751
    48     public void ReleasePartitions(params T[][] partition) {
    49       if (partitions.Count <= MaxParitionCount && partition.Length > 0)
    50         partitions.PushRange(partition);
     52    public void ReleasePartitions(List<T[]> releasedPartitions) {
     53      if (partitions.Count < MaxParitionCount)
     54        partitions.PushRange((T[][])InternalListArrayProperty.GetValue(releasedPartitions), 0, releasedPartitions.Count);
    5155    }
    5256
     
    7175    }
    7276
    73     private class ManagedPool<T> : IManagedPool<T> where T : class, IPooledObject {
     77    private class ManagedPool : IManagedPool<T> {
    7478      private readonly ManagedPoolProvider<T> provider;
    75       private readonly IList<T[]> partitions = new List<T[]>();
     79      private readonly List<T[]> partitions = new List<T[]>();
    7680      private T[] currentPartition;
    7781      private int entryIndex;
     
    8286      }
    8387
    84       public T Get(bool reset = true) {
     88      public T Get(bool resetEntry = true) {
    8589        if (entryIndex == provider.PartitionSize) {
    8690          currentPartition = provider.GetPartition();
     
    9094
    9195        var entry = currentPartition[entryIndex++];
    92 
    93         if (reset) entry.Reset();
    94 
     96        if (resetEntry) entry.Reset();
    9597        return entry;
    9698      }
    9799
    98100      public void Dispose() {
    99         provider.ReleasePartitions(partitions.ToArray());
    100         partitions.Clear();
    101         entryIndex = provider.PartitionSize;
     101        if (partitions.Count > 0) {
     102          provider.ReleasePartitions(partitions);
     103          partitions.Clear();
     104          currentPartition = null;
     105          entryIndex = provider.PartitionSize;
     106        }
     107
    102108        provider.managedPools.Free(this);
    103109      }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeExtensions.cs

    r14777 r14834  
    2727    }
    2828
    29     public static IEnumerable<TreeNode<T>> DepthFirst<T>(this TreeNode<T> node) {
     29    public static IEnumerable<TreeNode<T>> DepthLast<T>(this TreeNode<T> node) {
    3030      foreach (var child in node.Children) {
    3131        if (child.Children.Count > 0) {
    32           foreach (var subChild in child.DepthFirst()) {
     32          foreach (var subChild in child.DepthLast()) {
    3333            yield return subChild;
    3434          }
     
    3737    }
    3838
    39     public static IEnumerable<T> DepthFirst<T>(this TreeNode<T> node, Func<IEnumerable<T>, T> resolveParent) {
     39    public static IEnumerable<T> DepthLast<T>(this TreeNode<T> node, Func<IEnumerable<T>, T> resolveParent) {
    4040      foreach (var child in node.Children) {
    4141        if (child.Children.Count > 0) {
    42           var subExpressions = child.DepthFirst(resolveParent);
     42          var subExpressions = child.DepthLast(resolveParent);
    4343          yield return resolveParent(subExpressions);
    4444        } else yield return child.Value;
     
    4747
    4848    public static PushProgram ToPushProgram(this TreeNode<Expression> tree, Func<Expression, bool> condition = null) {
    49       var expressions = tree.DepthFirst(e => ResolveProgram(e, condition));
     49      var expressions = tree.DepthLast(e => ResolveProgram(e, condition));
    5050
    5151      return ResolveProgram(expressions, condition);
Note: See TracChangeset for help on using the changeset viewer.