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
Files:
6 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
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/BooleanExpressions.cs

    r14875 r14905  
    1111  [PushExpression(StackTypes.Boolean, "BOOLEAN.AND")]
    1212  public class BooleanAndExpression : StatelessExpression {
    13     public override bool Eval(IInternalPushInterpreter interpreter) {
    14       if (interpreter.BooleanStack.Count < 2)
    15         return false;
     13    public bool IsNoop(IInternalPushInterpreter interpreter) {
     14      return interpreter.BooleanStack.Count < 2;
     15    }
    1616
     17    public void TryEval(IInternalPushInterpreter interpreter) {
    1718      var first = interpreter.BooleanStack.Pop();
    1819      var second = interpreter.BooleanStack.Top;
     
    2021
    2122      interpreter.BooleanStack.SetTop(result);
     23    }
     24
     25    public override bool Eval(IInternalPushInterpreter interpreter) {
     26      if (IsNoop(interpreter))
     27        return false;
     28
     29      TryEval(interpreter);
    2230      return true;
    2331    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/Expression.cs

    r14834 r14905  
    22  using System;
    33  using System.Collections.Generic;
    4 
    5   using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    64  using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;
    75
     
    108  [Serializable]
    119  public abstract class Expression : IPooledObject {
    12     public bool IsProgram { get { return this.GetType() == typeof(PushProgram); } }
     10    public bool IsProgram { get { return GetType() == typeof(PushProgram); } }
    1311
    1412    public static readonly IReadOnlyCollection<Expression> EmptyContainer = new Expression[0];
     
    1816      get
    1917      {
    20         var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(PushExpressionAttribute));
    21 
    22         return attribute != null
    23           ? attribute.ExpressionName
    24           : string.Empty;
     18        return ExpressionTable.TypeToAttributeTable[GetType()].ExpressionName;
    2519      }
    2620    }
     21
     22    //public abstract bool IsNoop(IInternalPushInterpreter interpreter);
    2723
    2824    public abstract bool Eval(IInternalPushInterpreter interpreter);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteProblem.cs

    r14897 r14905  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite {
    2   using System.Linq;
    32  using Common;
    43  using Configuration;
    54  using Core;
    65  using Encodings.IntegerVectorEncoding;
    7   using Expressions;
    86  using HeuristicLab.BenchmarkSuite.Problems;
    97  using Instances;
     
    4644      config.SetEnabledStacks((StackTypes)data.EnabledDataTypes);
    4745
    48       // update enabled stack types
    49       foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {
    50         var enable = config.EnabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]).Any();
    51         config.SetStack(stackType, enable);
    52       }
    53 
    5446      Encoding.Bounds[0, 0] = 0;
    5547      Encoding.Bounds[0, 1] = config.EnabledExpressions.Count;
     
    6355      IReadOnlyPushConfiguration config,
    6456      IPushEvaluator evaluator) {
    65       return new PushBenchmarkSuiteSolution(vector, bestQuality, random, config, (PushBenchmarkSuiteEvaluator)PushEvaluator.Clone());
     57      return new PushBenchmarkSuiteSolution(vector, bestQuality, random, (IReadOnlyPushConfiguration)config.Clone(), (PushBenchmarkSuiteEvaluator)PushEvaluator.Clone());
    6658    }
    6759  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs

    r14834 r14905  
    5252
    5353      if (e.Node.Parent == null) {
    54         Content.SetStack(stackType, e.Node.Checked, true);
     54        Content.SetStack(stackType, e.Node.Checked, true, false);
    5555        SetStackNodeText(e.Node);
    5656        foreach (var subNode in e.Node.Nodes.OfType<TreeNode>().Where(n => n.Checked != e.Node.Checked))
Note: See TracChangeset for help on using the changeset viewer.