Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/17 21:36:03 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed small issues, testet benchmark suite, added INX Expressions

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data
Files:
6 edited

Legend:

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

    r14777 r15189  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool {
    22  public interface IPooledObject {
     3    void Init();
    34    void Reset();
    45  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ManagedPoolProvider.cs

    r15017 r15189  
    1010  public interface IManagedPool<T> : IDisposable where T : class, IPooledObject {
    1111    T Get(bool reset = true);
     12    void Release();
    1213  }
    1314
     
    1718    private readonly BinaryFormatter binaryFormatter = new BinaryFormatter();
    1819    private byte[] dummyPartition;
     20    private static volatile object dummyCreationLockObject = new object();
    1921
    2022    private static readonly FieldInfo InternalListArrayProperty = typeof(List<T[]>).GetField(
     
    3739    public int InstanceCount { get { return partitions.Count * PartitionSize; } }
    3840
    39     private void InitDummyPartition(Func<T> factory) {
    40       var temp = new T[PartitionSize];
    41 
    42       for (var i = 0u; i < PartitionSize; i++) {
    43         temp[i] = factory();
    44       }
    45 
    46       using (var memoryStream = new MemoryStream()) {
    47         binaryFormatter.Serialize(memoryStream, temp);
    48         dummyPartition = memoryStream.ToArray();
    49       }
    50     }
    51 
    5241    public void Clear() {
     42      dummyPartition = null;
     43      managedPools.Clear();
    5344      partitions.Clear();
    5445    }
     
    6556
    6657    private T[] CloneDummyPartition() {
    67       if (dummyPartition == null)
    68         InitDummyPartition(factory);
     58      if (dummyPartition == null) {
     59        lock (dummyCreationLockObject) {
     60          if (dummyPartition == null) {
     61            var temp = new T[PartitionSize];
     62
     63            for (var i = 0u; i < PartitionSize; i++) {
     64              temp[i] = factory();
     65            }
     66
     67            using (var memoryStream = new MemoryStream()) {
     68              binaryFormatter.Serialize(memoryStream, temp);
     69              dummyPartition = memoryStream.ToArray();
     70            }
     71          }
     72        }
     73      }
    6974
    7075      using (var memoryStream = new MemoryStream(dummyPartition)) {
    7176        memoryStream.Seek(0, SeekOrigin.Begin);
    7277
    73         return (T[])binaryFormatter.Deserialize(memoryStream);
     78        var result = (T[])binaryFormatter.Deserialize(memoryStream);
     79
     80        for (var i = 0; i < result.Length; i++)
     81          result[i].Init();
     82
     83        return result;
    7484      }
    7585    }
     
    102112      }
    103113
    104       public void Dispose() {
     114      public void Release() {
    105115        if (partitions.Count > 0) {
    106116          provider.ReleasePartitions(partitions);
     
    109119          entryIndex = provider.PartitionSize;
    110120        }
     121      }
     122
     123      public void Dispose() {
     124        Release();
    111125
    112126        provider.managedPools.Free(this);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ObjectPool.cs

    r14777 r15189  
    66
    77namespace HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool {
     8  using System.Collections.Generic;
    89  using System.Threading;
    910
     
    102103      }
    103104    }
     105
     106    public void Clear() {
     107      for (int i = 0; i < _items.Length; i++) {
     108        _items[i] = default(Element);
     109      }
     110    }
     111
     112    public IEnumerable<T> Items
     113    {
     114      get
     115      {
     116        var items = _items;
     117        for (var i = 0; i < items.Length; i++) {
     118          if (items[i].Value != null) {
     119            yield return items[i].Value;
     120          }
     121        }
     122      }
     123    }
    104124  }
    105125}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledList.cs

    r14908 r15189  
    66  [Serializable]
    77  public class PooledList<T> : List<T>, IPooledObject {
    8     public void Reset() {
     8    public Guid Id { get; private set; }
     9
     10    void IPooledObject.Init() {
     11      Id = Guid.NewGuid();
     12    }
     13
     14    void IPooledObject.Reset() {
    915      Clear();
    1016    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledObject.cs

    r14908 r15189  
    2020    }
    2121
     22    void IPooledObject.Init() { }
     23
    2224    public void Reset() {
    2325      resetor(item);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeExtensions.cs

    r15017 r15189  
    8181      }
    8282
    83       return new PushProgram(expressions.ToArray());
     83      return new PushProgram(expressions.ToList());
    8484    }
    8585  }
Note: See TracChangeset for help on using the changeset viewer.