Changeset 15017 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data
- Timestamp:
- 06/01/17 09:28:34 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ManagedPoolProvider.cs
r14875 r15017 25 25 26 26 public readonly int PartitionSize; 27 public readonly int MaxPar itionCount;27 public readonly int MaxPartitionCount; 28 28 public const int DefaultMaxInstanceCount = 65536; 29 29 30 30 public ManagedPoolProvider(int partitionSize, Func<T> factory, int? maxPartitionCount = null) { 31 31 PartitionSize = partitionSize; 32 MaxPar itionCount = maxPartitionCount ?? DefaultMaxInstanceCount / PartitionSize;32 MaxPartitionCount = maxPartitionCount ?? DefaultMaxInstanceCount / PartitionSize; 33 33 this.factory = factory; 34 34 … … 50 50 } 51 51 52 public void Clear() { 53 partitions.Clear(); 54 } 55 52 56 public void ReleasePartitions(List<T[]> releasedPartitions) { 53 if (partitions.Count < MaxPar itionCount)57 if (partitions.Count < MaxPartitionCount) 54 58 partitions.PushRange((T[][])InternalListArrayProperty.GetValue(releasedPartitions), 0, releasedPartitions.Count); 55 59 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeExtensions.cs
r14834 r15017 8 8 9 9 public static class TreeExtensions { 10 public static Tree<T> ToTree<T>( 10 private static readonly Expression ExecNoop = ExpressionTable.GetStatelessExpression<ExecNoopExpression>(); 11 private static readonly Expression CodeNoop = ExpressionTable.GetStatelessExpression<CodeNoopExpression>(); 12 13 public static TreeNode<T> ToTree<T>( 11 14 this IEnumerable<T> items, 12 15 Predicate<T> isChild, 13 16 Func<T, IReadOnlyList<T>> childrenResolver) { 14 var tree = new Tree <T>();17 var tree = new TreeNode<T>(); 15 18 16 19 foreach (var item in items) { … … 35 38 } else yield return child; 36 39 } 40 41 yield return node; 37 42 } 38 43 … … 46 51 } 47 52 53 public static PushProgram ToPushProgramWithoutNoopExpressions(this TreeNode<Expression> tree) { 54 return ToPushProgram(tree, e => !ReferenceEquals(e, ExecNoop) && !ReferenceEquals(e, CodeNoop)); 55 } 56 48 57 public static PushProgram ToPushProgram(this TreeNode<Expression> tree, Func<Expression, bool> condition = null) { 58 // wrap into program as depthlast expects that tree represents program and not a single expression 59 if (tree.Count == 1) { 60 var tmp = tree; 61 tree = new TreeNode<Expression>(); 62 tree.AddNode(tmp); 63 } 64 49 65 var expressions = tree.DepthLast(e => ResolveProgram(e, condition)); 50 66 … … 52 68 } 53 69 54 public static Tree <Expression> ToTree(this PushProgram program) {70 public static TreeNode<Expression> ToTree(this PushProgram program) { 55 71 var tree = program.Expressions.ToTree(e => e.IsProgram, e => ((PushProgram)e).Expressions); 56 72 tree.Value = program; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeNode.cs
r14908 r15017 5 5 public T Value { get; set; } 6 6 public IList<TreeNode<T>> Children { get; private set; } 7 public int Count { get; private set; } 7 8 8 9 public TreeNode() { 9 10 Children = new List<TreeNode<T>>(); 11 Count = 1; 10 12 } 11 13 … … 16 18 public void Add(T value) { 17 19 Children.Add(new TreeNode<T>(value)); 20 Count++; 18 21 } 19 22 20 23 public void AddNode(TreeNode<T> node) { 21 24 Children.Add(node); 25 Count += node.Count; 22 26 } 23 27 24 28 public void ReplaceNode(int index, TreeNode<T> node) { 29 Count -= Children[index].Count; 25 30 Children[index] = node; 31 Count += node.Count; 26 32 } 27 33 }
Note: See TracChangeset
for help on using the changeset viewer.