Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/19/17 12:55:58 (7 years ago)
Author:
pkimmesw
Message:

#2665 Started Plush Encoding, Added Zero Error Individual Count Analyzer

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IEnabledExpressionsConfiguration.cs

    r15032 r15273  
    1717  }
    1818
    19   public interface IEnabledExpressionsConfiguration : INamedItem {
     19  public interface IReadOnlyExpressionsConfiguration : INamedItem {
     20    int InExpressionCount { get; }
     21
     22    IReadOnlyList<string> EnabledExpressions { get; }
     23    IReadOnlyDictionary<StackTypes, int> ExpressionsPerStackCount { get; }
     24  }
     25
     26  public interface IExpressionsConfiguration : IReadOnlyExpressionsConfiguration {
    2027    event EventHandler<EnabledExpressionsChangedEventArgs> EnabledExpressionsChanged;
    2128
    22     IReadOnlyList<string> EnabledExpressions { get; }
    23 
    2429    void EnableStack(StackTypes types, bool enableDependencies = false);
    25     void DisableStack(StackTypes type, bool enableDepenencies = false);
     30    void DisableStack(StackTypes type, bool enableDependencies = false);
    2631    void SetStack(StackTypes type, bool state, bool setDependencies = false);
    2732    void EnableExpressionOfStack(StackTypes types);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs

    r15032 r15273  
    22  using System.Collections.Generic;
    33  using Base.Erc;
    4   using Common;
    5 
    6   using HeuristicLab.Core;
    74
    85  using Stack;
    96
    10   public interface IReadOnlyPushConfiguration : IItem {
     7  public interface IReadOnlyPushConfiguration : IReadOnlyExpressionsConfiguration {
     8    int Seed { get; }
    119    int EvalPushLimit { get; }
    1210    int MaxDepth { get; }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfigurationBase.cs

    r15189 r15273  
    1212
    1313  [StorableClass]
    14   public abstract class PushConfigurationBase : NamedItem, IEnabledExpressionsConfiguration {
     14  public abstract class PushConfigurationBase : NamedItem, IExpressionsConfiguration {
    1515
    1616    protected PushConfigurationBase() {
     
    2828      enabledExpressions = origin.EnabledExpressions.ToList();
    2929      expressionsPerStackCount = origin.expressionsPerStackCount.ToDictionary(x => x.Key, x => x.Value);
    30     }
     30      InExpressionCount = origin.InExpressionCount;
     31      Seed = origin.Seed;
     32    }
     33
     34    [Storable]
     35    public int Seed { get; set; }
     36
     37    [Storable]
     38    public int InExpressionCount { get; private set; }
    3139
    3240    [Storable]
    3341    private readonly Dictionary<StackTypes, int> expressionsPerStackCount;
     42
     43    public IReadOnlyDictionary<StackTypes, int> ExpressionsPerStackCount { get { return expressionsPerStackCount; } }
    3444
    3545    public event EventHandler<EnabledExpressionsChangedEventArgs> EnabledExpressionsChanged;
     
    112122
    113123    private void EnableExpressions(IEnumerable<string> expressionNames) {
    114       foreach (var expressionName in expressionNames.Except(EnabledExpressions))
     124      var addedExpressions = expressionNames as IList<string> ?? expressionNames.ToList();
     125
     126      foreach (var expressionName in addedExpressions.Except(EnabledExpressions))
    115127        EnableExpression(expressionName, false);
    116128
    117129      if (EnabledExpressionsChanged != null) {
    118         EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(expressionNames, new string[0]));
     130        EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(addedExpressions, new string[0]));
    119131      }
    120132    }
     
    133145
    134146    private void DisableExpressions(IEnumerable<string> expressionNames) {
    135       foreach (var expressionName in expressionNames.Intersect(EnabledExpressions))
     147      var removedExpressions = expressionNames as IList<string> ?? expressionNames.ToList();
     148
     149      foreach (var expressionName in removedExpressions.Intersect(EnabledExpressions))
    136150        DisableExpression(expressionName, false);
    137151
    138152      if (EnabledExpressionsChanged != null) {
    139         EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(new string[0], expressionNames));
     153        EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(new string[0], removedExpressions));
    140154      }
    141155    }
     
    229243      else DisableStack(type, setDependencies);
    230244    }
     245
     246    public void InitInExpressions(int totalInputArgumentCount) {
     247      InExpressionCount = totalInputArgumentCount;
     248
     249      for (var i = 0; i < ExpressionTable.InExpressionTable.Count; i++) {
     250        var expression = ExpressionTable.InExpressionTable[i];
     251        var expressionName = ExpressionTable.TypeToNameTable[expression.GetType()];
     252
     253        DisableExpression(expressionName);
     254      }
     255
     256      if (totalInputArgumentCount > ExpressionTable.InExpressionTable.Count)
     257        throw new InvalidOperationException("More input arguments defined as InExpression types");
     258
     259      for (var i = 0; i < totalInputArgumentCount; i++) {
     260        var expression = ExpressionTable.InExpressionTable[i];
     261        var expressionName = ExpressionTable.TypeToNameTable[expression.GetType()];
     262
     263        EnableExpression(expressionName);
     264      }
     265    }
    231266  }
    232267}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfigurationParameterCollection.cs

    r15032 r15273  
    1111  [StorableClass]
    1212  public class PushConfigurationParameterCollection : PushConfigurationBase, IReadOnlyPushConfiguration {
    13     private const string InstructionsParameterName = "Instructions";
    14     private const string InstructionsParameterDescription = "Enables/Disables Instructions";
    15     private const string EvalPushLimitParameterName = "EvalPushLimit";
    16     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).";
    17     private const string MaxPointsInProgramParameterName = "MaxProgramLength";
    18     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.";
    19     private const string TopLevelPushCodeParameterName = "TopLevelPushCode";
    20     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.";
    21     private const string TopLevelPopCodeParameterName = "TopLevelPopCode";
    22     private const string TopLevelPopCodeParameterDescription = "When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE.";
    23     private const string MaxPointsInRandomInstructionParameterName = "MaxPointsInRandomInstruction";
    24     private const string MaxPointsInRandomInstructionParameterDescription = "MaxPointsInRandomInstruction";
    25     private const string ErcOptionsParameterName = "ERC options";
    26     private const string MaxStringLengthParameterName = "Max. string length";
    27     private const string MaxDepthParameterName = "Max. program recursion";
    28     private const string MaxParenthesesCloseParameterName = "Max. parentheses close";
    29     private const string MaxParenthesesCloseParameterDescription = "Specifies how many sub programs are closed if open during the recursive translation of an individual to a push program. Value is exclusive.";
    30     private const string ParenthesesCloseBiasLevelParameterName = "Parentheses close bias level";
    31     private const string ParenthesesCloseBiasLevelParameterDescription = "Specifies how strong a random value between 0 .. 'Max. parentheses close' is biased towards 0. In other words, this parameter controls the length of sub programs.";
    32     private const string MaxVectorLengthParameterName = "Max. vector length";
     13    private const string INSTRUCTIONS_PARAMETER_NAME = "Instructions";
     14    private const string INSTRUCTIONS_PARAMETER_DESCRIPTION = "Enables/Disables Instructions";
     15    private const string EVAL_PUSH_LIMIT_PARAMETER_NAME = "EvalPushLimit";
     16    private const string EVAL_PUSH_LIMIT_PARAMETER_DESCRIPTION = "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).";
     17    private const string MAX_POINTS_IN_PROGRAM_PARAMETER_NAME = "MaxProgramLength";
     18    private const string MAX_PROGRAM_LENGTH_PARAMETER_DESCRIPTION = "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.";
     19    private const string TOP_LEVEL_PUSH_CODE_PARAMETER_NAME = "TopLevelPushCode";
     20    private const string TOP_LEVEL_PUSH_CODE_PARAMETER_DESCRIPTION = "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.";
     21    private const string TOP_LEVEL_POP_CODE_PARAMETER_NAME = "TopLevelPopCode";
     22    private const string TOP_LEVEL_POP_CODE_PARAMETER_DESCRIPTION = "When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE.";
     23    private const string MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME = "MaxPointsInRandomInstruction";
     24    private const string MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_DESCRIPTION = "MaxPointsInRandomInstruction";
     25    private const string ERC_OPTIONS_PARAMETER_NAME = "ERC options";
     26    private const string MAX_STRING_LENGTH_PARAMETER_NAME = "Max. string length";
     27    private const string MAX_DEPTH_PARAMETER_NAME = "Max. program recursion";
     28    private const string MAX_PARENTHESES_CLOSE_PARAMETER_NAME = "Max. parentheses close";
     29    private const string MAX_PARENTHESES_CLOSE_PARAMETER_DESCRIPTION = "Specifies how many sub programs are closed if open during the recursive translation of an individual to a push program. Value is exclusive.";
     30    private const string PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME = "Parentheses close bias level";
     31    private const string PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_DESCRIPTION = "Specifies how strong a random value between 0 .. 'Max. parentheses close' is biased towards 0. In other words, this parameter controls the length of sub programs.";
     32    private const string MAX_VECTOR_LENGTH_PARAMETER_NAME = "Max. vector length";
    3333
    3434    public PushConfigurationParameterCollection() {
     
    6262
    6363    private void InitParameters() {
    64       if (!Parameters.ContainsKey(InstructionsParameterName))
    65         Parameters.Add(new ValueParameter<IEnabledExpressionsConfiguration>(
    66           InstructionsParameterName,
    67           InstructionsParameterDescription,
     64      if (!Parameters.ContainsKey(INSTRUCTIONS_PARAMETER_NAME))
     65        Parameters.Add(new ValueParameter<IExpressionsConfiguration>(
     66          INSTRUCTIONS_PARAMETER_NAME,
     67          INSTRUCTIONS_PARAMETER_DESCRIPTION,
    6868          this));
    6969
    70       if (!Parameters.ContainsKey(ErcOptionsParameterName))
    71         Parameters.Add(new ValueParameter<ErcOptions>(ErcOptionsParameterName));
    72 
    73       if (!Parameters.ContainsKey(MaxVectorLengthParameterName))
    74         Parameters.Add(new FixedValueParameter<IntValue>(
    75           MaxVectorLengthParameterName,
     70      if (!Parameters.ContainsKey(ERC_OPTIONS_PARAMETER_NAME))
     71        Parameters.Add(new ValueParameter<ErcOptions>(ERC_OPTIONS_PARAMETER_NAME));
     72
     73      if (!Parameters.ContainsKey(MAX_VECTOR_LENGTH_PARAMETER_NAME))
     74        Parameters.Add(new FixedValueParameter<IntValue>(
     75          MAX_VECTOR_LENGTH_PARAMETER_NAME,
    7676          new IntValue(500)) { Hidden = true });
    7777
    78       if (!Parameters.ContainsKey(EvalPushLimitParameterName))
    79         Parameters.Add(new FixedValueParameter<IntValue>(
    80           EvalPushLimitParameterName,
    81           EvalPushLimitParameterDescription,
     78      if (!Parameters.ContainsKey(EVAL_PUSH_LIMIT_PARAMETER_NAME))
     79        Parameters.Add(new FixedValueParameter<IntValue>(
     80          EVAL_PUSH_LIMIT_PARAMETER_NAME,
     81          EVAL_PUSH_LIMIT_PARAMETER_DESCRIPTION,
    8282          new IntValue(1000)));
    8383
    84       if (!Parameters.ContainsKey(MaxPointsInProgramParameterName))
    85         Parameters.Add(new FixedValueParameter<IntValue>(
    86           MaxPointsInProgramParameterName,
    87           MaxProgramLengthParameterDescription,
     84      if (!Parameters.ContainsKey(MAX_POINTS_IN_PROGRAM_PARAMETER_NAME))
     85        Parameters.Add(new FixedValueParameter<IntValue>(
     86          MAX_POINTS_IN_PROGRAM_PARAMETER_NAME,
     87          MAX_PROGRAM_LENGTH_PARAMETER_DESCRIPTION,
    8888          new IntValue(200)));
    8989
    90       if (!Parameters.ContainsKey(MaxParenthesesCloseParameterName))
    91         Parameters.Add(new FixedValueParameter<IntValue>(
    92           MaxParenthesesCloseParameterName,
    93           MaxParenthesesCloseParameterDescription,
     90      if (!Parameters.ContainsKey(MAX_PARENTHESES_CLOSE_PARAMETER_NAME))
     91        Parameters.Add(new FixedValueParameter<IntValue>(
     92          MAX_PARENTHESES_CLOSE_PARAMETER_NAME,
     93          MAX_PARENTHESES_CLOSE_PARAMETER_DESCRIPTION,
    9494          new IntValue(4)) { Hidden = true });
    9595
    96       if (!Parameters.ContainsKey(ParenthesesCloseBiasLevelParameterName))
     96      if (!Parameters.ContainsKey(PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME))
    9797        Parameters.Add(new FixedValueParameter<DoubleValue>(
    98           ParenthesesCloseBiasLevelParameterName,
    99           ParenthesesCloseBiasLevelParameterDescription,
     98          PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME,
     99          PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_DESCRIPTION,
    100100          new DoubleValue(4)) { Hidden = true });
    101101
    102       if (!Parameters.ContainsKey(TopLevelPushCodeParameterName))
     102      if (!Parameters.ContainsKey(TOP_LEVEL_PUSH_CODE_PARAMETER_NAME))
    103103        Parameters.Add(new FixedValueParameter<BoolValue>(
    104           TopLevelPushCodeParameterName,
    105           TopLevelPushCodeParameterDescription,
     104          TOP_LEVEL_PUSH_CODE_PARAMETER_NAME,
     105          TOP_LEVEL_PUSH_CODE_PARAMETER_DESCRIPTION,
    106106          new BoolValue(true)) { Hidden = true });
    107107
    108       if (!Parameters.ContainsKey(TopLevelPopCodeParameterName))
     108      if (!Parameters.ContainsKey(TOP_LEVEL_POP_CODE_PARAMETER_NAME))
    109109        Parameters.Add(new FixedValueParameter<BoolValue>(
    110           TopLevelPopCodeParameterName,
    111           TopLevelPopCodeParameterDescription,
     110          TOP_LEVEL_POP_CODE_PARAMETER_NAME,
     111          TOP_LEVEL_POP_CODE_PARAMETER_DESCRIPTION,
    112112          new BoolValue(false)) { Hidden = true });
    113113
    114       if (!Parameters.ContainsKey(MaxPointsInRandomInstructionParameterName))
    115         Parameters.Add(new FixedValueParameter<IntValue>(
    116           MaxPointsInRandomInstructionParameterName,
    117           MaxPointsInRandomInstructionParameterDescription,
     114      if (!Parameters.ContainsKey(MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME))
     115        Parameters.Add(new FixedValueParameter<IntValue>(
     116          MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME,
     117          MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_DESCRIPTION,
    118118          new IntValue(50)) { Hidden = true });
    119119
    120       if (!Parameters.ContainsKey(MaxStringLengthParameterName))
    121         Parameters.Add(new FixedValueParameter<IntValue>(
    122           MaxStringLengthParameterName,
     120      if (!Parameters.ContainsKey(MAX_STRING_LENGTH_PARAMETER_NAME))
     121        Parameters.Add(new FixedValueParameter<IntValue>(
     122          MAX_STRING_LENGTH_PARAMETER_NAME,
    123123          new IntValue(1000)) { Hidden = true });
    124124
    125       if (!Parameters.ContainsKey(MaxDepthParameterName))
    126         Parameters.Add(new FixedValueParameter<IntValue>(
    127           MaxDepthParameterName,
     125      if (!Parameters.ContainsKey(MAX_DEPTH_PARAMETER_NAME))
     126        Parameters.Add(new FixedValueParameter<IntValue>(
     127          MAX_DEPTH_PARAMETER_NAME,
    128128          new IntValue(1000)) { Hidden = true });
    129129    }
    130130
    131     public IValueParameter<IEnabledExpressionsConfiguration> InstructionsParameter
    132     {
    133       get { return (IValueParameter<IEnabledExpressionsConfiguration>)Parameters[InstructionsParameterName]; }
    134     }
    135 
    136     public IEnabledExpressionsConfiguration Instructions
     131    public IValueParameter<IExpressionsConfiguration> InstructionsParameter
     132    {
     133      get { return (IValueParameter<IExpressionsConfiguration>)Parameters[INSTRUCTIONS_PARAMETER_NAME]; }
     134    }
     135
     136    public IExpressionsConfiguration Instructions
    137137    {
    138138      get { return InstructionsParameter.Value; }
     
    142142    public IValueParameter<ErcOptions> ErcOptionsParameter
    143143    {
    144       get { return (IValueParameter<ErcOptions>)Parameters[ErcOptionsParameterName]; }
     144      get { return (IValueParameter<ErcOptions>)Parameters[ERC_OPTIONS_PARAMETER_NAME]; }
    145145    }
    146146
     
    181181    public IValueParameter<IntValue> EvalPushLimitParameter
    182182    {
    183       get { return (IValueParameter<IntValue>)Parameters[EvalPushLimitParameterName]; }
     183      get { return (IValueParameter<IntValue>)Parameters[EVAL_PUSH_LIMIT_PARAMETER_NAME]; }
    184184    }
    185185
     
    198198    public IValueParameter<DoubleValue> ParenthesesCloseBiasLevelParameter
    199199    {
    200       get { return (IValueParameter<DoubleValue>)Parameters[ParenthesesCloseBiasLevelParameterName]; }
     200      get { return (IValueParameter<DoubleValue>)Parameters[PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME]; }
    201201    }
    202202
     
    212212    public IValueParameter<IntValue> MaxParenthesesCloseParameter
    213213    {
    214       get { return (IValueParameter<IntValue>)Parameters[MaxParenthesesCloseParameterName]; }
     214      get { return (IValueParameter<IntValue>)Parameters[MAX_PARENTHESES_CLOSE_PARAMETER_NAME]; }
    215215    }
    216216
     
    229229    public IValueParameter<IntValue> MaxDepthParameter
    230230    {
    231       get { return (IValueParameter<IntValue>)Parameters[MaxDepthParameterName]; }
     231      get { return (IValueParameter<IntValue>)Parameters[MAX_DEPTH_PARAMETER_NAME]; }
    232232    }
    233233
     
    249249    public IValueParameter<IntValue> MaxPointsInProgramParameter
    250250    {
    251       get { return (IValueParameter<IntValue>)Parameters[MaxPointsInProgramParameterName]; }
     251      get { return (IValueParameter<IntValue>)Parameters[MAX_POINTS_IN_PROGRAM_PARAMETER_NAME]; }
    252252    }
    253253
     
    263263    public IValueParameter<IntValue> MaxVectorLengthParameter
    264264    {
    265       get { return (IValueParameter<IntValue>)Parameters[MaxVectorLengthParameterName]; }
     265      get { return (IValueParameter<IntValue>)Parameters[MAX_VECTOR_LENGTH_PARAMETER_NAME]; }
    266266    }
    267267
     
    277277    public IValueParameter<IntValue> MaxPointsInRandomExpressionParameter
    278278    {
    279       get { return (IValueParameter<IntValue>)Parameters[MaxPointsInRandomInstructionParameterName]; }
     279      get { return (IValueParameter<IntValue>)Parameters[MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME]; }
    280280    }
    281281
     
    295295    public IValueParameter<BoolValue> TopLevelPushCodeParameter
    296296    {
    297       get { return (IValueParameter<BoolValue>)Parameters[TopLevelPushCodeParameterName]; }
     297      get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_PUSH_CODE_PARAMETER_NAME]; }
    298298    }
    299299
     
    312312    public IValueParameter<BoolValue> TopLevelPopCodeParameter
    313313    {
    314       get { return (IValueParameter<BoolValue>)Parameters[TopLevelPopCodeParameterName]; }
     314      get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_POP_CODE_PARAMETER_NAME]; }
    315315    }
    316316
     
    326326    public IValueParameter<IntValue> MaxStringLengthParameter
    327327    {
    328       get { return (IValueParameter<IntValue>)Parameters[MaxStringLengthParameterName]; }
     328      get { return (IValueParameter<IntValue>)Parameters[MAX_STRING_LENGTH_PARAMETER_NAME]; }
    329329    }
    330330
Note: See TracChangeset for help on using the changeset viewer.