Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/28/17 22:52:08 (8 years ago)
Author:
pkimmesw
Message:

#2665 Dynamic ErcValues, Separate Push from BenchmarkSuite Push

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis
Files:
14 added
6 deleted
16 edited

Legend:

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

    r14875 r14897  
    129129    <Compile Include="Push\Data\Tree\TreeExtensions.cs" />
    130130    <Compile Include="Push\Data\Tree\TreeNode.cs" />
     131    <Compile Include="Push\Constants\Environment.cs" />
    131132    <Compile Include="Push\Exporter\Exporter.cs" />
    132133    <Compile Include="Push\Expressions\BooleanExpressions.cs" />
     
    149150    <Compile Include="Push\Expressions\NameExpressions.cs" />
    150151    <Compile Include="Push\Expressions\PopExpressions.cs" />
     152    <Compile Include="Push\Expressions\PrintExpressions.cs" />
    151153    <Compile Include="Push\Expressions\PushExpressions.cs" />
    152154    <Compile Include="Push\Expressions\PushProgram.cs" />
     
    188190    <Compile Include="Push\Generators\CodeGenerator\RecursiveCodeGenerator.cs" />
    189191    <Compile Include="Push\Generators\ErcUtils.cs" />
    190     <Compile Include="Push\Generators\StringGenerator.cs" />
    191192    <Compile Include="Push\Interpreter\Extensions.cs" />
    192193    <Compile Include="Push\Interpreter\IInternalPushInterpreter.cs" />
     
    199200    <Compile Include="Push\Interpreter\PushInterpreterPool.cs" />
    200201    <Compile Include="Push\Parser\PushParser.cs" />
     202    <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteSolution.cs" />
    201203    <Compile Include="Push\Problem\DataBounds.cs" />
    202204    <Compile Include="Push\Problem\EvaluationResult.cs" />
    203205    <Compile Include="Push\Problem\IndividualMapper.cs" />
    204     <Compile Include="Push\Problem\PushEvaluator.cs" />
     206    <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteEvaluator.cs" />
     207    <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteProblem.cs" />
     208    <Compile Include="Push\Problem\IPushEvaluator.cs" />
    205209    <Compile Include="Push\Problem\PushProblem.cs" />
    206210    <Compile Include="Properties\AssemblyInfo.cs" />
     
    220224      <DependentUpon>ExpressionSelectionView.cs</DependentUpon>
    221225    </Compile>
    222     <Compile Include="Push\Views\PushProgramDebuggerView.cs">
     226    <Compile Include="Push\Views\PushDebuggerView.cs">
    223227      <SubType>UserControl</SubType>
    224228    </Compile>
    225     <Compile Include="Push\Views\PushProgramDebuggerView.Designer.cs">
    226       <DependentUpon>PushProgramDebuggerView.cs</DependentUpon>
     229    <Compile Include="Push\Views\PushDebuggerView.Designer.cs">
     230      <DependentUpon>PushDebuggerView.cs</DependentUpon>
     231    </Compile>
     232    <Compile Include="Push\Problem\BenchmarkSuite\BenchmarkSuitePushSolutionView.cs">
     233      <SubType>UserControl</SubType>
     234    </Compile>
     235    <Compile Include="Push\Problem\BenchmarkSuite\BenchmarkSuitePushSolutionView.Designer.cs">
     236      <DependentUpon>BenchmarkSuitePushSolutionView.cs</DependentUpon>
    227237    </Compile>
    228238  </ItemGroup>
     
    231241      <Generator>ResXFileCodeGenerator</Generator>
    232242      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     243      <SubType>Designer</SubType>
    233244    </EmbeddedResource>
    234245    <EmbeddedResource Include="Push\Views\ExpressionSelectionView.resx">
    235246      <DependentUpon>ExpressionSelectionView.cs</DependentUpon>
    236247    </EmbeddedResource>
    237     <EmbeddedResource Include="Push\Views\PushProgramDebuggerView.resx">
    238       <DependentUpon>PushProgramDebuggerView.cs</DependentUpon>
     248    <EmbeddedResource Include="Push\Views\PushDebuggerView.resx">
     249      <DependentUpon>PushDebuggerView.cs</DependentUpon>
     250    </EmbeddedResource>
     251    <EmbeddedResource Include="Push\Problem\BenchmarkSuite\BenchmarkSuitePushSolutionView.resx">
     252      <DependentUpon>BenchmarkSuitePushSolutionView.cs</DependentUpon>
    239253    </EmbeddedResource>
    240254  </ItemGroup>
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Plugin.cs

    r14727 r14897  
    2929  [PluginFile("HeuristicLab.Problems.ProgramSynthesis.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Problems.ProgramSynthesis.BenchmarkSuite", "1.0")]
     31  [PluginDependency("HeuristicLab.Problems.ProgramSynthesis.Base", "1.0")]
    3132  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3233  [PluginDependency("HeuristicLab.Common", "3.3")]
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Properties/Resources.resx

    r14727 r14897  
    11<?xml version="1.0" encoding="utf-8"?>
    22<root>
    3   <!-- 
    4     Microsoft ResX Schema 
    5    
     3  <!--
     4    Microsoft ResX Schema
     5
    66    Version 2.0
    7    
    8     The primary goals of this format is to allow a simple XML format 
    9     that is mostly human readable. The generation and parsing of the 
    10     various data types are done through the TypeConverter classes 
     7
     8    The primary goals of this format is to allow a simple XML format
     9    that is mostly human readable. The generation and parsing of the
     10    various data types are done through the TypeConverter classes
    1111    associated with the data types.
    12    
     12
    1313    Example:
    14    
     14
    1515    ... ado.net/XML headers & schema ...
    1616    <resheader name="resmimetype">text/microsoft-resx</resheader>
     
    2727        <comment>This is a comment</comment>
    2828    </data>
    29                
    30     There are any number of "resheader" rows that contain simple 
     29
     30    There are any number of "resheader" rows that contain simple
    3131    name/value pairs.
    32    
    33     Each data row contains a name, and value. The row also contains a 
    34     type or mimetype. Type corresponds to a .NET class that support 
    35     text/value conversion through the TypeConverter architecture. 
    36     Classes that don't support this are serialized and stored with the 
     32
     33    Each data row contains a name, and value. The row also contains a
     34    type or mimetype. Type corresponds to a .NET class that support
     35    text/value conversion through the TypeConverter architecture.
     36    Classes that don't support this are serialized and stored with the
    3737    mimetype set.
    38    
    39     The mimetype is used for serialized objects, and tells the 
    40     ResXResourceReader how to depersist the object. This is currently not 
     38
     39    The mimetype is used for serialized objects, and tells the
     40    ResXResourceReader how to depersist the object. This is currently not
    4141    extensible. For a given mimetype the value must be set accordingly:
    42    
    43     Note - application/x-microsoft.net.object.binary.base64 is the format 
    44     that the ResXResourceWriter will generate, however the reader can 
     42
     43    Note - application/x-microsoft.net.object.binary.base64 is the format
     44    that the ResXResourceWriter will generate, however the reader can
    4545    read any of the formats listed below.
    46    
     46
    4747    mimetype: application/x-microsoft.net.object.binary.base64
    48     value   : The object must be serialized with 
     48    value   : The object must be serialized with
    4949            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    5050            : and then encoded with base64 encoding.
    51    
     51
    5252    mimetype: application/x-microsoft.net.object.soap.base64
    53     value   : The object must be serialized with 
     53    value   : The object must be serialized with
    5454            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
    5555            : and then encoded with base64 encoding.
    5656
    5757    mimetype: application/x-microsoft.net.object.bytearray.base64
    58     value   : The object must be serialized into a byte array 
     58    value   : The object must be serialized into a byte array
    5959            : using a System.ComponentModel.TypeConverter
    6060            : and then encoded with base64 encoding.
     
    8484          <xsd:element name="data">
    8585            <xsd:complexType>
    86               <xsd:sequence>
     86              <xsd:items>
    8787                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
    8888                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
    89               </xsd:sequence>
     89              </xsd:items>
    9090              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
    9191              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
     
    9696          <xsd:element name="resheader">
    9797            <xsd:complexType>
    98               <xsd:sequence>
     98              <xsd:items>
    9999                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
    100               </xsd:sequence>
     100              </xsd:items>
    101101              <xsd:attribute name="name" type="xsd:string" use="required" />
    102102            </xsd:complexType>
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs

    r14875 r14897  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Configuration {
    22  using System.Collections.Generic;
    3 
    4   using HeuristicLab.Common;
    5   using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces;
    6   using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
     3  using Base.Erc;
     4  using Common;
     5  using Stack;
    76
    87  public interface IReadOnlyPushConfiguration : IDeepCloneable {
     
    1211    int MaxStringLength { get; }
    1312    int MaxVectorLength { get; }
     13    int MinPointsInProgram { get; }
    1414    int MaxPointsInProgram { get; }
    1515    int MaxPointsInRandomExpression { get; }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs

    r14875 r14897  
    55  using Attributes;
    66  using Base.Erc;
    7   using Base.Erc.Interfaces;
    87  using Common;
    98  using Core;
     
    1413  [StorableClass]
    1514  public class PushConfiguration : ParameterizedNamedItem, IReadOnlyPushConfiguration, IEnabledExpressionsConfiguration {
    16 
    17 
    18 
    1915    public PushConfiguration() {
    2016      Name = "Push Configuration";
     
    2521      ErcOptions = new ErcOptions();
    2622      EvalPushLimit = 1024;
    27       MaxPointsInProgram = 128;
     23      MinPointsInProgram = 25;
     24      MaxPointsInProgram = 200;
    2825      TopLevelPushCode = true;
    2926      TopLevelPopCode = false;
    3027      MaxPointsInRandomExpression = 64;
    31       MaxStringLength = 32;
     28      MaxStringLength = 128;
    3229      MaxVectorLength = 64;
    3330      MaxDepth = 32;
     
    3835    private void InitEnabledStacks(bool state = true) {
    3936      foreach (StackTypes type in Enum.GetValues(typeof(StackTypes))) {
    40         if (!enabledStacks.ContainsKey(type))
     37        if (!enabledStacks.ContainsKey(type) && type != StackTypes.None)
    4138          enabledStacks.Add(type, state);
    4239      }
     
    5451      ErcOptions = cloner.Clone(origin.ErcOptions);
    5552      EvalPushLimit = origin.EvalPushLimit;
     53      MinPointsInProgram = origin.MinPointsInProgram;
    5654      MaxPointsInProgram = origin.MaxPointsInProgram;
    5755      MaxPointsInRandomExpression = origin.MaxPointsInRandomExpression;
     
    7270
    7371    [Storable]
    74     private Dictionary<StackTypes, bool> enabledStacks;
     72    private readonly Dictionary<StackTypes, bool> enabledStacks;
    7573
    7674    public IReadOnlyDictionary<StackTypes, bool> EnabledStacks { get { return enabledStacks; } }
     
    122120
    123121    /// <summary>
     122    ///     This is the minimum size of an item on the CODE stack, expressed as a number of points.
     123    ///     A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be
     124    ///     exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the
     125    ///     instruction.
     126    /// </summary>
     127    [Storable]
     128    public int MinPointsInProgram { get; set; }
     129
     130    /// <summary>
    124131    ///     This is the maximum size of an item on the CODE stack, expressed as a number of points.
    125132    ///     A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be
    126     ///     exceeded
    127     ///     should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the
     133    ///     exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the
    128134    ///     instruction.
    129135    /// </summary>
     
    155161    [Storable]
    156162    public int MaxVectorLength { get; set; }
     163
     164
     165    public void SetEnabledStacks(StackTypes types) {
     166      // Disable all
     167      EnabledExpressions.Clear();
     168
     169      // Enable those are required
     170      foreach (StackTypes type in Enum.GetValues(types.GetType())) {
     171        if (type == StackTypes.None) continue;
     172
     173        enabledStacks[type] = false;
     174
     175        if (types.HasFlag(type))
     176          EnableStack(type, true);
     177      }
     178    }
    157179
    158180    public void EnableExpressionOfStack(StackTypes types) {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/EqualsExpressions.cs

    r14875 r14897  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
    22  using System.Collections.Generic;
    3 
    4   using HeuristicLab.Common;
    5   using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    6   using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    7   using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
     3  using Attributes;
     4  using Common;
     5  using Interpreter;
     6  using Stack;
    87
    98  /// <summary>
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RandExpressions.cs

    r14834 r14897  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
    22  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    3   using HeuristicLab.Problems.ProgramSynthesis.Push.Generators;
    43  using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator;
    54  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    65  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
    7   using HeuristicLab.Random;
    86
    97  /// <summary>
     
    1614        return false;
    1715
    18       var name = interpreter.CustomExpressions.Count == 0 || interpreter.Random.NextDouble() < interpreter.Configuration.ErcOptions.NameErcOptions.NewNameProbability
    19                    ? ErcUtils.GetName(interpreter.Configuration.ErcOptions.NameErcOptions, interpreter.Random)
    20                    : interpreter.CustomExpressions.Keys.SampleRandom(interpreter.Random);
    21 
     16      var name = interpreter.Configuration.ErcOptions.NameErcOptions.GetErcValue(interpreter.Random);
    2217      interpreter.NameStack.Push(name);
    2318      return true;
     
    3429        return false;
    3530
    36       var value = ErcUtils.GetInteger(interpreter.Configuration.ErcOptions.IntegerErcOptions, interpreter.Random);
     31      var value = interpreter.Configuration.ErcOptions.IntegerErcOptions.GetErcValue(interpreter.Random);
    3732      interpreter.IntegerStack.Push(value);
    3833      return true;
     
    4944        return false;
    5045
    51       var value = ErcUtils.GetDouble(interpreter.Configuration.ErcOptions.FloatErcOptions, interpreter.Random);
     46      var value = interpreter.Configuration.ErcOptions.FloatErcOptions.GetErcValue(interpreter.Random);
    5247      interpreter.FloatStack.Push(value);
    5348      return true;
     
    6459        return false;
    6560
    66       var value = ErcUtils.GetBoolean(interpreter.Configuration.ErcOptions.BooleanErcOptions, interpreter.Random);
     61      var value = interpreter.Configuration.ErcOptions.BooleanErcOptions.GetErcValue(interpreter.Random);
    6762      interpreter.BooleanStack.Push(value);
    6863      return true;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/CodeGeneratorUtils.cs

    r14875 r14897  
    33
    44namespace HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator {
     5  using Core;
     6  using Expressions;
    57
    6   using HeuristicLab.Core;
    7   using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces;
    8   using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    9   using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
     8  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc;
     9
     10  using Stack;
    1011
    1112  internal static class CodeGeneratorUtils {
     
    1920
    2021      return index >= enabledExpressions.Count
    21         ? customExpressions.ElementAt(index - (enabledExpressions.Count - 1)).Value
     22        ? customExpressions.Values.ElementAt(index - enabledExpressions.Count)
    2223        : CreateExpressionOrErc(index, random, enabledExpressions, ercOptions);
    2324    }
     
    5556    }
    5657
     58    private static readonly Expression Noop = ExpressionTable.GetStatelessExpression<ExecNoopExpression>();
    5759    /// <summary>
    5860    /// Create a ErcExpression whereby the type of the expression conforms to the passed stack type.
     
    6567      switch (type) {
    6668        case StackTypes.Integer:
    67           if (ercOptions.IntegerErcOptions == null || !ercOptions.IntegerErcOptions.IsEnabled)
    68             return ExpressionTable.GetStatelessExpression<ExecNoopExpression>();
    69 
    70           var intValue = ErcUtils.GetInteger(ercOptions.IntegerErcOptions, random);
    71 
    72           return new IntegerPushExpression(intValue);
     69          return ercOptions.IntegerErcOptions == null || !ercOptions.IntegerErcOptions.IsEnabled
     70             ? Noop
     71             : new IntegerPushExpression(ercOptions.IntegerErcOptions.GetErcValue(random));
    7372
    7473        case StackTypes.Float:
    75           if (ercOptions.FloatErcOptions == null || !ercOptions.FloatErcOptions.IsEnabled)
    76             return ExpressionTable.GetStatelessExpression<ExecNoopExpression>();
    77 
    78           var doubleValue = ErcUtils.GetDouble(ercOptions.FloatErcOptions, random);
    79 
    80           return new FloatPushExpression(doubleValue);
     74          return ercOptions.FloatErcOptions == null || !ercOptions.FloatErcOptions.IsEnabled
     75            ? Noop
     76            : new FloatPushExpression(ercOptions.FloatErcOptions.GetErcValue(random));
    8177
    8278        case StackTypes.Boolean:
    8379          return ercOptions.BooleanErcOptions == null || !ercOptions.BooleanErcOptions.IsEnabled
    84             ? ExpressionTable.GetStatelessExpression<ExecNoopExpression>()
    85             : new BooleanPushExpression(ErcUtils.GetBoolean(ercOptions.BooleanErcOptions, random));
     80            ? Noop
     81            : new BooleanPushExpression(ercOptions.BooleanErcOptions.GetErcValue(random));
    8682
    8783        case StackTypes.Name:
    8884          return ercOptions.NameErcOptions == null || !ercOptions.NameErcOptions.IsEnabled
    89             ? ExpressionTable.GetStatelessExpression<ExecNoopExpression>()
    90             : new NamePushExpression(ErcUtils.GetName(ercOptions.NameErcOptions, random));
     85            ? Noop
     86            : new NamePushExpression(ercOptions.NameErcOptions.GetErcValue(random));
    9187
    9288        case StackTypes.String:
    9389          return ercOptions.StringErcOptions == null || !ercOptions.StringErcOptions.IsEnabled
    94             ? ExpressionTable.GetStatelessExpression<ExecNoopExpression>()
    95             : new StringPushExpression(ErcUtils.GetString(ercOptions.StringErcOptions, random));
     90            ? Noop
     91            : new StringPushExpression(ercOptions.StringErcOptions.GetErcValue(random));
    9692
    9793        case StackTypes.Char:
    9894          return ercOptions.CharErcOptions == null || !ercOptions.CharErcOptions.IsEnabled
    99             ? ExpressionTable.GetStatelessExpression<ExecNoopExpression>()
    100             : new CharPushExpression(ErcUtils.GetChar(ercOptions.CharErcOptions, random));
     95            ? Noop
     96            : new CharPushExpression(ercOptions.CharErcOptions.GetErcValue(random));
    10197
    10298        default:
    103           return ExpressionTable.GetStatelessExpression<ExecNoopExpression>();
     99          return Noop;
    104100      }
    105101    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs

    r14834 r14897  
    2424    IPushStack<List<bool>> BooleanVectorStack { get; }
    2525    IPushStack<List<string>> StringVectorStack { get; }
     26    IPushStack<string> PrintStack { get; }
    2627    IDictionary<string, Expression> CustomExpressions { get; }
    2728    IReadOnlyPushConfiguration Configuration { get; }
    2829    void Clear();
     30    void Reset();
    2931    void Run(string code, bool stepwise = false);
    3032    void Run(Expression expression, bool stepwise = false);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs

    r14875 r14897  
    7373      };
    7474
     75      PrintStack = new PushStack<string> {
     76        IsEnabled = Configuration.EnabledStacks[StackTypes.Print]
     77      };
     78
    7579      CustomExpressions = new Dictionary<string, Expression>();
    7680      PoolContainer = poolContainer ?? new InterpreterPoolContainer();
     
    155159    [PushStack(StackTypes.StringVector)]
    156160    public IPushStack<List<string>> StringVectorStack { get; private set; }
     161
     162    [PushStack(StackTypes.Print)]
     163    public IPushStack<string> PrintStack { get; private set; }
    157164
    158165    public IDictionary<string, Expression> CustomExpressions { get; private set; }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/EvaluationResult.cs

    r14834 r14897  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    6 
    7 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem
    8 {
    9     public class EvaluationResult
    10     {
    11       public EvaluationResult(int exampleCount)
    12       {
    13         ExampleQualities = new double[exampleCount];
    14       }
     1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
     2  public class EvaluationResult {
     3    public EvaluationResult(int exampleCount) {
     4      ExampleQualities = new double[exampleCount];
     5    }
    156
    167
    17         public double TotalQuality { get; set; }
    18         public double[] ExampleQualities { get; set; }
    19     }
     8    public double TotalQuality { get; set; }
     9    public double[] ExampleQualities { get; set; }
     10  }
    2011}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IndividualMapper.cs

    r14875 r14897  
    4343
    4444    private static PushProgram ToPushProgram(this IntegerVector vector, IReadOnlyPushConfiguration config, IRandom random) {
    45       var expressions = new Expression[vector.Length];
    4645      var enabledExpressions = config.EnabledExpressions;
    4746      var ercOptions = config.ErcOptions;
     47      //var programLength = random.Next(config.MinPointsInProgram, config.MaxPointsInProgram + 1);
     48      var expressions = new Expression[vector.Length];
    4849
    4950      for (var i = 0; i < vector.Length; i++)
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs

    r14875 r14897  
    22
    33namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
    4   using System.Collections.Generic;
    54  using System.Linq;
    6   using BenchmarkSuite.Problems;
     5
    76  using Common;
    87  using Configuration;
     
    109  using Data.Pool;
    1110  using Encodings.IntegerVectorEncoding;
    12   using Expressions;
    1311  using HeuristicLab.Data;
    1412  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc;
    15 
    16   using Instances;
     13  using HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite;
     14
    1715  using Interpreter;
    1816  using Optimization;
     
    2018  using Persistence.Default.CompositeSerializers.Storable;
    2119  using Random;
    22   using Stack;
    2320
    2421  [StorableClass]
    25   [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 180)]
    26   [Item("Push Problem", "")]
    27   public class PushProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding>, IProblemInstanceConsumer<ProblemData> {
     22  public abstract class PushProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding> {
    2823    [Storable]
    29     private readonly PushConfiguration config;
    30     private PushInterpreterPool pool;
    31     private readonly ObjectPool<IRandom> randomPool = new ObjectPool<IRandom>(() => new MersenneTwister());
     24    protected readonly PushConfiguration config;
     25    protected PushInterpreterPool pool;
     26    protected readonly ObjectPool<IRandom> randomPool = new ObjectPool<IRandom>(() => new MersenneTwister());
     27
     28    [Storable]
     29    protected readonly IPushEvaluator PushEvaluator;
    3230
    3331    public const string CaseQualitiesScopeParameterName = "CaseQualities";
     
    3533    private const string TestQualityResultName = "Test Quality";
    3634
    37     public PushProblem() {
     35    protected PushProblem(PushBenchmarkSuiteEvaluator evaluator) {
    3836      config = new PushConfiguration();
     37      PushEvaluator = evaluator;
    3938
    4039      InitData();
     
    4443
    4544    [StorableConstructor]
    46     public PushProblem(bool deserializing)
     45    protected PushProblem(bool deserializing)
    4746      : base(deserializing) {
    4847    }
    4948
    50     public PushProblem(PushProblem original, Cloner cloner)
     49    protected PushProblem(PushProblem original, Cloner cloner)
    5150      : base(original, cloner) {
    5251      config = cloner.Clone(original.config);
     52      PushEvaluator = cloner.Clone(original.PushEvaluator);
    5353
    5454      InitData();
     
    7878    #region Parameters
    7979
    80     private const string DataBoundsParameterName = "DataBounds";
    81     private const string DataParameterName = "Data";
    82     private const string DataParameterDescription = "Program Synthesis";
    8380    private const string InstructionsParameterName = "Instructions";
    8481    private const string InstructionsParameterDescription = "Enables/Disables Instructions";
    8582    private const string EvalPushLimitParameterName = "EvalPushLimit";
    8683    private const string EvalPushLimitParameterDescription = "This is the maximum allowed number of \"executions\" in a single top-level call to the interpreter. The execution of a single Push instruction counts as one execution, as does the processing of a single literal, as does the descent into one layer of parentheses (that is, the processing of the \"(\" counts as one execution).";
     84    private const string MinPointsInProgramParameterName = "MinProgramLength";
     85    private const string MinProgramLengthParameterDescription = "This is the minimum size of an item on the CODE/EXEC stack, expressed as a number of points. A point is an instruction, a literal, or a pair of parentheses.";
    8786    private const string MaxPointsInProgramParameterName = "MaxProgramLength";
    88     private const string MaxProgramLengthParameterDescription = "This is the maximum size of an item on the CODE stack, expressed as a number of points. A point is an instruction, a literal, or a pair of parentheses.";
     87    private const string MaxProgramLengthParameterDescription = "This is the maximum size of an item on the CODE/EXEC stack, expressed as a number of points. A point is an instruction, a literal, or a pair of parentheses.";
    8988    private const string TopLevelPushCodeParameterName = "TopLevelPushCode";
    9089    private const string TopLevelPushCodeParameterDescription = "When TRUE (which is the default), code passed to the top level of the interpreter will be pushed onto the CODE stack prior to execution.";
     
    9897
    9998    private void InitParameters() {
    100       Parameters.Add(new FixedValueParameter<DataBounds>(DataBoundsParameterName));
    101 
    10299      Parameters.Add(new ValueParameter<IEnabledExpressionsConfiguration>(
    103100        InstructionsParameterName,
     
    105102        config));
    106103
    107       Parameters.Add(new ValueParameter<ProblemData>(
    108         DataParameterName,
    109         DataParameterDescription));
    110 
    111104      Parameters.Add(new ValueParameter<ErcOptions>(ErcOptionsParameterName, config.ErcOptions));
    112105
     
    117110
    118111      Parameters.Add(new FixedValueParameter<IntValue>(
     112        MinPointsInProgramParameterName,
     113        MinProgramLengthParameterDescription,
     114        new IntValue(config.MinPointsInProgram)) { Hidden = true });
     115
     116      Parameters.Add(new FixedValueParameter<IntValue>(
    119117        MaxPointsInProgramParameterName,
    120118        MaxProgramLengthParameterDescription,
    121119        new IntValue(config.MaxPointsInProgram)));
    122       Encoding.LengthParameter = Parameters[MaxPointsInProgramParameterName] as IFixedValueParameter<IntValue>;
     120      Encoding.LengthParameter = MaxPointsInProgramParameter as IFixedValueParameter<IntValue>;
    123121
    124122      Parameters.Add(new FixedValueParameter<BoolValue>(
     
    153151    }
    154152
    155     public IValueParameter<DataBounds> DataBoundsParameter
    156     {
    157       get { return (IValueParameter<DataBounds>)Parameters[DataBoundsParameterName]; }
    158     }
    159 
    160     public DataBounds DataBounds
    161     {
    162       get { return DataBoundsParameter.Value; }
    163       set { DataBoundsParameter.Value = value; }
    164     }
    165 
    166 
    167153    public IValueParameter<IEnabledExpressionsConfiguration> InstructionsParameter
    168154    {
     
    174160      get { return InstructionsParameter.Value; }
    175161      set { InstructionsParameter.Value = value; }
    176     }
    177 
    178     public IValueParameter<ProblemData> DataParameter
    179     {
    180       get { return (IValueParameter<ProblemData>)Parameters[DataParameterName]; }
    181     }
    182 
    183     public ProblemData Data
    184     {
    185       get { return DataParameter.Value; }
    186       set { DataParameter.Value = value; }
    187162    }
    188163
     
    267242
    268243    /// <summary>
     244    ///     This is the minimum size of an item on the CODE stack, expressed as a number of points.
     245    ///     A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be
     246    ///     exceeded
     247    ///     should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the
     248    ///     instruction.
     249    /// </summary>
     250    public IValueParameter<IntValue> MinPointsInProgramParameter
     251    {
     252      get { return (IValueParameter<IntValue>)this.Parameters[MinPointsInProgramParameterName]; }
     253    }
     254
     255    public int MinPointsInProgram
     256    {
     257      get { return config.MaxPointsInProgram; }
     258      set
     259      {
     260        MinPointsInProgramParameter.Value.Value = value;
     261        config.MinPointsInProgram = value;
     262      }
     263    }
     264
     265    /// <summary>
    269266    ///     The maximum number of points in an expression produced by the CODE.RAND instruction.
    270267    /// </summary>
     
    338335
    339336    public override bool Maximization { get { return false; } }
    340 
    341     public override IDeepCloneable Clone(Cloner cloner) {
    342       return new PushProblem(this, cloner);
    343     }
    344337
    345338    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     
    357350    private void AnalyzeBestTestSolution(IntegerVector bestIndividual, ResultCollection results, IRandom random) {
    358351      var program = bestIndividual.ToPushProgram(config, randomPool);
    359       var trainingResult = PushEvaluator.Evaluate(program, pool, random, Data, DataBounds.TestRange.Start, DataBounds.TestRange.End);
     352      var testResult = PushEvaluator.EvaluateTest(pool, program, random);
    360353
    361354      if (!results.ContainsKey(TestQualityResultName)) {
    362         results.Add(new Result(TestQualityResultName, new DoubleValue(trainingResult.TotalQuality)));
     355        results.Add(new Result(TestQualityResultName, new DoubleValue(testResult.TotalQuality)));
    363356      } else {
    364         ((DoubleValue)results[TestQualityResultName].Value).Value = trainingResult.TotalQuality;
     357        ((DoubleValue)results[TestQualityResultName].Value).Value = testResult.TotalQuality;
    365358      }
    366359    }
    367360
    368361    private bool AnalyzeBestTrainingSolution(IntegerVector bestIndividual, double bestQuality, ResultCollection results, IRandom random) {
    369       var solution = new PushSolution(bestIndividual, bestQuality, Data, random, config, DataBounds.TrainingRange.Start, DataBounds.TrainingRange.End);
     362      var solution = CreatePushSolution(
     363        bestIndividual,
     364        bestQuality,
     365        random,
     366        config,
     367        PushEvaluator);
    370368
    371369      if (!results.ContainsKey(BestTrainingSolutionResultName)) {
     
    385383    }
    386384
     385    protected abstract PushSolution CreatePushSolution(
     386      IntegerVector vector,
     387      double bestQuality,
     388      IRandom random,
     389      IReadOnlyPushConfiguration config,
     390      IPushEvaluator evaluator);
     391
    387392    public override double Evaluate(Individual individual, IRandom random) {
    388393      var program = individual.ToPushProgram(config, randomPool);
    389       var result = PushEvaluator.Evaluate(
    390         program,
    391         pool,
    392         random,
    393         Data,
    394         DataBounds.TrainingRange.Start,
    395         DataBounds.TrainingRange.End);
    396 
    397       individual.SetScopeValue(CaseQualitiesScopeParameterName, new DoubleArray(result.ExampleQualities));
     394      var result = PushEvaluator.EvaluateTraining(pool, program, random);
     395
     396      individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
    398397
    399398      return result.TotalQuality;
    400     }
    401 
    402     public void Load(ProblemData data) {
    403       Data = data;
    404       BestKnownQuality = data.BestResult;
    405       MaxPointsInProgram = data.MaxSize;
    406       EvalPushLimit = data.EvalLimit;
    407       ErcOptions = data.ErcOptions;
    408 
    409       config.EnabledExpressions = (IList<string>)ExpressionTable.GetExpressionsByStackTypes((StackTypes)data.EnabledDataTypes);
    410 
    411       // update enabled stack types
    412       foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {
    413         var enable = config.EnabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]).Any();
    414         config.SetStack(stackType, enable);
    415       }
    416 
    417       Encoding.Bounds[0, 0] = 0;
    418       Encoding.Bounds[0, 1] = config.EnabledExpressions.Count;
    419       Encoding.Length = config.MaxPointsInProgram;
    420 
    421       DataBounds.TrainingRange.Start = 0;
    422       DataBounds.TrainingRange.End = Data.TrainingCount;
    423       DataBounds.TestRange.Start = Data.TrainingCount;
    424       DataBounds.TestRange.End = Data.TrainingCount + Data.TestCount;
    425399    }
    426400  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushSolution.cs

    r14875 r14897  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
    2   using HeuristicLab.BenchmarkSuite.Problems;
    3   using HeuristicLab.Common;
    4   using HeuristicLab.Core;
    5   using HeuristicLab.Encodings.IntegerVectorEncoding;
    6   using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    7   using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
     2  using Common;
     3  using Configuration;
     4  using Core;
     5  using Encodings.IntegerVectorEncoding;
     6  using Expressions;
     7  using Persistence.Default.CompositeSerializers.Storable;
    88
    99  [StorableClass]
     
    1414    public readonly IntegerVector IntegerVector;
    1515    [Storable]
    16     public readonly ProblemData Data;
    17     [Storable]
    1816    public readonly IRandom Random;
    1917    [Storable]
    2018    public readonly IReadOnlyPushConfiguration Config;
     19
    2120    [Storable]
    22     public readonly int DataStart;
    23     [Storable]
    24     public readonly int DataEnd;
    25     [Storable]
    26     public readonly bool Simplify;
     21    public readonly IPushEvaluator Evaluator;
    2722
    28     public PushSolution(IntegerVector integerVector, double quality, ProblemData data, IRandom random, IReadOnlyPushConfiguration config, int dataStart, int dataEnd, bool simplify = false)
     23    public readonly PushProgram Program;
     24
     25    public PushSolution(IntegerVector integerVector, double quality, IRandom random, IReadOnlyPushConfiguration config, IPushEvaluator evaluator, bool simplify = false)
    2926      : base("Solution", "A push solution.") {
    3027      IntegerVector = integerVector;
    3128      Quality = quality;
    32       Data = data;
    3329      Random = random;
    3430      Config = config;
    35       DataStart = dataStart;
    36       DataEnd = dataEnd;
    37       Simplify = simplify;
     31      Evaluator = evaluator;
     32
     33      Program = IntegerVector.ToPushProgram(config);
     34
     35      if (simplify)
     36        Program = Simplifier.Simplifier.Simplify(Program, p => Evaluator.EvaluateTraining(config, p, random).TotalQuality);
    3837    }
    3938
    4039    public PushSolution(PushSolution origin, Cloner cloner) : base(origin, cloner) {
     40      Quality = origin.Quality;
    4141      IntegerVector = cloner.Clone(origin.IntegerVector);
    42       Quality = origin.Quality;
    43       Data = cloner.Clone(origin.Data);
    4442      Random = cloner.Clone(origin.Random);
    4543      Config = cloner.Clone(origin.Config);
    46       DataStart = origin.DataStart;
    47       DataEnd = origin.DataEnd;
    48       Simplify = origin.Simplify;
     44    }
     45
     46    public virtual PushSolution Simplify() {
     47      return new PushSolution(IntegerVector, Quality, Random, Config, Evaluator, true);
    4948    }
    5049
    5150    [StorableConstructor]
    52     private PushSolution(bool deserializing) : base(deserializing) { }
     51    protected PushSolution(bool deserializing) : base(deserializing) { }
    5352
    5453    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/StackTypes.cs

    r14875 r14897  
    55  [Flags]
    66  public enum StackTypes : ushort {
    7     None = 0x00, // Required to specify expression dependencies
     7    None = 0x01, // Required to specify expression dependencies
    88    Integer = 0x02,
    99    Float = 0x04,
     
    1414    Code = 0x80,
    1515    Exec = 0x100,
    16     Return = 0x200,
     16    Print = 0x200,
    1717    IntegerVector = 0x400,
    1818    FloatVector = 0x800,
    1919    StringVector = 0x1000,
    20     BooleanVector = 0x2000
     20    BooleanVector = 0x2000,
    2121  }
    2222}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.resx

    r14777 r14897  
    6767          <xsd:element name="metadata">
    6868            <xsd:complexType>
    69               <xsd:sequence>
     69              <xsd:items>
    7070                <xsd:element name="value" types="xsd:string" minOccurs="0" />
    71               </xsd:sequence>
     71              </xsd:items>
    7272              <xsd:attribute name="name" use="required" types="xsd:string" />
    7373              <xsd:attribute name="types" types="xsd:string" />
     
    8484          <xsd:element name="data">
    8585            <xsd:complexType>
    86               <xsd:sequence>
     86              <xsd:items>
    8787                <xsd:element name="value" types="xsd:string" minOccurs="0" msdata:Ordinal="1" />
    8888                <xsd:element name="comment" types="xsd:string" minOccurs="0" msdata:Ordinal="2" />
    89               </xsd:sequence>
     89              </xsd:items>
    9090              <xsd:attribute name="name" types="xsd:string" use="required" msdata:Ordinal="1" />
    9191              <xsd:attribute name="types" types="xsd:string" msdata:Ordinal="3" />
     
    9696          <xsd:element name="resheader">
    9797            <xsd:complexType>
    98               <xsd:sequence>
     98              <xsd:items>
    9999                <xsd:element name="value" types="xsd:string" minOccurs="0" msdata:Ordinal="1" />
    100               </xsd:sequence>
     100              </xsd:items>
    101101              <xsd:attribute name="name" types="xsd:string" use="required" />
    102102            </xsd:complexType>
Note: See TracChangeset for help on using the changeset viewer.