Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/02/17 20:42:40 (8 years ago)
Author:
pkimmesw
Message:

#2665 Made ErcOptions checkable

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

Legend:

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

    r14834 r14905  
    2222    IList<string> EnabledExpressions { get; }
    2323
    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);
     24    void EnableStack(StackTypes types, bool enableExpressions = true, bool enableDependencies = true);
     25    void DisableStack(StackTypes type, bool disableExpressions = true, bool enableDepenencies = true);
     26    void SetStack(StackTypes type, bool state, bool setExpressions = true, bool setDependencies = true);
    2727    void EnableExpressionOfStack(StackTypes types);
    28     void DisableExpressionOfStack(StackTypes types);
     28    void DisableExpressionsOfStack(StackTypes types);
    2929    void EnableExpression(string name, bool enableStackIfDisabled = false);
    3030    void DisableExpression(string name, bool disableStackIfEnabled = false);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs

    r14897 r14905  
    33  using System.Collections.Generic;
    44  using System.Linq;
    5   using Attributes;
    65  using Base.Erc;
    76  using Common;
     
    174173
    175174        if (types.HasFlag(type))
    176           EnableStack(type, true);
     175          EnableStack(type, false, true);
    177176      }
    178177    }
    179178
    180179    public void EnableExpressionOfStack(StackTypes types) {
    181       var names = ExpressionTable.StackTypeToNamesTable[types]
    182         .Except(EnabledExpressions)
    183         .ToArray();
    184 
    185       foreach (var name in names)
     180      EnableExpressions(ExpressionTable.StackTypeToNamesTable[types]);
     181    }
     182
     183    public void EnableExpressionDependentOnStack(StackTypes types) {
     184      var names = ExpressionTable.StackDependencyToNamesTable[types].Where(
     185        name => {
     186          var type = ExpressionTable.NameToTypeTable[name];
     187          var attribute = ExpressionTable.TypeToAttributeTable[type];
     188
     189          return (attribute.StackType | attribute.AdditionalStackDependencies)
     190            .ToEnumerable()
     191            .All(st => enabledStacks.ContainsKey(st) && enabledStacks[st]);
     192        });
     193
     194      EnableExpressions(names);
     195    }
     196
     197    private void EnableExpressions(IEnumerable<string> names) {
     198      foreach (var name in names.Except(EnabledExpressions))
    186199        EnabledExpressions.Add(name);
    187200
     
    191204    }
    192205
    193     public void DisableExpressionOfStack(StackTypes types) {
    194       var names = ExpressionTable.StackTypeToNamesTable[types]
    195         .Intersect(EnabledExpressions)
    196         .ToArray();
    197 
    198       foreach (var name in names)
     206    public void DisableExpressionsOfStack(StackTypes types) {
     207      DisableExpressions(ExpressionTable.StackTypeToNamesTable[types]);
     208    }
     209
     210    public void DisableExpressionsDependentOnStack(StackTypes types) {
     211      var names = ExpressionTable.StackDependencyToNamesTable
     212          .Where(pair => pair.Key.HasFlag(types))
     213          .SelectMany(pair => pair.Value);
     214
     215      DisableExpressions(names);
     216    }
     217
     218    private void DisableExpressions(IEnumerable<string> names) {
     219      foreach (var name in names.Intersect(EnabledExpressions))
    199220        EnabledExpressions.Remove(name);
    200221
     
    241262
    242263    public void EnableExpression<T>(bool enableStackIfDisabled = false) where T : Expression {
    243       var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(PushExpressionAttribute));
     264      var attribute = ExpressionTable.TypeToAttributeTable[typeof(T)];
    244265      EnableExpression(attribute.ExpressionName, enableStackIfDisabled);
    245266    }
    246267
    247268    public void DisableExpression<T>(bool disableStackIfEnabled = false) where T : Expression {
    248       var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(PushExpressionAttribute));
     269      var attribute = ExpressionTable.TypeToAttributeTable[typeof(T)];
    249270      DisableExpression(attribute.ExpressionName, disableStackIfEnabled);
    250271    }
     
    260281    }
    261282
    262     public void EnableStack(StackTypes type, bool enableExpressions = false) {
     283    public void EnableStack(StackTypes type, bool enableExpressions = true, bool enableDependencies = true) {
    263284      enabledStacks[type] = true;
    264285
    265       if (enableExpressions)
    266         EnableExpressionOfStack(type);
    267     }
    268 
    269     public void DisableStack(StackTypes type, bool disableExpressions = false) {
     286      if (enableExpressions) EnableExpressionOfStack(type);
     287      if (enableDependencies) EnableExpressionDependentOnStack(type);
     288    }
     289
     290    public void DisableStack(StackTypes type, bool disableExpressions = true, bool disableDependencies = true) {
    270291      enabledStacks[type] = false;
    271292
    272       if (disableExpressions)
    273         DisableExpressionOfStack(type);
    274     }
    275 
    276     public void SetStack(StackTypes type, bool state, bool cascadeForExpressions = false) {
    277       if (state) EnableStack(type, cascadeForExpressions);
    278       else DisableStack(type, cascadeForExpressions);
     293      if (disableExpressions) DisableExpressionsOfStack(type);
     294      if (disableDependencies) DisableExpressionsDependentOnStack(type);
     295    }
     296
     297    public void SetStack(StackTypes type, bool state, bool setExpressions = true, bool setDependencies = true) {
     298      if (state) EnableStack(type, setExpressions, setDependencies);
     299      else DisableStack(type, setExpressions, setDependencies);
    279300    }
    280301
Note: See TracChangeset for help on using the changeset viewer.