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
Files:
11 added
42 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/HeuristicLab.Problems.ProgramSynthesis.csproj

    r15032 r15189  
    136136    <Compile Include="Push\Data\Tree\TreeExtensions.cs" />
    137137    <Compile Include="Push\Data\Tree\TreeNode.cs" />
    138     <Compile Include="Push\Constants\Environment.cs" />
     138    <Compile Include="Push\Constants\PushEnvironment.cs" />
    139139    <Compile Include="Push\Exporter\Exporter.cs" />
    140140    <Compile Include="Push\Expressions\BooleanExpressions.cs" />
     
    153153    <Compile Include="Push\Expressions\FloatExpressions.cs" />
    154154    <Compile Include="Push\Expressions\FlushExpressions.cs" />
     155    <Compile Include="Push\Expressions\InExpressions.cs" />
    155156    <Compile Include="Push\Expressions\IntegerExpressions.cs" />
    156157    <Compile Include="Push\Expressions\NameExpressions.cs" />
     
    194195    <Compile Include="Push\Extensions\ControlExntensions.cs" />
    195196    <Compile Include="Push\Extensions\EnumExtensions.cs" />
     197    <Compile Include="Push\Extensions\ProblemDataExtensions.cs" />
    196198    <Compile Include="Push\Extensions\LongExtensions.cs" />
    197199    <Compile Include="Push\Extensions\RandomExtensions.cs" />
     200    <Compile Include="Push\Extensions\StringBuilderExtensions.cs" />
    198201    <Compile Include="Push\Generators\CodeGenerator\CodeGeneratorUtils.cs" />
    199202    <Compile Include="Push\Generators\CodeGenerator\LinearCodeGenerator.cs" />
    200203    <Compile Include="Push\Generators\CodeGenerator\RecursiveCodeGenerator.cs" />
     204    <Compile Include="Push\Individual\InduvidualMapper.cs" />
    201205    <Compile Include="Push\Interpreter\Extensions.cs" />
    202206    <Compile Include="Push\Interpreter\IInternalPushInterpreter.cs" />
     
    208212    <Compile Include="Push\Interpreter\PushInterpreter.cs" />
    209213    <Compile Include="Push\Interpreter\PushInterpreterPool.cs" />
     214    <Compile Include="Push\ObjectPools\StringBuilderPool.cs" />
    210215    <Compile Include="Push\Parser\PushParser.cs" />
    211216    <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteSolution.cs" />
    212217    <Compile Include="Push\Problem\DataBounds.cs" />
    213218    <Compile Include="Push\Problem\EvaluationResult.cs" />
    214     <Compile Include="Push\Problem\IndividualMapper.cs" />
     219    <Compile Include="Push\Individual\IndividualExtensions.cs" />
    215220    <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteEvaluator.cs" />
    216221    <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteProblem.cs" />
     
    223228    <Compile Include="Push\Selector\LexicaseSelector.cs" />
    224229    <Compile Include="Push\Simplifier\Simplifier.cs" />
     230    <Compile Include="Push\Stack\IPrintStack.cs" />
    225231    <Compile Include="Push\Stack\IPushStack.cs" />
    226232    <Compile Include="Push\Stack\IPushStackBase.cs" />
     233    <Compile Include="Push\Stack\PrintStack.cs" />
    227234    <Compile Include="Push\Stack\PushStack.cs" />
    228235    <Compile Include="Push\Stack\InterpreterStackStringifier.cs" />
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs

    r15033 r15189  
    1414  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
    1515  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    16   using HeuristicLab.Problems.ProgramSynthesis.Push.Problem;
     16  using HeuristicLab.Problems.ProgramSynthesis.Push.Individual;
    1717
    1818  /// <summary>
     
    3535      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the symbol frequencies should be stored."));
    3636
    37       Parameters.Add(new FixedValueParameter<BoolValue>(AggregateStackTypesParameterName, "Determines if expressions should be aggregated by their primary stack type."));
     37      Parameters.Add(new FixedValueParameter<BoolValue>(AggregateStackTypesParameterName, "Determines if expressions should be aggregated by their primary stack type.", new BoolValue(true)));
    3838    }
    3939
     
    8484      var config = PushConfigurationParameter.ActualValue;
    8585      var integerVectors = IntegerVectorParameter.ActualValue;
    86       var pushPrograms = integerVectors.Select(iv => iv.ToPushProgram(config)).ToArray();
     86      var pushPrograms = integerVectors.Select(iv => iv.ToPushProgram(config));
    8787
    8888      var results = ResultsParameter.ActualValue;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfigurationBase.cs

    r15032 r15189  
    4848      set
    4949      {
    50         var removedExpressions = enabledExpressions.ToArray();
     50        var removedExpressions = enabledExpressions.ToList();
    5151        enabledExpressions.Clear();
    5252        enabledExpressions.AddRange(value);
     
    6868        var attribute = ExpressionTable.TypeToAttributeTable[type];
    6969
    70         expressionsPerStackCount[attribute.StackType]++;
     70        if (expressionsPerStackCount.ContainsKey(attribute.StackType)) {
     71          expressionsPerStackCount[attribute.StackType]++;
     72        }
    7173
    7274        foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues())
     
    150152
    151153      enabledExpressions.Add(expressionName);
    152       expressionsPerStackCount[attribute.StackType]++;
    153       foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues())
     154
     155      if (expressionsPerStackCount.ContainsKey(attribute.StackType))
     156        expressionsPerStackCount[attribute.StackType]++;
     157
     158      foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues().Where(expressionsPerStackCount.ContainsKey))
    154159        expressionsPerStackCount[additionalStackType]++;
    155160
     
    172177
    173178      enabledExpressions.Remove(expressionName);
    174       expressionsPerStackCount[attribute.StackType]--;
    175       foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues())
     179
     180      if (expressionsPerStackCount.ContainsKey(attribute.StackType))
     181        expressionsPerStackCount[attribute.StackType]--;
     182
     183      foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues().Where(expressionsPerStackCount.ContainsKey))
    176184        expressionsPerStackCount[additionalStackType]--;
    177185
  • 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  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CharExpressions.cs

    r15032 r15189  
    151151
    152152    public override void Eval(IInternalPushInterpreter interpreter) {
    153       var chars = interpreter.StringStack.Pop().Reverse().ToArray();
     153      var chars = interpreter.StringStack.Pop().Reverse().ToList();
    154154      interpreter.CharStack.Push(chars);
    155155    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/Expression.cs

    r15017 r15189  
    4343
    4444    public object Clone() {
     45      return Clone(new Cloner());
     46    }
     47
     48    public virtual IDeepCloneable Clone(Cloner cloner) {
    4549      return this;
    4650    }
    4751
    48     public IDeepCloneable Clone(Cloner cloner) {
    49       return this;
    50     }
     52    void IPooledObject.Init() { }
    5153
    5254    void IPooledObject.Reset() { }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs

    r15032 r15189  
    2525
    2626    static ExpressionTable() {
    27       StatelessExpressionTypes = GetExpressionTypes(typeof(StatelessExpression)).ToArray();
    28       StatefulExpressionTypes = GetExpressionTypes(typeof(StatefulExpression<>)).ToArray();
     27      StatelessExpressionTypes = GetExpressionTypes(typeof(StatelessExpression)).ToList();
     28      StatefulExpressionTypes = GetExpressionTypes(typeof(StatefulExpression<>)).ToList();
    2929
    3030      StatelessExpressionTable = GetStatelessExpressionTable();
     
    3535        .Where(t => typeToNameTable.ContainsKey(t))
    3636        .Select(type => typeToNameTable[type])
    37         .ToArray();
     37        .ToList();
    3838
    3939      ExpressionCount = StatelessExpressionTable.Count + StatefulExpressionFactory.Count;
     
    5757        dictionary.Add(type, expression);
    5858
    59         // do not index hidden expressions like push expression in tables
    60         if (attribute.IsHidden) continue;
     59        //// do not index hidden expressions like push expression in tables
     60        //if (attribute.IsHidden) continue;
    6161
    6262        indexToNameTable.Add(indexToNameTable.Keys.Count, attribute.Name);
     
    156156          .Where(entry => (entry.Key & ~allowedTypes) == 0x0)
    157157          .SelectMany(entry => entry.Value)
    158           .ToArray();
     158          .ToList();
    159159    }
    160160
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PrintExpressions.cs

    r15032 r15189  
    22  using System.Collections.Generic;
    33  using System.Globalization;
    4   using System.Text;
    54  using Attributes;
    65  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    76  using HeuristicLab.Problems.ProgramSynthesis.Push.Constants;
     7
    88  using Interpreter;
    99  using Stack;
     
    2121
    2222    public override void Eval(IInternalPushInterpreter interpreter) {
    23       interpreter.PrintStack.Push(string.Empty);
     23      interpreter.PrintStack.NewLine();
    2424    }
    2525  }
     
    2828  public abstract class PrintExpression<T> : StatelessExpression {
    2929    protected PrintExpression() { }
     30
    3031    [StorableConstructor]
    3132    protected PrintExpression(bool deserializing) : base(deserializing) { }
    3233
    3334    protected void Eval(IInternalPushInterpreter interpreter, IPushStack<T> stack) {
    34       var value = stack.Pop().ToString();
    35 
    36       if (interpreter.PrintStack.IsEmpty)
    37         interpreter.PrintStack.Push(value);
    38       else
    39         interpreter.PrintStack.Top += value;
     35      var value = stack.Pop();
     36
     37      interpreter.PrintStack.Push(value);
    4038    }
    4139
    4240    protected void EvalVector(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) {
    43       var sb = new StringBuilder();
    4441      var vector = vectorStack.Pop();
    4542
    46       sb.Append(PushEnvironment.VectorStartSymbol);
     43      interpreter.PrintStack.Push(PushEnvironment.VectorStartSymbol);
    4744
    4845      if (vector.Count > 0) {
    49         sb.Append(vector[0]);
     46        interpreter.PrintStack.Push(vector[0]);
    5047
    5148        for (var i = 1; i < vector.Count; i++) {
    52           sb.Append(PushEnvironment.VectorSeparatorSymbol);
    53           sb.Append(vector[i]);
     49          interpreter.PrintStack.Push(PushEnvironment.VectorSeparatorSymbol);
     50          interpreter.PrintStack.Push(vector[i]);
    5451        }
    5552      }
    5653
    57       sb.Append(PushEnvironment.VectorEndSymbol);
    58 
    59       var value = sb.ToString();
    60       interpreter.PrintStack.Push(value);
     54      interpreter.PrintStack.Push(PushEnvironment.VectorEndSymbol);
    6155    }
    6256  }
     
    165159
    166160    public override void Eval(IInternalPushInterpreter interpreter) {
    167       Eval(interpreter, interpreter.IntegerStack);
     161      var value = interpreter.IntegerStack.Pop();
     162      interpreter.PrintStack.Push(value);
    168163    }
    169164  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PushProgram.cs

    r15017 r15189  
    88  using Data.Pool;
    99  using Extensions;
     10
     11  using HeuristicLab.Common;
     12
    1013  using Interpreter;
    1114  using Persistence.Default.CompositeSerializers.Storable;
     
    4144    }
    4245
     46    public PushProgram(PushProgram origin, Cloner cloner) {
     47      stringRepresentation = origin.stringRepresentation;
     48      hashCode = origin.hashCode;
     49      depth = origin.depth;
     50      treeIndex = origin.treeIndex;
     51      expressions = new List<Expression>(origin.expressions);
     52    }
     53
     54    public override IDeepCloneable Clone(Cloner cloner) {
     55      return new PushProgram(this, cloner);
     56    }
     57
    4358    public bool IsEmpty { get { return Count == 0; } }
    4459    public int Count { get { return expressions.Count; } }
     
    5166      return program;
    5267    }
     68
     69    void IPooledObject.Init() { }
    5370
    5471    void IPooledObject.Reset() {
     
    263280            yield return sub;
    264281        else yield return expr;
     282      }
     283    }
     284
     285    public IReadOnlyList<Expression> Flatten() {
     286      var result = new List<Expression>();
     287      Flatten(result);
     288      return result;
     289    }
     290
     291    private void Flatten(List<Expression> result) {
     292      result.AddRange(expressions);
     293
     294      for (var i = 0; i < expressions.Count; i++) {
     295        var expr = expressions[i];
     296        if (expr.IsProgram) {
     297          ((PushProgram)expr).Flatten(result);
     298        }
    265299      }
    266300    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StatefulExpression.cs

    r15017 r15189  
    6969    }
    7070
     71    void IPooledObject.Init() { }
     72
    7173    public void Reset() {
    7274      State = default(T);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs

    r15032 r15189  
    453453        .Where(x => !string.IsNullOrWhiteSpace(x))
    454454        .Reverse()
    455         .ToArray();
    456 
    457       if (words.Length == 0) {
     455        .ToList();
     456
     457      if (words.Count == 0) {
    458458        interpreter.StringStack.Pop();
    459459      } else {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorButLastExpressions.cs

    r15032 r15189  
    2525      vectorStack.Top = vectorStack.Top
    2626        .Take(vectorStack.Top.Count - 1)
    27         .ToArray();
     27        .ToList();
    2828    }
    2929  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorIterateExpressions.cs

    r15032 r15189  
    5656        }
    5757
    58         vectorStack.Top = vector.Take(last).ToArray();
     58        vectorStack.Top = vector.Take(last).ToList();
    5959      }
    6060    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorPushAllExpressions.cs

    r15032 r15189  
    2323
    2424    protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) {
    25       var vector = vectorStack.Pop().Reverse().ToArray();
     25      var vector = vectorStack.Pop().Reverse().ToList();
    2626      literalStack.Push(vector);
    2727    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRemoveExpressions.cs

    r15032 r15189  
    2525    protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) {
    2626      var literal = literalStack.Pop();
    27       vectorStack.Top = vectorStack.Top.Where(x => !x.Equals(literal)).ToArray();
     27      vectorStack.Top = vectorStack.Top.Where(x => !x.Equals(literal)).ToList();
    2828    }
    2929  }
     
    9292  [PushExpression(
    9393    StackTypes.StringVector,
     94    "STRING[].REMOVE",
    9495    "Removes all occurrences of the top STRING in the top STRING[].",
    95     "STRING[].REMOVE",
    9696    StackTypes.String)]
    9797  public class StringVectorRemoveExpression : VectorRemoveExpression<string> {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRestExpressions.cs

    r15032 r15189  
    4242      }
    4343
    44       vectorStack.Top = vector.Skip(1).ToArray();
     44      vectorStack.Top = vector.Skip(1).ToList();
    4545    }
    4646  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorReverseExpressions.cs

    r15032 r15189  
    2525
    2626    protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack) {
    27       vectorStack.Top = vectorStack.Top.Reverse().ToArray();
     27      vectorStack.Top = vectorStack.Top.Reverse().ToList();
    2828    }
    2929  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorSubExpressions.cs

    r15032 r15189  
    5151      }
    5252
    53       vectorStack.Top = vector.Skip(first).Take(lenght).ToArray();
     53      vectorStack.Top = vector.Skip(first).Take(lenght).ToList();
    5454    }
    5555  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorTakeExpressions.cs

    r15032 r15189  
    5353      }
    5454
    55       vectorStack.Top = vector.Take(count).ToArray();
     55      vectorStack.Top = vector.Take(count).ToList();
    5656    }
    5757  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/CodeGeneratorUtils.cs

    r15017 r15189  
    3838      IRandom random,
    3939      IReadOnlyErcOptions ercOptions) {
    40       var x = random.NextDouble();
    41       Expression expression = null;
     40      //var x = random.NextDouble();
     41      //Expression expression = null;
    4242
    43       if (x < ercOptions.ErcProbability) {
    44         var expressionType = ExpressionTable.NameToTypeTable[expressionName];
    45         expression = CreateRandomErcExpression(
    46             ExpressionTable.TypeToAttributeTable[expressionType].StackType,
    47             random,
    48             ercOptions);
    49       }
     43      //if (x < ercOptions.ErcProbability) {
     44      //  var expressionType = ExpressionTable.NameToTypeTable[expressionName];
     45      //  expression = CreateRandomErcExpression(
     46      //      ExpressionTable.TypeToAttributeTable[expressionType].StackType,
     47      //      random,
     48      //      ercOptions);
     49      //}
    5050
    51       if (expression == null || expression is ExecNoopExpression) {
    52         expression = ExpressionTable.GetExpression(expressionName);
    53       }
     51      //if (expression == null || expression is ExecNoopExpression) {
     52      //  expression = ExpressionTable.GetExpression(expressionName);
     53      //}
     54
     55      //return expression;
     56
     57      var expression = ExpressionTable.GetExpression(expressionName);
    5458
    5559      return expression;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/RecursiveCodeGenerator.cs

    r14834 r15189  
    2323      var code = RandomCode(maxPoints, random, pushGpConfiguration, customExpressions);
    2424
    25       return PushProgram.Create(pool, code.ToArray());
     25      return PushProgram.Create(pool, code.ToList());
    2626    }
    2727
     
    2929      var code = RandomCode(maxPoints, random, pushGpConfiguration, customExpressions);
    3030
    31       return new PushProgram(code.ToArray());
     31      return new PushProgram(code.ToList());
    3232    }
    3333
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/Extensions.cs

    r15017 r15189  
    2525
    2626    public static Type GetStackEntryType(this StackTypes stackType) {
     27      if (StackProperties.ContainsKey(stackType) &&
     28          StackProperties[stackType].PropertyType.IsGenericType) {
     29        var genericTypeDef = StackProperties[stackType].PropertyType.GetGenericTypeDefinition();
     30        if (genericTypeDef == typeof(IPushStack<>))
     31          return genericTypeDef.GetGenericArguments()[0];
     32      }
     33
    2734      return StackProperties.ContainsKey(stackType)
    28         ? StackProperties[stackType].PropertyType.GetGenericArguments().Single()
     35        ? StackProperties[stackType]
     36            .PropertyType
     37            .GetInterfaces()
     38            .First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPushStack<>))
     39            .GetGenericArguments()
     40            .First()
    2941        : null;
    3042    }
    3143
    3244    public static void PrintStacks(this IPushInterpreter interpreter) {
    33       var stackTypesType = typeof(StackTypes);
    34 
    35       foreach (StackTypes type in Enum.GetValues(stackTypesType)) {
    36         if (!interpreter.Stacks.ContainsKey(type)) continue;
    37 
    38         var stackName = Enum.GetName(stackTypesType, type);
    39         var stack = interpreter.Stacks[type];
     45      foreach (var pair in interpreter.Stacks) {
     46        var stackName = pair.Key.ToString();
     47        var stack = interpreter.Stacks[pair.Key];
    4048
    4149        if (stack.IsEmpty || !stack.IsEnabled) continue;
    4250
    43         var stackString = string.Join(" ", interpreter.StringifyStack(type).Reverse());
     51        var stackString = string.Join(" ", interpreter.StringifyStack(pair.Key).Reverse());
    4452        Console.WriteLine("--------- {0} ---------\n{1}\n", stackName, stackString);
    4553      }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IInternalPushInterpreter.cs

    r14834 r15189  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter {
     2  using System.Collections.Generic;
     3
     4  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
     5
    26  public interface IInternalPushInterpreter : IPushInterpreter {
    37    InterpreterPoolContainer PoolContainer { get; }
    48    bool IsNameQuoteFlagSet { get; set; }
     9    IReadOnlyList<Expression> InputExpressions { get; }
    510  }
    611}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs

    r15017 r15189  
    2424    IPushStack<IReadOnlyList<bool>> BooleanVectorStack { get; }
    2525    IPushStack<IReadOnlyList<string>> StringVectorStack { get; }
    26     IPushStack<string> PrintStack { get; }
     26    IPrintStack PrintStack { get; }
    2727    IDictionary<string, Expression> CustomExpressions { get; }
    2828    IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; }
     
    3030    void Clear();
    3131    void Reset();
     32
     33    void SetInput(
     34      IReadOnlyList<long> integers = null,
     35      IReadOnlyList<double> floats = null,
     36      IReadOnlyList<bool> booleans = null,
     37      IReadOnlyList<char> chars = null,
     38      IReadOnlyList<string> strings = null,
     39      IReadOnlyList<IReadOnlyList<long>> integerVectors = null,
     40      IReadOnlyList<IReadOnlyList<double>> floatVectors = null,
     41      IReadOnlyList<IReadOnlyList<string>> stringVectors = null);
    3242
    3343    void Run(bool stepwise);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs

    r15032 r15189  
    22  using System;
    33  using System.Collections.Generic;
     4  using System.Linq;
    45  using System.Runtime.CompilerServices;
    56  using System.Threading;
     
    3536      BooleanVectorStack = new PushStack<IReadOnlyList<bool>>();
    3637      StringVectorStack = new PushStack<IReadOnlyList<string>>();
    37       PrintStack = new PushStack<string>();
     38      PrintStack = new PrintStack();
    3839
    3940      Stacks = new Dictionary<StackTypes, IPushStack> {
     
    5354      };
    5455
     56      supportedStackTypes = Stacks.Keys.ToArray();
     57
    5558      CustomExpressions = new Dictionary<string, Expression>();
    5659      PoolContainer = poolContainer ?? new InterpreterPoolContainer();
     
    6366    }
    6467
     68    private readonly StackTypes[] supportedStackTypes;
    6569    public IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; private set; }
    6670
     
    128132    public IPushStack<IReadOnlyList<string>> StringVectorStack { get; private set; }
    129133    [PushStack(StackTypes.Print)]
    130     public IPushStack<string> PrintStack { get; private set; }
     134    public IPrintStack PrintStack { get; private set; }
    131135
    132136    public IDictionary<string, Expression> CustomExpressions { get; private set; }
    133137
    134138    public bool IsNameQuoteFlagSet { get; set; }
     139
     140    private readonly List<Expression> inputExpressions = new List<Expression>();
     141    IReadOnlyList<Expression> IInternalPushInterpreter.InputExpressions { get { return inputExpressions; } }
     142
     143    public void SetInput(
     144      IReadOnlyList<long> integers = null,
     145      IReadOnlyList<double> floats = null,
     146      IReadOnlyList<bool> booleans = null,
     147      IReadOnlyList<char> chars = null,
     148      IReadOnlyList<string> strings = null,
     149      IReadOnlyList<IReadOnlyList<long>> integerVectors = null,
     150      IReadOnlyList<IReadOnlyList<double>> floatVectors = null,
     151      IReadOnlyList<IReadOnlyList<string>> stringVectors = null) {
     152
     153      // Integer
     154      if (integers != null && integers.Count > 0) {
     155        var integerPushExpressionPool = PoolContainer.GetStatefulExpressionPool<IntegerPushExpression>();
     156
     157        for (var i = 0; i < integers.Count; i++) {
     158          var expression = IntegerPushExpression.Create(integerPushExpressionPool, integers[i]);
     159          inputExpressions.Add(expression);
     160        }
     161      }
     162
     163      // Float
     164      if (floats != null && floats.Count > 0) {
     165        var floatPushExpressionPool = PoolContainer.GetStatefulExpressionPool<FloatPushExpression>();
     166
     167        for (var i = 0; i < floats.Count; i++) {
     168          var expression = FloatPushExpression.Create(floatPushExpressionPool, floats[i]);
     169          inputExpressions.Add(expression);
     170        }
     171      }
     172
     173      // Booleans
     174      if (booleans != null && booleans.Count > 0) {
     175        var booleanPushExpressionPool = PoolContainer.GetStatefulExpressionPool<BooleanPushExpression>();
     176
     177        for (var i = 0; i < booleans.Count; i++) {
     178          var expression = BooleanPushExpression.Create(booleanPushExpressionPool, booleans[i]);
     179          inputExpressions.Add(expression);
     180        }
     181      }
     182
     183      // Char
     184      if (chars != null && chars.Count > 0) {
     185        var charPushExpressionPool = PoolContainer.GetStatefulExpressionPool<CharPushExpression>();
     186
     187        for (var i = 0; i < chars.Count; i++) {
     188          var expression = CharPushExpression.Create(charPushExpressionPool, chars[i]);
     189          inputExpressions.Add(expression);
     190        }
     191      }
     192
     193      // String
     194      if (strings != null && strings.Count > 0) {
     195        var stringPushExpressionPool = PoolContainer.GetStatefulExpressionPool<StringPushExpression>();
     196
     197        for (var i = 0; i < strings.Count; i++) {
     198          var expression = StringPushExpression.Create(stringPushExpressionPool, strings[i]);
     199          inputExpressions.Add(expression);
     200        }
     201      }
     202
     203      // IntegerVector
     204      if (integerVectors != null && integerVectors.Count > 0) {
     205        var integerVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<IntegerVectorPushExpression>();
     206
     207        for (var i = 0; i < integerVectors.Count; i++) {
     208          var expression = IntegerVectorPushExpression.Create(integerVectorPushExpressionPool, integerVectors[i]);
     209          inputExpressions.Add(expression);
     210        }
     211      }
     212
     213      // FloatVector
     214      if (floatVectors != null && floatVectors.Count > 0) {
     215        var floatVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<FloatVectorPushExpression>();
     216
     217        for (var i = 0; i < floatVectors.Count; i++) {
     218          var expression = FloatVectorPushExpression.Create(floatVectorPushExpressionPool, floatVectors[i]);
     219          inputExpressions.Add(expression);
     220        }
     221      }
     222
     223      // StringVector
     224      if (stringVectors != null && stringVectors.Count > 0) {
     225        var stringVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<StringVectorPushExpression>();
     226
     227        for (var i = 0; i < stringVectors.Count; i++) {
     228          var expression = StringVectorPushExpression.Create(stringVectorPushExpressionPool, stringVectors[i]);
     229          inputExpressions.Add(expression);
     230        }
     231      }
     232    }
     233
    135234
    136235    public Task RunAsync(string code, CancellationToken token = default(CancellationToken)) {
     
    240339      currentProgram = null;
    241340
     341      inputExpressions.Clear();
    242342      Clear();
    243343      ConfigureStacks();
     
    245345
    246346    private void ConfigureStacks() {
    247       foreach (var pair in this.Stacks) {
    248         pair.Value.IsEnabled = Configuration.IsStackEnabled(pair.Key);
     347      for (var i = 0u; i < supportedStackTypes.Length; i++) {
     348        var key = supportedStackTypes[i];
     349        Stacks[key].IsEnabled = Configuration.IsStackEnabled(key);
    249350      }
    250351
     
    257358    /// </summary>
    258359    public void Clear() {
    259       foreach (var stack in Stacks)
    260         stack.Value.Clear();
     360      for (var i = 0u; i < supportedStackTypes.Length; i++) {
     361        var key = supportedStackTypes[i];
     362        Stacks[key].Clear();
     363      }
    261364
    262365      CustomExpressions.Clear();
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs

    r15032 r15189  
    4747      PushProgramPoolProvider.Clear();
    4848      ExpressionListPoolProvider.Clear();
     49      pool.Clear();
    4950    }
    5051  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Parser/PushParser.cs

    r15017 r15189  
    175175          .Substring(1, word.Length - 2)
    176176          .Split(PushEnvironment.VectorSeparatorSymbol)
    177           .ToArray();
    178 
    179         if (vectorEntries.Length == 0) {
     177          .ToList();
     178
     179        if (vectorEntries.Count == 0) {
    180180          expression = null;
    181181          return false;
     
    190190
    191191        if (e.GetType() == typeof(IntegerPushExpression)) {
    192           var integerValues = vectorEntries.Select(long.Parse).ToArray();
     192          var integerValues = vectorEntries.Select(long.Parse).ToList();
    193193          expression = new IntegerVectorPushExpression(integerValues);
    194194        } else if (e.GetType() == typeof(FloatPushExpression)) {
    195           var doubleValues = vectorEntries.Select(x => double.Parse(x, NumberStyles.Float, cultureInfo)).ToArray();
     195          var doubleValues = vectorEntries.Select(x => double.Parse(x, NumberStyles.Float, cultureInfo)).ToList();
    196196          expression = new FloatVectorPushExpression(doubleValues);
    197197        } else if (e.GetType() == typeof(StringPushExpression)) {
    198           var stringValues = vectorEntries.Select(str => str.Substring(1, str.Length - 2)).ToArray();
     198          var stringValues = vectorEntries.Select(str => str.Substring(1, str.Length - 2)).ToList();
    199199          expression = new StringVectorPushExpression(stringValues);
    200200        } else if (e.GetType() == typeof(BooleanPushExpression)) {
    201           var booleanValues = vectorEntries.Select(bool.Parse).ToArray();
     201          var booleanValues = vectorEntries.Select(bool.Parse).ToList();
    202202          expression = new BooleanVectorPushExpression(booleanValues);
    203203        } else {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/BenchmarkSuitePushSolutionView.cs

    r15032 r15189  
    5353      var example = Evaluator.Data.Examples[exampleComboBox.SelectedIndex];
    5454
    55       interpreter.BooleanStack.Push(example.InputBoolean);
    56       interpreter.IntegerStack.Push(example.InputInteger);
    57       interpreter.FloatStack.Push(example.InputFloat);
    58       interpreter.CharStack.Push(example.InputChar);
    59       interpreter.StringStack.Push(example.InputString);
    60       interpreter.IntegerVectorStack.Push(example.InputIntegerVector.Select(x => x.ToList()).ToArray());
    61       interpreter.FloatVectorStack.Push(example.InputFloatVector.Select(x => x.ToList()).ToArray());
    62       interpreter.StringVectorStack.Push(example.InputStringVector.Select(x => x.ToList()).ToArray());
    63       interpreter.BooleanVectorStack.Push(example.InputBooleanVector.Select(x => x.ToList()).ToArray());
     55      interpreter.SetInput(
     56        integers: example.InputInteger,
     57        floats: example.InputFloat,
     58        booleans: example.InputBoolean,
     59        chars: example.InputChar,
     60        strings: example.InputString,
     61        integerVectors: example.InputIntegerVector,
     62        floatVectors: example.InputFloatVector,
     63        stringVectors: example.InputStringVector);
     64
     65      //interpreter.BooleanStack.Push(example.InputBoolean);
     66      //interpreter.IntegerStack.Push(example.InputInteger);
     67      //interpreter.FloatStack.Push(example.InputFloat);
     68      //interpreter.CharStack.Push(example.InputChar);
     69      //interpreter.StringStack.Push(example.InputString);
     70      //interpreter.IntegerVectorStack.Push(example.InputIntegerVector.Select(x => x.ToList()).ToList());
     71      //interpreter.FloatVectorStack.Push(example.InputFloatVector.Select(x => x.ToList()).ToList());
     72      //interpreter.StringVectorStack.Push(example.InputStringVector.Select(x => x.ToList()).ToList());
     73      //interpreter.BooleanVectorStack.Push(example.InputBooleanVector.Select(x => x.ToList()).ToList());
    6474    }
    6575
     
    198208            var type = data.OutputArgumentTypes[j];
    199209            var offset = outputArgumentCountDict[type];
     210
     211            // estimated
    200212            row.Cells[data.InputArgumentTypes.Length + j * 2].Value = ViewHelper.StringifyOutput(type, offset, Content.Config.FloatStringFormat, example, Separator);
     213
     214            // output
    201215            row.Cells[data.InputArgumentTypes.Length + j * 2 + 1].Value = StringifyResult(type, offset, pushInterpreter, example, Separator);
     216
    202217            outputArgumentCountDict[type]++;
    203218          }
     
    243258
    244259        case ExampleArgumentType.Print:
    245           return string.Join(valueSeparator, string.Join(PushEnvironment.NewLine, interpreter.PrintStack.Take(example.OutputPrintLineCount)));
     260          return string.Join(valueSeparator, string.Join(PushEnvironment.NewLine, interpreter.PrintStack.AsStrings().Take(example.OutputPrintLineCount)));
    246261
    247262        case ExampleArgumentType.String:
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteEvaluator.cs

    r15017 r15189  
    22  using System;
    33  using System.Collections.Generic;
     4  using System.Globalization;
    45  using System.Linq;
    56
     
    130131      var example = Data.Examples[exampleIndex];
    131132
    132       interpreter.BooleanStack.Push(example.InputBoolean);
    133       interpreter.IntegerStack.Push(example.InputInteger);
    134       interpreter.FloatStack.Push(example.InputFloat);
    135       interpreter.CharStack.Push(example.InputChar);
    136       interpreter.StringStack.Push(example.InputString);
    137       interpreter.StringVectorStack.Push(example.InputStringVector);
    138       interpreter.IntegerVectorStack.Push(example.InputIntegerVector);
    139       interpreter.FloatVectorStack.Push(example.InputFloatVector);
     133      //interpreter.BooleanStack.Push(example.InputBoolean);
     134      //interpreter.IntegerStack.Push(example.InputInteger);
     135      //interpreter.FloatStack.Push(example.InputFloat);
     136      //interpreter.CharStack.Push(example.InputChar);
     137      //interpreter.StringStack.Push(example.InputString);
     138      //interpreter.StringVectorStack.Push(example.InputStringVector);
     139      //interpreter.IntegerVectorStack.Push(example.InputIntegerVector);
     140      //interpreter.FloatVectorStack.Push(example.InputFloatVector);
     141
     142      interpreter.SetInput(
     143        integers: example.InputInteger,
     144        floats: example.InputFloat,
     145        booleans: example.InputBoolean,
     146        chars: example.InputChar,
     147        strings: example.InputString,
     148        integerVectors: example.InputIntegerVector,
     149        floatVectors: example.InputFloatVector,
     150        stringVectors: example.InputStringVector);
    140151
    141152      interpreter.Run(program);
    142153
    143154      switch (Data.ProblemType) {
    144         //case ProblemType.NumberIO:
    145         //  if (interpreter.PrintStack.IsEmpty)
    146         //    return Data.WorstResult;
    147 
    148         //  double value;
    149         //  var levenshteinDistance = GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult);
    150         //  return levenshteinDistance + (double.TryParse(interpreter.PrintStack.Top, out value)
    151         //    ? FloatDiffer(value, example.OutputFloat[0], example.OutputFloatPrecision)
    152         //    : Data.WorstResult / 2);
    153 
    154         case ProblemType.Median: return interpreter.PrintStack.IsEmpty ? 1 : interpreter.PrintStack.Top.Equals(example.OutputPrint) ? 0 : 1;
    155       }
    156 
     155        case ProblemType.NumberIO: return NumberIo(interpreter, example);
     156        case ProblemType.Median: return Median(interpreter, example);
     157      }
     158
     159      return Default(interpreter, example);
     160    }
     161
     162    private double Default(IPushInterpreter interpreter, Example example) {
    157163      var result = GetDiff(example.OutputInteger, interpreter.IntegerStack, Data.WorstResult, IntegerDiffer)
    158                  + GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision))
    159                  + GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer)
    160                  + GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer)
    161                  + GetDiff(example.OutputChar, interpreter.CharStack, Data.WorstResult, CharDiffer)
    162                  + GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult)
    163                  + GetVectorDiff(example.OutputIntegerVector, interpreter.IntegerVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, IntegerDiffer))
    164                  + GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision)))
    165                  + GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer));
     164             + GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision))
     165             + GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer)
     166             + GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer)
     167             + GetDiff(example.OutputChar, interpreter.CharStack, Data.WorstResult, CharDiffer)
     168             + GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult)
     169             + GetVectorDiff(example.OutputIntegerVector, interpreter.IntegerVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, IntegerDiffer))
     170             + GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision)))
     171             + GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer));
    166172
    167173      return result;
     174    }
     175
     176    private double Median(IPushInterpreter interpreter, Example example) {
     177      return interpreter.PrintStack.IsEmpty || !interpreter.PrintStack.Top.Equals(example.OutputPrint) ? 1 : 0;
     178    }
     179
     180    private double NumberIo(IPushInterpreter interpreter, Example example) {
     181      if (interpreter.PrintStack.IsEmpty)
     182        return Data.WorstResult;
     183
     184      double value;
     185      if (double.TryParse(interpreter.PrintStack.Top, NumberStyles.Number | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value)) {
     186        var diff = Math.Abs(example.OutputFloat[0] - value);
     187        var result = Math.Min(diff, Data.WorstResult);
     188
     189        return result;
     190      }
     191
     192      var penaltyError = Data.WorstResult / 4.0d;
     193      var levenshteinDistance = GetPrintDiffer(
     194        example.OutputPrint,
     195        interpreter.PrintStack.Top,
     196        Data.WorstResult);
     197
     198      return levenshteinDistance + penaltyError;
    168199    }
    169200
     
    217248    }
    218249
     250    private static double GetPrintDiffer(string estimated, string printResult, double worstResult) {
     251      var distance = LevenshteinDistance(estimated, printResult);
     252
     253      return Math.Min(distance, worstResult);
     254    }
     255
    219256    private static double GetPrintDiffer(string estimated, IPushStack<string> printStack, int estimatedCount, double worstResult) {
    220       var printResult = string.Join(PushEnvironment.NewLine, printStack.Take(estimatedCount));
     257      var printResult = string.Join(PushEnvironment.NewLine, printStack.AsStrings().Take(estimatedCount));
    221258      var distance = LevenshteinDistance(estimated, printResult);
    222259
     
    234271        var count = Math.Min(estimated.Count, resultStack.Count);
    235272        var result = resultStack.Peek(count);
    236         comparableLength = Math.Min(estimated.Count, result.Length);
     273        comparableLength = Math.Min(estimated.Count, result.Count);
    237274
    238275        for (var i = 0; i < comparableLength; i++) {
     
    259296        var count = Math.Min(estimated.Count, resultStack.Count);
    260297        var result = resultStack.Peek(count);
    261         comparableLength = Math.Min(estimated.Count, result.Length);
     298        comparableLength = Math.Min(estimated.Count, result.Count);
    262299
    263300        for (var i = 0; i < comparableLength; i++) {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteProblem.cs

    r15032 r15189  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite {
     2
    23  using Common;
    34  using Configuration;
     
    78  using HeuristicLab.BenchmarkSuite.Problems;
    89  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
     10  using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions;
    911
    1012  using Instances;
     
    5355
    5456      config.SetEnabledStacks((StackTypes)data.EnabledDataTypes);
     57      data.InitInExpressions(config);
    5558
    5659      Encoding.Bounds[0, 0] = 0;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs

    r15032 r15189  
    1212  using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer;
    1313  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
     14  using HeuristicLab.Problems.ProgramSynthesis.Push.Individual;
    1415  using HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite;
    1516
     
    125126      // clear pools and free reserved memory
    126127      pool.Clear();
     128      IndividualMapper.Clear();
    127129    }
    128130
     
    158160
    159161    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     162      IndividualMapper.Reset();
     163
    160164      var bestQuality = Maximization ? qualities.Max() : qualities.Min();
    161165      var bestIdx = Array.IndexOf(qualities, bestQuality);
     
    165169      rand.Reset(seed);
    166170
    167       var program = vector.ToPushProgram(config, rand);
     171      var program = (PushProgram)vector.ToPushProgram(config, rand).Clone();
    168172      var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, rand);
    169173
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs

    r14908 r15189  
    7474      for (var k = 0; k < repeats; k++) {
    7575        // The fitness cases are shuffled.
    76         var fitnessCaseIndexes = Enumerable.Range(0, caseCount).Shuffle(random).ToArray();
     76        var fitnessCaseIndexes = Enumerable.Range(0, caseCount).Shuffle(random).ToList();
    7777
    7878        // copy list if required
     
    8383          var bestIndividuals = pool;
    8484
    85           for (var j = 0; j < fitnessCaseIndexes.Length && bestIndividuals.Count > 1; j++)
     85          for (var j = 0; j < fitnessCaseIndexes.Count && bestIndividuals.Count > 1; j++)
    8686            bestIndividuals = GetBestIndividuals(maximization, caseQualities, bestIndividuals, fitnessCaseIndexes[j]);
    8787
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStack.cs

    r15017 r15189  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Stack {
    2   using System;
    32  using System.Collections.Generic;
    43
     
    1817    void Push(IEnumerable<T> items);
    1918    new void Clear();
    20     T Peek();
    21     T[] Peek(int count);
    22     void PushResult(int count, Func<T[], T> templateFunc);
     19    IReadOnlyList<T> Peek(int count);
    2320    void Insert(int index, T item);
    24     T ReverseElementAt(int offset);
    2521    T Pop();
    26     T[] Pop(int count);
     22    IReadOnlyList<T> Pop(int count);
    2723    bool TryPop(out T item);
    2824    T ElementAt(int index);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/InterpreterStackStringifier.cs

    r15017 r15189  
    4545
    4646    private static IEnumerable<string> StringifyLiteralStack<T>(IPushStack<T> stack, string prefix = "", string postfix = "", bool reverse = true) {
    47       var result = stack.AsEnumerable();
     47      var result = stack.AsStrings();
    4848
    4949      if (reverse)
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PushStack.cs

    r15017 r15189  
    122122    }
    123123
    124     public T ReverseElementAt(int offset) {
    125       return data[offset];
    126     }
    127 
    128124    public T this[int index]
    129125    {
     
    145141      if (index == Count - 1) return;
    146142
    147       var item = ReverseElementAt(index);
     143      var item = data[index];
    148144      data.RemoveAt(index);
    149145      data.Add(item);
     
    157153    }
    158154
    159     public T[] Pop(int count) {
     155    public IReadOnlyList<T> Pop(int count) {
    160156      var items = Peek(count);
    161157      Remove(count);
     
    164160    }
    165161
    166     public T Peek() {
    167       return Top;
    168     }
    169 
    170     public T[] Peek(int count) {
     162    public IReadOnlyList<T> Peek(int count) {
    171163      var startIndex = Count - count;
    172164
     
    207199    }
    208200
    209     public void PushResult(int count, Func<T[], T> templateFunc) {
    210       if (!IsEnabled) return;
    211 
    212       var startIndex = Count - count;
    213       var items = new T[count];
    214 
    215       data.CopyTo(startIndex, items, 0, count);
    216       Remove(count - 1);
    217 
    218       data[Count - 1] = templateFunc(items);
    219     }
    220 
    221201    public void Push(IReadOnlyList<T> items, int startIndex) {
    222202      if (!IsEnabled) return;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/StackTypes.cs

    r15032 r15189  
    2020    BooleanVector = 0x2000,
    2121  }
     22
     23  //public static class StackTypeExtensions {
     24  //  private static readonly IReadOnlyDictionary<StackTypes, string> StackTypesNameDict = new Dictionary<StackTypes, string> {
     25  //    { StackTypes.Integer, "Integer" },
     26  //    { StackTypes.Float, "Float" },
     27  //    { StackTypes.Char, "Char" },
     28  //    { StackTypes.String, "String" },
     29  //    { StackTypes.Boolean, "Boolean" },
     30  //    { StackTypes.Name, "Name" },
     31  //    { StackTypes.Code, "Code" },
     32  //    { StackTypes.Exec, "Exec" },
     33  //    { StackTypes.Print, "Print" },
     34  //    { StackTypes.IntegerVector, "IntegerVector" },
     35  //    { StackTypes.FloatVector, "FloatVector" },
     36  //    { StackTypes.StringVector, "StringVector" },
     37  //    { StackTypes.BooleanVector, "BooleanVector" },
     38  //  };
     39
     40  //  public static string GetName(this StackTypes types) {
     41  //    return StackTypesNameDict[types];
     42  //  }
     43  //}
    2244}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs

    r15032 r15189  
    9898    private IEnumerable<TreeNode> GetTreeNodes(IReadOnlyList<string> enabledExpressions) {
    9999      foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {
     100        if (stackType == StackTypes.None)
     101          continue;
     102
    100103        var stackTreeNode = new TreeNode {
    101104          Tag = stackType
Note: See TracChangeset for help on using the changeset viewer.