Changeset 16947


Ignore:
Timestamp:
05/13/19 15:16:40 (2 weeks ago)
Author:
mkommend
Message:

#2521: Adapted GP basic problems to use read-only value parameters.

Location:
branches/2521_ProblemRefactoring
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessCovarianceOptimizationProblem.cs

    r16813 r16947  
    6060    private static readonly CovarianceSquaredExponentialIso sqrExpIso;
    6161
    62     private static readonly SymbolicExpressionTreeEncoding defaultEncoding;
    63 
    6462    static GaussianProcessCovarianceOptimizationProblem() {
    6563      // cumbersome initialization because of ConstrainedValueParameters
     
    187185      Encoding.TreeLength = 10;
    188186      Encoding.TreeDepth = 5;
     187      Encoding.GrammarParameter.ReadOnly = false;
    189188      Encoding.Grammar = g;
     189      Encoding.GrammarParameter.ReadOnly = true;
    190190    }
    191191
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeEncoding.cs

    r16723 r16947  
    2525using System.Collections.Generic;
    2626using System.Linq;
     27using HEAL.Attic;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Core;
     
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    32 using HEAL.Attic;
    3333using HeuristicLab.PluginInfrastructure;
    3434
     
    167167      treeDepthParameter = new FixedValueParameter<IntValue>(Name + ".Maximum Tree Depth", "Maximal depth of the symbolic expression. The minimum depth needed for the algorithm is 3 because two levels are reserved for the ProgramRoot and the Start symbol.", new IntValue(maximumDepth));
    168168      grammarParameter = new ValueParameter<ISymbolicExpressionGrammar>(Name + ".Grammar", "The grammar that should be used for symbolic expression tree.", grammar);
     169      grammarParameter.ReadOnly = true;
    169170      functionDefinitionsParameter = new FixedValueParameter<IntValue>(Name + ".Function Definitions", "Maximal number of automatically defined functions", new IntValue(0));
    170171      functionArgumentsParameter = new FixedValueParameter<IntValue>(Name + ".Function Arguments", "Maximal number of arguments of automatically defined functions.", new IntValue(0));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs

    r16946 r16947  
    8282      get { return (IValueParameter<BoolMatrix>)Parameters["World"]; }
    8383    }
    84     public IValueParameter<IntValue> MaxTimeStepsParameter {
    85       get { return (IValueParameter<IntValue>)Parameters["MaximumTimeSteps"]; }
     84    public IFixedValueParameter<IntValue> MaxTimeStepsParameter {
     85      get { return (IFixedValueParameter<IntValue>)Parameters["MaximumTimeSteps"]; }
    8686    }
    8787    #endregion
     
    9292      set { WorldParameter.Value = value; }
    9393    }
    94     public IntValue MaxTimeSteps {
    95       get { return MaxTimeStepsParameter.Value; }
    96       set { MaxTimeStepsParameter.Value = value; }
     94    public int MaxTimeSteps {
     95      get { return MaxTimeStepsParameter.Value.Value; }
     96      set { MaxTimeStepsParameter.Value.Value = value; }
    9797    }
    9898    #endregion
     
    119119      BoolMatrix world = new BoolMatrix(ToBoolMatrix(santaFeAntTrail));
    120120      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
    121       Parameters.Add(new ValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
     121      Parameters.Add(new FixedValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
    122122
    123123      var g = new SimpleSymbolicExpressionGrammar();
     
    128128      Encoding.TreeLength = 20;
    129129      Encoding.TreeDepth = 10;
     130      Encoding.GrammarParameter.ReadOnly = false;
    130131      Encoding.Grammar = g;
    131       base.BestKnownQuality = 89;
    132       base.Encoding.GrammarParameter.ReadOnly = true;
     132      Encoding.GrammarParameter.ReadOnly = true;
     133
     134      BestKnownQuality = 89;
     135      BestKnownQualityParameter.ReadOnly = true;
    133136    }
    134137
    135138
    136139    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
    137       var interpreter = new Interpreter(tree, World, MaxTimeSteps.Value);
     140      var interpreter = new Interpreter(tree, World, MaxTimeSteps);
    138141      interpreter.Run();
    139142      return interpreter.FoodEaten;
     
    146149
    147150      if (!results.ContainsKey(bestSolutionResultName)) {
    148         results.Add(new Result(bestSolutionResultName, new Solution(World, trees[bestIdx], MaxTimeSteps.Value, qualities[bestIdx])));
     151        results.Add(new Result(bestSolutionResultName, new Solution(World, trees[bestIdx], MaxTimeSteps, qualities[bestIdx])));
    149152      } else if (((Solution)(results[bestSolutionResultName].Value)).Quality < qualities[bestIdx]) {
    150         results[bestSolutionResultName].Value = new Solution(World, trees[bestIdx], MaxTimeSteps.Value, qualities[bestIdx]);
     153        results[bestSolutionResultName].Value = new Solution(World, trees[bestIdx], MaxTimeSteps, qualities[bestIdx]);
    151154      }
    152155    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs

    r16946 r16947  
    8686      Encoding.TreeLength = 100;
    8787      Encoding.TreeDepth = 17;
    88       Encoding.GrammarParameter.ReadOnly = true;
    8988
    9089      UpdateGrammar();
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs

    r16813 r16947  
    9696        g.AddTerminalSymbol(string.Format("{0}", i));
    9797
     98      Encoding.GrammarParameter.ReadOnly = false;
    9899      Encoding.Grammar = g;
     100      Encoding.GrammarParameter.ReadOnly = true;
    99101
     102      BestKnownQualityParameter.ReadOnly = false;
    100103      BestKnownQuality = Math.Pow(2, NumberOfBits); // this is a benchmark problem (the best achievable quality is known for a given number of bits)
     104      BestKnownQualityParameter.ReadOnly = true;
    101105    }
    102106
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs

    r16946 r16947  
    8686        new IntValue(11)));
    8787
    88       var g = new SimpleSymbolicExpressionGrammar(); // will be replaced in update grammar
    89       Encoding = new SymbolicExpressionTreeEncoding(g, 100, 17);
    90       Encoding.GrammarParameter.ReadOnly = true;
     88      Encoding.TreeLength = 100;
     89      Encoding.TreeDepth = 17;
    9190
    9291      UpdateGrammar();
     
    115114      Encoding.GrammarParameter.ReadOnly = true;
    116115
     116      BestKnownQualityParameter.ReadOnly = false;
    117117      BestKnownQuality = Math.Pow(2, NumberOfBits); // this is a benchmark problem (the best achievable quality is known for a given number of bits)
     118      BestKnownQualityParameter.ReadOnly = true;
    118119    }
    119120
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs

    r16813 r16947  
    7878      Encoding.TreeLength = 1000;
    7979      Encoding.TreeDepth = 17;
     80      Encoding.GrammarParameter.ReadOnly = false;
    8081      Encoding.Grammar = g;
     82      Encoding.GrammarParameter.ReadOnly = true;
    8183    }
    8284
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Problem.cs

    r16946 r16947  
    7373    }
    7474
    75     public Problem() : base(new SymbolicExpressionTreeEncoding()) {
     75    public Problem() : base(new SymbolicExpressionTreeEncoding(new Grammar(), maximumLength: 1000, maximumDepth: 10)) {
    7676      DirectoryValue robocodeDir = new DirectoryValue { Value = @"robocode" };
    7777
     
    8484      Parameters.Add(new ValueParameter<EnemyCollection>(EnemiesParameterName, "The enemies that should be battled.", robotList));
    8585
    86       Encoding.TreeLength = 1000;
    87       Encoding.TreeDepth = 10;
    88       Encoding.Grammar = new Grammar();
    89       Encoding.GrammarParameter.ReadOnly = true;
    9086      Encoding.FunctionArguments = 0;
    9187      Encoding.FunctionDefinitions = 0;
Note: See TracChangeset for help on using the changeset viewer.