Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/10/17 00:27:31 (8 years ago)
Author:
pkimmesw
Message:

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

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

Legend:

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

    r14777 r14834  
    2222    IList<string> EnabledExpressions { get; }
    2323
    24     void EnableStack(StackTypes types);
    25     void DisableStack(StackTypes types);
     24    void EnableStack(StackTypes types, bool enableExpressions = false);
     25    void DisableStack(StackTypes type, bool disableExpressions = false);
     26    void SetStack(StackTypes type, bool state, bool cascadeForExpressions = false);
    2627    void EnableExpressionOfStack(StackTypes types);
    2728    void DisableExpressionOfStack(StackTypes types);
    28     void EnableExpression(string name);
    29     void DisableExpression(string name);
    30     void EnableExpression<T>() where T : Expression;
    31     void DisableExpression<T>() where T : Expression;
     29    void EnableExpression(string name, bool enableStackIfDisabled = false);
     30    void DisableExpression(string name, bool disableStackIfEnabled = false);
     31    void SetExpression(string name, bool state, bool cascadeForStack = false);
     32    void SetExpression<T>(bool state, bool cascadeForStack = false) where T : Expression;
     33    void EnableExpression<T>(bool enableStackIfDisabled = false) where T : Expression;
     34    void DisableExpression<T>(bool disableStackIfEnabled = false) where T : Expression;
    3235  }
    3336}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs

    r14777 r14834  
    33
    44  using HeuristicLab.Common;
     5  using HeuristicLab.Problems.ProgramSynthesis.Push.Erc.Interfaces;
     6  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
    57
    68  public interface IReadOnlyPushConfiguration : IDeepCloneable {
    7     bool IsBooleanStackEnabled { get; }
    8     bool IsIntegerStackEnabled { get; }
    9     bool IsFloatStackEnabled { get; }
    10     bool IsCharStackEnabled { get; }
    11     bool IsStringStackEnabled { get; }
    12     bool IsCodeStackEnabled { get; }
    13     bool IsNameStackEnabled { get; }
    14     double ErcProbability { get; }
     9    IReadOnlyDictionary<StackTypes, bool> EnabledStacks { get; }
    1510    int EvalPushLimit { get; }
    1611    int MaxDepth { get; }
    1712    int MaxStringLength { get; }
     13    int MaxVectorLength { get; }
    1814    int MaxPointsInProgram { get; }
    1915    int MaxPointsInRandomExpression { get; }
    2016    bool TopLevelPushCode { get; }
    2117    bool TopLevelPopCode { get; }
    22     int MinRandomInteger { get; }
    23     int MaxRandomInteger { get; }
    24     double MinRandomFloat { get; }
    25     double MaxRandomFloat { get; }
    26     double NewErcNameProbability { get; }
    27 
     18    IReadOnlyErcOptions ErcOptions { get; }
    2819    IReadOnlyList<string> EnabledExpressions { get; }
    2920  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs

    r14777 r14834  
    33  using System.Collections.Generic;
    44  using System.Linq;
    5 
    6   using HeuristicLab.Common;
    7   using HeuristicLab.Core;
    8   using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    9   using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    10   using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    11   using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
     5  using Attributes;
     6  using Common;
     7  using Core;
     8  using Erc;
     9  using Erc.Interfaces;
     10  using Expressions;
     11  using Persistence.Default.CompositeSerializers.Storable;
     12  using Stack;
    1213
    1314  [StorableClass]
    14   public class PushConfiguration : NamedItem, IReadOnlyPushConfiguration, IEnabledExpressionsConfiguration {
    15     private static readonly string itemName = "Push Configuration";
     15  public class PushConfiguration : ParameterizedNamedItem, IReadOnlyPushConfiguration, IEnabledExpressionsConfiguration {
     16
     17
    1618
    1719    public PushConfiguration() {
    18       this.EvalPushLimit = 1024;
    19       this.MaxPointsInProgram = 128;
    20       this.MaxPointsInRandomExpression = 64;
    21       this.MaxDepth = 4;
    22       this.MaxStringLength = 64;
    23 
    24       this.TopLevelPushCode = true;
    25       this.TopLevelPopCode = false;
    26 
    27       this.MinRandomInteger = -128;
    28       this.MaxRandomInteger = 128;
    29       this.MinRandomFloat = -128D;
    30       this.MaxRandomFloat = 128D;
    31       this.NewErcNameProbability = 0.5;
    32       this.ErcProbability = 0.2;
    33 
    34       this.enabledExpressions = ExpressionTable.ExpressionNames.ToList();
     20      Name = "Push Configuration";
     21
     22      enabledExpressions = ExpressionTable.ExpressionNames.ToList();
     23      EnabledStacks = new Dictionary<StackTypes, bool>();
     24
     25      ErcOptions = new ErcOptions();
     26      EvalPushLimit = 1024;
     27      MaxPointsInProgram = 128;
     28      TopLevelPushCode = true;
     29      TopLevelPopCode = false;
     30      MaxPointsInRandomExpression = 64;
     31      MaxStringLength = 32;
     32      MaxVectorLength = 64;
     33      MaxDepth = 32;
     34
     35      InitEnabledStacks();
     36    }
     37
     38    private void InitEnabledStacks(bool state = true) {
     39      foreach (StackTypes type in Enum.GetValues(typeof(StackTypes))) {
     40        if (!EnabledStacks.ContainsKey(type))
     41          EnabledStacks.Add(type, state);
     42      }
    3543    }
    3644
     
    4149
    4250    public PushConfiguration(PushConfiguration origin, Cloner cloner) : base(origin, cloner) {
    43       this.EnabledExpressions = origin.EnabledExpressions.ToList();
    44 
    45       this.EvalPushLimit = origin.EvalPushLimit;
    46       this.MaxPointsInProgram = origin.MaxPointsInProgram;
    47       this.MaxPointsInRandomExpression = origin.MaxPointsInRandomExpression;
    48       this.MaxDepth = origin.MaxDepth;
    49       this.MaxStringLength = origin.MaxStringLength;
    50 
    51       this.TopLevelPushCode = origin.TopLevelPushCode;
    52       this.TopLevelPopCode = origin.TopLevelPopCode;
    53 
    54       this.MinRandomInteger = origin.MinRandomInteger;
    55       this.MaxRandomInteger = origin.MaxRandomInteger;
    56       this.MinRandomFloat = origin.MinRandomFloat;
    57       this.MaxRandomFloat = origin.MaxRandomFloat;
    58       this.NewErcNameProbability = origin.NewErcNameProbability;
    59       this.ErcProbability = origin.ErcProbability;
    60 
    61       this.isBooleanStackEnabled = origin.IsBooleanStackEnabled;
    62       this.isIntegerStackEnabled = origin.IsIntegerStackEnabled;
    63       this.isFloatStackEnabled = origin.IsFloatStackEnabled;
    64       this.isNameStackEnabled = origin.IsNameStackEnabled;
    65       this.isCodeStackEnabled = origin.IsCodeStackEnabled;
    66       this.isExecStackEnabled = origin.IsExecStackEnabled;
    67     }
     51      enabledExpressions = origin.EnabledExpressions.ToList();
     52      EnabledStacks = origin.EnabledStacks.ToDictionary(x => x.Key, x => x.Value);
     53
     54      ErcOptions = cloner.Clone(origin.ErcOptions);
     55      EvalPushLimit = origin.EvalPushLimit;
     56      MaxPointsInProgram = origin.MaxPointsInProgram;
     57      MaxPointsInRandomExpression = origin.MaxPointsInRandomExpression;
     58      TopLevelPushCode = origin.TopLevelPushCode;
     59      TopLevelPopCode = origin.TopLevelPopCode;
     60      MaxStringLength = origin.MaxStringLength;
     61      MaxVectorLength = origin.MaxVectorLength;
     62      MaxDepth = origin.MaxDepth;
     63    }
     64
     65    [StorableHook(HookType.AfterDeserialization)]
     66    // ReSharper disable once UnusedMember.Local
     67    private void AfterDeserialization() {
     68      // Ensures that all types added after last serialization are available in enabledStacks
     69      InitEnabledStacks(false);
     70    }
     71
     72    [Storable]
     73    public IDictionary<StackTypes, bool> EnabledStacks { get; set; }
     74
     75    IReadOnlyDictionary<StackTypes, bool> IReadOnlyPushConfiguration.EnabledStacks { get { return EnabledStacks as IReadOnlyDictionary<StackTypes, bool>; } }
    6876
    6977    public event EventHandler<EnabledExpressionsChangedEventArgs> EnabledExpressionsChanged;
    7078
    71 
    72     private readonly List<string> enabledExpressions = new List<string>();
    73 
    74     [Storable]
     79    [Storable]
     80    private readonly List<string> enabledExpressions;
     81
    7582    public IList<string> EnabledExpressions
    7683    {
    77       get
    78       {
    79         return enabledExpressions;
    80       }
     84      get { return enabledExpressions; }
    8185      set
    8286      {
     87        var removedExpressions = enabledExpressions.ToArray();
    8388        enabledExpressions.Clear();
    8489        enabledExpressions.AddRange(value);
    85       }
    86     }
    87 
    88     IReadOnlyList<string> IReadOnlyPushConfiguration.EnabledExpressions { get { return this.EnabledExpressions as IReadOnlyList<string>; } }
    89 
    90     [Storable]
    91     private bool isBooleanStackEnabled = true;
    92 
    93     public bool IsBooleanStackEnabled
    94     {
    95       get
    96       {
    97         return this.isBooleanStackEnabled;
    98       }
    99 
    100       set
    101       {
    102         if (this.isBooleanStackEnabled == value) return;
    103 
    104         this.isBooleanStackEnabled = value;
    105 
    106         if (this.isBooleanStackEnabled) EnableExpressionOfStack(StackTypes.Boolean);
    107         else DisableExpressionOfStack(StackTypes.Boolean);
    108       }
    109     }
    110 
    111     [Storable]
    112     private bool isIntegerStackEnabled = true;
    113 
    114     public bool IsIntegerStackEnabled
    115     {
    116       get
    117       {
    118         return this.isIntegerStackEnabled;
    119       }
    120 
    121       set
    122       {
    123         if (this.isIntegerStackEnabled == value) return;
    124 
    125         this.isIntegerStackEnabled = value;
    126 
    127         if (this.isIntegerStackEnabled) EnableExpressionOfStack(StackTypes.Integer);
    128         else DisableExpressionOfStack(StackTypes.Integer);
    129       }
    130     }
    131 
    132     [Storable]
    133     private bool isFloatStackEnabled = true;
    134 
    135     public bool IsFloatStackEnabled
    136     {
    137       get
    138       {
    139         return this.isFloatStackEnabled;
    140       }
    141 
    142       set
    143       {
    144         if (this.isFloatStackEnabled == value) return;
    145 
    146         this.isFloatStackEnabled = value;
    147 
    148         if (this.isFloatStackEnabled) EnableExpressionOfStack(StackTypes.Float);
    149         else DisableExpressionOfStack(StackTypes.Float);
    150       }
    151     }
    152 
    153     [Storable]
    154     private bool isCodeStackEnabled = true;
    155 
    156     public bool IsCodeStackEnabled
    157     {
    158       get
    159       {
    160         return this.isCodeStackEnabled;
    161       }
    162 
    163       set
    164       {
    165         if (this.isCodeStackEnabled == value) return;
    166 
    167         this.isCodeStackEnabled = value;
    168 
    169         if (this.isCodeStackEnabled) EnableExpressionOfStack(StackTypes.Code);
    170         else DisableExpressionOfStack(StackTypes.Code);
    171       }
    172     }
    173 
    174     [Storable]
    175     private bool isExecStackEnabled = true;
    176 
    177     public bool IsExecStackEnabled
    178     {
    179       get
    180       {
    181         return this.isExecStackEnabled;
    182       }
    183 
    184       set
    185       {
    186         if (this.isExecStackEnabled == value) return;
    187 
    188         this.isExecStackEnabled = value;
    189 
    190         if (this.isExecStackEnabled) EnableExpressionOfStack(StackTypes.Exec);
    191         else DisableExpressionOfStack(StackTypes.Exec);
    192       }
    193     }
    194 
    195     [Storable]
    196     private bool isCharStackEnabled = true;
    197 
    198     public bool IsCharStackEnabled
    199     {
    200       get
    201       {
    202         return this.isCharStackEnabled;
    203       }
    204 
    205       set
    206       {
    207         if (this.isCharStackEnabled == value) return;
    208 
    209         this.isCharStackEnabled = value;
    210 
    211         if (this.isCharStackEnabled) EnableExpressionOfStack(StackTypes.Char);
    212         else DisableExpressionOfStack(StackTypes.Char);
    213       }
    214     }
    215 
    216     [Storable]
    217     private bool isStringStackEnabled = true;
    218 
    219     public bool IsStringStackEnabled
    220     {
    221       get
    222       {
    223         return this.isStringStackEnabled;
    224       }
    225 
    226       set
    227       {
    228         if (this.isStringStackEnabled == value) return;
    229 
    230         this.isStringStackEnabled = value;
    231 
    232         if (this.isStringStackEnabled) EnableExpressionOfStack(StackTypes.String);
    233         else DisableExpressionOfStack(StackTypes.String);
    234       }
    235     }
    236 
    237     [Storable]
    238     private bool isNameStackEnabled = true;
    239 
    240     public bool IsNameStackEnabled
    241     {
    242       get
    243       {
    244         return this.isNameStackEnabled;
    245       }
    246 
    247       set
    248       {
    249         if (this.isNameStackEnabled == value) return;
    250 
    251         this.isNameStackEnabled = value;
    252 
    253         if (this.isNameStackEnabled) EnableExpressionOfStack(StackTypes.Name);
    254         else DisableExpressionOfStack(StackTypes.Name);
    255       }
    256     }
    257 
    258     [Storable]
    259     public double ErcProbability { get; set; }
     90
     91        if (EnabledExpressionsChanged != null) {
     92          EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(value, removedExpressions));
     93        }
     94      }
     95    }
     96
     97    IReadOnlyList<string> IReadOnlyPushConfiguration.EnabledExpressions { get { return EnabledExpressions as IReadOnlyList<string>; } }
     98
     99    [Storable]
     100    public ErcOptions ErcOptions { get; set; }
     101
     102    IReadOnlyErcOptions IReadOnlyPushConfiguration.ErcOptions { get { return ErcOptions; } }
    260103
    261104    /// <summary>
     
    309152    public int MaxStringLength { get; set; }
    310153
    311     /// <summary>
    312     ///     The minimum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND.
    313     /// </summary>
    314     [Storable]
    315     public int MinRandomInteger { get; set; }
    316 
    317     /// <summary>
    318     ///     The maximum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND.
    319     /// </summary>
    320     [Storable]
    321     public int MaxRandomInteger { get; set; }
    322 
    323     /// <summary>
    324     ///     The minimum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND.
    325     /// </summary>
    326     [Storable]
    327     public double MinRandomFloat { get; set; }
    328 
    329     /// <summary>
    330     ///     The maximum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND.
    331     /// </summary>
    332     [Storable]
    333     public double MaxRandomFloat { get; set; }
    334 
    335     /// <summary>
    336     ///     The probability that the selection of the ephemeral
    337     ///     random NAME constant for inclusion in randomly generated code will produce a new name
    338     ///     (rather than a name that was previously generated).
    339     /// </summary>
    340     [Storable]
    341     public double NewErcNameProbability { get; set; }
     154    [Storable]
     155    public int MaxVectorLength { get; set; }
    342156
    343157    public void EnableExpressionOfStack(StackTypes types) {
    344       foreach (var name in ExpressionTable.StackTypeToNamesTable[types]) {
    345         EnableExpression(name);
     158      var names = ExpressionTable.StackTypeToNamesTable[types]
     159        .Except(EnabledExpressions)
     160        .ToArray();
     161
     162      foreach (var name in names)
     163        EnabledExpressions.Add(name);
     164
     165      if (EnabledExpressionsChanged != null) {
     166        EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(names, new string[0]));
    346167      }
    347168    }
    348169
    349170    public void DisableExpressionOfStack(StackTypes types) {
    350       foreach (var name in ExpressionTable.StackTypeToNamesTable[types]) {
    351         DisableExpression(name);
    352       }
    353     }
    354 
    355     public void EnableExpression(string name) {
     171      var names = ExpressionTable.StackTypeToNamesTable[types]
     172        .Intersect(EnabledExpressions)
     173        .ToArray();
     174
     175      foreach (var name in names)
     176        EnabledExpressions.Remove(name);
     177
     178      if (EnabledExpressionsChanged != null) {
     179        EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(new string[0], names));
     180      }
     181    }
     182
     183    public void EnableExpression(string name, bool enableStackIfDisabled = false) {
    356184      if (EnabledExpressions.Contains(name)) return;
    357185
    358186      EnabledExpressions.Add(name);
    359187
    360       if (EnabledExpressionsChanged != null) {
    361         EnabledExpressionsChanged.Invoke(this, new EnabledExpressionsChangedEventArgs(
     188      if (enableStackIfDisabled) {
     189        var type = ExpressionTable.TypeToNameTable.Single(x => x.Value == name).Key;
     190        var attribute = ExpressionTable.TypeToAttributeTable[type];
     191        EnabledStacks[attribute.StackType] = true;
     192      }
     193
     194      if (EnabledExpressionsChanged != null) {
     195        EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(
    362196          new[] { name },
    363197          new string[0]));
     
    365199    }
    366200
    367     public void DisableExpression(string name) {
     201    public void DisableExpression(string name, bool disableStackIfEnabled = false) {
    368202      if (!EnabledExpressions.Contains(name)) return;
    369203
    370204      EnabledExpressions.Remove(name);
    371205
    372       if (EnabledExpressionsChanged != null) {
    373         EnabledExpressionsChanged.Invoke(this, new EnabledExpressionsChangedEventArgs(
     206      if (disableStackIfEnabled) {
     207        var type = ExpressionTable.TypeToNameTable.Single(x => x.Value == name).Key;
     208        var attribute = ExpressionTable.TypeToAttributeTable[type];
     209        EnabledStacks[attribute.StackType] = false;
     210      }
     211
     212      if (EnabledExpressionsChanged != null) {
     213        EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(
    374214          new string[0],
    375215          new[] { name }));
     
    377217    }
    378218
    379     public void EnableExpression<T>() where T : Expression {
     219    public void EnableExpression<T>(bool enableStackIfDisabled = false) where T : Expression {
    380220      var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(PushExpressionAttribute));
    381       EnableExpression(attribute.ExpressionName);
    382     }
    383 
    384     public void DisableExpression<T>() where T : Expression {
     221      EnableExpression(attribute.ExpressionName, enableStackIfDisabled);
     222    }
     223
     224    public void DisableExpression<T>(bool disableStackIfEnabled = false) where T : Expression {
    385225      var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(PushExpressionAttribute));
    386       DisableExpression(attribute.ExpressionName);
    387     }
    388 
    389     public void EnableStack(StackTypes types) {
    390       SetStack(types, true);
    391     }
    392 
    393     public void DisableStack(StackTypes types) {
    394       SetStack(types, false);
    395     }
    396 
    397     public void SetStack(StackTypes types, bool value) {
    398       switch (types) {
    399         case StackTypes.Boolean:
    400           IsBooleanStackEnabled = value;
    401           break;
    402         case StackTypes.Integer:
    403           IsIntegerStackEnabled = value;
    404           break;
    405         case StackTypes.Float:
    406           IsFloatStackEnabled = value;
    407           break;
    408         case StackTypes.Name:
    409           IsNameStackEnabled = value;
    410           break;
    411         case StackTypes.Code:
    412           IsCodeStackEnabled = value;
    413           break;
    414         case StackTypes.Exec:
    415           this.IsExecStackEnabled = value;
    416           break;
    417         case StackTypes.Char:
    418           this.IsCharStackEnabled = value;
    419           break;
    420         case StackTypes.String:
    421           this.IsStringStackEnabled = value;
    422           break;
    423         default: throw new InvalidOperationException("Stacktype unknown");
    424       }
     226      DisableExpression(attribute.ExpressionName, disableStackIfEnabled);
     227    }
     228
     229    public void SetExpression(string name, bool state, bool cascadeForStack = false) {
     230      if (state) EnableExpression(name, cascadeForStack);
     231      else DisableExpression(name, cascadeForStack);
     232    }
     233
     234    public void SetExpression<T>(bool state, bool cascadeForStack = false) where T : Expression {
     235      if (state) EnableExpression<T>(cascadeForStack);
     236      else DisableExpression<T>(cascadeForStack);
     237    }
     238
     239    public void EnableStack(StackTypes type, bool enableExpressions = false) {
     240      EnabledStacks[type] = true;
     241
     242      if (enableExpressions)
     243        EnableExpressionOfStack(type);
     244    }
     245
     246    public void DisableStack(StackTypes type, bool disableExpressions = false) {
     247      EnabledStacks[type] = false;
     248
     249      if (disableExpressions)
     250        DisableExpressionOfStack(type);
     251    }
     252
     253    public void SetStack(StackTypes type, bool state, bool cascadeForExpressions = false) {
     254      if (state) EnableStack(type, cascadeForExpressions);
     255      else DisableStack(type, cascadeForExpressions);
    425256    }
    426257
Note: See TracChangeset for help on using the changeset viewer.