Changeset 12899


Ignore:
Timestamp:
08/25/15 14:18:07 (6 years ago)
Author:
gkronber
Message:

#2422: ported lawn mower problem to use BasicProblem and SymbolicExpressionTreeEncoding

Location:
trunk/sources
Files:
2 added
2 deleted
12 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r12895 r12899  
    438438EndProject
    439439Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.ArtificialAnt.Views-3.5", "HeuristicLab.Problems.ArtificialAnt.Views\3.5\HeuristicLab.Problems.ArtificialAnt.Views-3.5.csproj", "{0ABD192C-926A-47A9-878C-79B6AF5C07C9}"
     440EndProject
     441Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.LawnMower-3.4", "HeuristicLab.Problems.LawnMower\3.4\HeuristicLab.Problems.LawnMower-3.4.csproj", "{9B44B886-729D-49B2-B887-4BDCACB91110}"
     442EndProject
     443Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.LawnMower.Views-3.4", "HeuristicLab.Problems.LawnMower.Views\3.4\HeuristicLab.Problems.LawnMower.Views-3.4.csproj", "{E186E7BD-E90E-4027-9965-D5E0DBEB00E8}"
    440444EndProject
    441445Global
     
    21412145    {0ABD192C-926A-47A9-878C-79B6AF5C07C9}.Release|x86.ActiveCfg = Release|x86
    21422146    {0ABD192C-926A-47A9-878C-79B6AF5C07C9}.Release|x86.Build.0 = Release|x86
     2147    {9B44B886-729D-49B2-B887-4BDCACB91110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     2148    {9B44B886-729D-49B2-B887-4BDCACB91110}.Debug|Any CPU.Build.0 = Debug|Any CPU
     2149    {9B44B886-729D-49B2-B887-4BDCACB91110}.Debug|x64.ActiveCfg = Debug|x64
     2150    {9B44B886-729D-49B2-B887-4BDCACB91110}.Debug|x64.Build.0 = Debug|x64
     2151    {9B44B886-729D-49B2-B887-4BDCACB91110}.Debug|x86.ActiveCfg = Debug|x86
     2152    {9B44B886-729D-49B2-B887-4BDCACB91110}.Debug|x86.Build.0 = Debug|x86
     2153    {9B44B886-729D-49B2-B887-4BDCACB91110}.Release|Any CPU.ActiveCfg = Release|Any CPU
     2154    {9B44B886-729D-49B2-B887-4BDCACB91110}.Release|Any CPU.Build.0 = Release|Any CPU
     2155    {9B44B886-729D-49B2-B887-4BDCACB91110}.Release|x64.ActiveCfg = Release|x64
     2156    {9B44B886-729D-49B2-B887-4BDCACB91110}.Release|x64.Build.0 = Release|x64
     2157    {9B44B886-729D-49B2-B887-4BDCACB91110}.Release|x86.ActiveCfg = Release|x86
     2158    {9B44B886-729D-49B2-B887-4BDCACB91110}.Release|x86.Build.0 = Release|x86
     2159    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     2160    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
     2161    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Debug|x64.ActiveCfg = Debug|x64
     2162    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Debug|x64.Build.0 = Debug|x64
     2163    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Debug|x86.ActiveCfg = Debug|x86
     2164    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Debug|x86.Build.0 = Debug|x86
     2165    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
     2166    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Release|Any CPU.Build.0 = Release|Any CPU
     2167    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Release|x64.ActiveCfg = Release|x64
     2168    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Release|x64.Build.0 = Release|x64
     2169    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Release|x86.ActiveCfg = Release|x86
     2170    {E186E7BD-E90E-4027-9965-D5E0DBEB00E8}.Release|x86.Build.0 = Release|x86
    21432171  EndGlobalSection
    21442172  GlobalSection(SolutionProperties) = preSolution
     
    21492177    {0C67A033-F6D9-4237-B3CA-C033A44706BE} = {D1B1DE45-F9C7-4FBF-B73C-E759BC4223D5}
    21502178    {3083C7AA-5AF4-4C75-BA19-B69B86E2F66A} = {D1B1DE45-F9C7-4FBF-B73C-E759BC4223D5}
     2179    {9A04599C-D608-4240-8DA6-D41F51C515A3} = {D1B1DE45-F9C7-4FBF-B73C-E759BC4223D5}
     2180    {71CDE004-C50F-48DF-858E-AB0AAA3537BC} = {D1B1DE45-F9C7-4FBF-B73C-E759BC4223D5}
    21512181  EndGlobalSection
    21522182EndGlobal
  • trunk/sources/HeuristicLab.Problems.LawnMower.Views/3.3/HeuristicLab.Problems.LawnMower.Views-3.3.csproj

    r12846 r12899  
    176176    <ProjectReference Include="..\..\HeuristicLab.Problems.LawnMower\3.3\HeuristicLab.Problems.LawnMower-3.3.csproj">
    177177      <Project>{9A04599C-D608-4240-8DA6-D41F51C515A3}</Project>
    178       <Name>HeuristicLab.Problems.LawnMower</Name>
     178      <Name>HeuristicLab.Problems.LawnMower-3.3</Name>
    179179      <Private>False</Private>
    180180    </ProjectReference>
  • trunk/sources/HeuristicLab.Problems.LawnMower.Views/3.4/Plugin.cs.frame

    r12753 r12899  
    2323
    2424namespace HeuristicLab.Problems.LawnMower.Views {
    25   [Plugin("HeuristicLab.Problems.LawnMower.Views", "Lawn mower demo problem for genetic programming (views)", "3.3.12.$WCREV$")]
    26   [PluginFile("HeuristicLab.Problems.LawnMower.Views-3.3.dll", PluginFileType.Assembly)]
     25  [Plugin("HeuristicLab.Problems.LawnMower.Views", "Lawn mower demo problem for genetic programming (views)", "3.4.0.$WCREV$")]
     26  [PluginFile("HeuristicLab.Problems.LawnMower.Views-3.4.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Core", "3.3")]
    2828  [PluginDependency("HeuristicLab.Core.Views", "3.3")]
     
    3030  [PluginDependency("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views", "3.4")]
    3131  [PluginDependency("HeuristicLab.MainForm", "3.3")]
    32   [PluginDependency("HeuristicLab.Problems.LawnMower", "3.3")]
     32  [PluginDependency("HeuristicLab.Problems.LawnMower", "3.4")]
    3333  public class HeuristicLabProblemsLawnMowerViewsPlugin : PluginBase {
    3434  }
  • trunk/sources/HeuristicLab.Problems.LawnMower.Views/3.4/Properties/AssemblyInfo.cs.frame

    r12753 r12899  
    5252// You can specify all the values or you can default the Build and Revision Numbers
    5353// by using the '*' as shown below:
    54 [assembly: AssemblyVersion("3.3.0.0")]
    55 [assembly: AssemblyFileVersion("3.3.12.$WCREV$")]
     54[assembly: AssemblyVersion("3.4.0.0")]
     55[assembly: AssemblyFileVersion("3.4.0.$WCREV$")]
  • trunk/sources/HeuristicLab.Problems.LawnMower.Views/3.4/SolutionProgramView.cs

    r12012 r12899  
    4949      }
    5050    }
    51 
    5251  }
    5352}
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.3/HeuristicLab.Problems.LawnMower-3.3.csproj

    r12846 r12899  
    116116  <ItemGroup>
    117117    <Compile Include="BestSolutionAnalyzer.cs" />
     118    <Compile Include="Symbols\Constant.cs">
     119      <SubType>Code</SubType>
     120    </Compile>
     121    <Compile Include="Symbols\ConstantTreeNode.cs">
     122      <SubType>Code</SubType>
     123    </Compile>
     124    <Compile Include="Symbols\Forward.cs">
     125      <SubType>Code</SubType>
     126    </Compile>
     127    <Compile Include="Symbols\Frog.cs">
     128      <SubType>Code</SubType>
     129    </Compile>
     130    <Compile Include="Symbols\Left.cs">
     131      <SubType>Code</SubType>
     132    </Compile>
     133    <Compile Include="Symbols\Prog.cs">
     134      <SubType>Code</SubType>
     135    </Compile>
     136    <Compile Include="Symbols\Sum.cs">
     137      <SubType>Code</SubType>
     138    </Compile>
    118139    <None Include="HeuristicLab.snk" />
    119140    <None Include="Plugin.cs.frame" />
     
    126147    <Compile Include="Plugin.cs" />
    127148    <Compile Include="Properties\AssemblyInfo.cs" />
    128     <Compile Include="Symbols\Constant.cs" />
    129     <Compile Include="Symbols\ConstantTreeNode.cs" />
    130     <Compile Include="Symbols\Forward.cs" />
    131     <Compile Include="Symbols\Frog.cs" />
    132     <Compile Include="Symbols\Left.cs" />
    133     <Compile Include="Symbols\Prog.cs" />
    134     <Compile Include="Symbols\Sum.cs" />
    135149  </ItemGroup>
    136150  <ItemGroup>
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Problem.cs

    r12504 r12899  
    3333namespace HeuristicLab.Problems.LawnMower {
    3434  [StorableClass]
    35   [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 160)]
    3635  [Item("Lawn Mower Problem", "The lawn mower demo problem for genetic programming.")]
    3736  public class Problem : SingleObjectiveHeuristicOptimizationProblem<Evaluator, ISymbolicExpressionTreeCreator> {
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.4/Interpreter.cs

    r12012 r12899  
    5959
    6060    private static Tuple<int, int> EvaluateLawnMowerProgram(ISymbolicExpressionTreeNode node, MowerState mowerState, bool[,] lawn, IEnumerable<ISymbolicExpressionTreeNode> adfs) {
    61       if (mowerState.Energy <= 0) return new Tuple<int, int>(0, 0);
     61      if (mowerState.Energy <= 0) return Tuple.Create(0, 0);
    6262
    6363      if (node.Symbol is ProgramRootSymbol) {
     
    6565      } else if (node.Symbol is StartSymbol) {
    6666        return EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
    67       } else if (node.Symbol is Left) {
     67      } else if (node.Symbol.Name == "Left") {
    6868        switch (mowerState.Heading) {
    6969          case Heading.East: mowerState.Heading = Heading.North;
     
    7878        }
    7979        return new Tuple<int, int>(0, 0);
    80       } else if (node.Symbol is Forward) {
     80      } else if (node.Symbol.Name == "Forward") {
    8181        int dRow = 0;
    8282        int dCol = 0;
     
    9797        uint newRow = (uint)((mowerState.Position.Item1 + lawn.GetLength(0) + dRow) % lawn.GetLength(0));
    9898        uint newColumn = (uint)((mowerState.Position.Item2 + lawn.GetLength(1) + dCol) % lawn.GetLength(1));
    99         mowerState.Position = new Tuple<uint, uint>(newRow, newColumn);
     99        mowerState.Position = Tuple.Create(newRow, newColumn);
    100100        mowerState.Energy = mowerState.Energy - 1;
    101101        lawn[newRow, newColumn] = true;
    102         return new Tuple<int, int>(0, 0);
    103       } else if (node.Symbol is Constant) {
    104         var constNode = node as ConstantTreeNode;
    105         return constNode.Value;
    106       } else if (node.Symbol is Sum) {
     102        return Tuple.Create(0, 0);
     103      } else if (node.Symbol.Name == "Sum") {
    107104        var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
    108105        var q = EvaluateLawnMowerProgram(node.GetSubtree(1), mowerState, lawn, adfs);
    109         return new Tuple<int, int>(p.Item1 + q.Item1,
    110           p.Item2 + q.Item2);
    111       } else if (node.Symbol is Prog) {
     106        return Tuple.Create(p.Item1 + q.Item1, p.Item2 + q.Item2);
     107      } else if (node.Symbol.Name == "Prog") {
    112108        EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
    113109        return EvaluateLawnMowerProgram(node.GetSubtree(1), mowerState, lawn, adfs);
    114       } else if (node.Symbol is Frog) {
     110      } else if (node.Symbol.Name == "Frog") {
    115111        var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
    116112        int x = p.Item1;
     
    120116        var newRow = (uint)((mowerState.Position.Item1 + x) % lawn.GetLength(0));
    121117        var newCol = (uint)((mowerState.Position.Item2 + y) % lawn.GetLength(1));
    122         mowerState.Position = new Tuple<uint, uint>(newRow, newCol);
     118        mowerState.Position = Tuple.Create(newRow, newCol);
    123119        mowerState.Energy = mowerState.Energy - 1;
    124120        lawn[newRow, newCol] = true;
    125         return new Tuple<int, int>(0, 0);
     121        return Tuple.Create(0, 0);
    126122      } else if (node.Symbol is InvokeFunction) {
    127123        var invokeNode = node as InvokeFunctionTreeNode;
     
    147143        return EvaluateLawnMowerProgram(functionDefinition.GetSubtree(0), mowerState, lawn, adfs);
    148144      } else {
    149         throw new ArgumentException("Invalid symbol in the lawn mower program.");
     145        // try to parse as ephemeral random const with format: "x,y" (x, y in [0..32[)
     146        int x, y;
     147        var tokens = node.Symbol.Name.Split(',');
     148        if (tokens.Length == 2 &&
     149            int.TryParse(tokens[0], out x) &&
     150            int.TryParse(tokens[1], out y)) {
     151          return Tuple.Create(x, y);
     152        } else {
     153          throw new ArgumentException("Invalid symbol in the lawn mower program.");
     154        }
    150155      }
    151156    }
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.4/Plugin.cs.frame

    r12753 r12899  
    2323
    2424namespace HeuristicLab.Problems.LawnMower {
    25   [Plugin("HeuristicLab.Problems.LawnMower", "Lawn mower demo problem for genetic programming", "3.3.12.$WCREV$")]
    26   [PluginFile("HeuristicLab.Problems.LawnMower-3.3.dll", PluginFileType.Assembly)]
     25  [Plugin("HeuristicLab.Problems.LawnMower", "Lawn mower demo problem for genetic programming", "3.4.0.$WCREV$")]
     26  [PluginFile("HeuristicLab.Problems.LawnMower-3.4.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Collections", "3.3")]
    2828  [PluginDependency("HeuristicLab.Common", "3.3")]
     
    3434  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3535  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     36  [PluginDependency("HeuristicLab.Random", "3.3")]
    3637  public class HeuristicLabProblemsLawnMowerPlugin : PluginBase {
    3738  }
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.4/Problem.cs

    r12504 r12899  
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3131using HeuristicLab.PluginInfrastructure;
     32using HeuristicLab.Random;
    3233
    3334namespace HeuristicLab.Problems.LawnMower {
     
    3536  [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 160)]
    3637  [Item("Lawn Mower Problem", "The lawn mower demo problem for genetic programming.")]
    37   public class Problem : SingleObjectiveHeuristicOptimizationProblem<Evaluator, ISymbolicExpressionTreeCreator> {
     38  public class Problem : SymbolicExpressionTreeProblem {
    3839    private const string LawnWidthParameterName = "LawnWidth";
    3940    private const string LawnLengthParameterName = "LawnLength";
    40     private const string LawnMowerProgramParameterName = "Program";
    41     private const string MaxLawnMowerProgramLengthParameterName = "MaxProgramLength";
    42     private const string MaxLawnMowerProgramDepthParameterName = "MaxProgramDepth";
    43     private const string LawnMowerGrammarParameterName = "Grammar";
    44     private const string MaxFunctionDefinitionsParameterName = "MaxFunctionDefinitions";
    45     private const string MaxArgumentDefinitionsParameterName = "MaxArgumentDefinitions";
    4641
    4742    public IFixedValueParameter<IntValue> LawnWidthParameter {
     
    5146      get { return (IFixedValueParameter<IntValue>)Parameters[LawnLengthParameterName]; }
    5247    }
    53     public IFixedValueParameter<IntValue> MaxLawnMowerProgramLengthParameter {
    54       get { return (IFixedValueParameter<IntValue>)Parameters[MaxLawnMowerProgramLengthParameterName]; }
    55     }
    56     public IFixedValueParameter<IntValue> MaxLawnMowerProgramDepthParameter {
    57       get { return (IFixedValueParameter<IntValue>)Parameters[MaxLawnMowerProgramDepthParameterName]; }
    58     }
    59     public IValueParameter<Grammar> GrammarParameter {
    60       get { return (IValueParameter<Grammar>)Parameters[LawnMowerGrammarParameterName]; }
    61     }
    62     public IFixedValueParameter<IntValue> MaxFunctionDefinitionsParameter {
    63       get { return (IFixedValueParameter<IntValue>)Parameters[MaxFunctionDefinitionsParameterName]; }
    64     }
    65     public IFixedValueParameter<IntValue> MaxArgumentDefinitionsParameter {
    66       get { return (IFixedValueParameter<IntValue>)Parameters[MaxArgumentDefinitionsParameterName]; }
     48
     49    public override bool Maximization {
     50      get { return true; }
    6751    }
    6852
     
    7357    protected Problem(Problem original, Cloner cloner)
    7458      : base(original, cloner) {
    75       RegisterEventHandlers();
    7659    }
    7760    public Problem()
    78       : base(new Evaluator(), new RampedHalfAndHalfTreeCreator()) {
     61      : base() {
    7962      Parameters.Add(new FixedValueParameter<IntValue>(LawnWidthParameterName, "Width of the lawn.", new IntValue(8)));
    8063      Parameters.Add(new FixedValueParameter<IntValue>(LawnLengthParameterName, "Length of the lawn.", new IntValue(8)));
    81       Parameters.Add(new FixedValueParameter<IntValue>(MaxLawnMowerProgramDepthParameterName, "Maximal depth of the lawn mower program.", new IntValue(13)));
    82       Parameters.Add(new FixedValueParameter<IntValue>(MaxLawnMowerProgramLengthParameterName, "Maximal length of the lawn mower program.", new IntValue(1000)));
    83       Parameters.Add(new FixedValueParameter<IntValue>(MaxFunctionDefinitionsParameterName, "Maximal number of automatically defined functions (ADF).", new IntValue(3)));
    84       Parameters.Add(new FixedValueParameter<IntValue>(MaxArgumentDefinitionsParameterName, "Maximal number of automatically defined arguments.", new IntValue(3)));
    85       Parameters.Add(new ValueParameter<Grammar>(LawnMowerGrammarParameterName, "Grammar for the lawn mower program.",
    86                      new Grammar()));
    87       Maximization.Value = true;
    8864
    89       GrammarParameter.Value.MaximumFunctionDefinitions = MaxFunctionDefinitionsParameter.Value.Value;
    90       GrammarParameter.Value.MaximumFunctionArguments = MaxArgumentDefinitionsParameter.Value.Value;
     65      var g = new SimpleSymbolicExpressionGrammar();
     66      g.AddSymbols(new string[] { "Sum", "Prog" }, 2, 2);
     67      g.AddSymbols(new string[] { "Frog" }, 1, 1);
     68      g.AddTerminalSymbols(new string[] { "Left", "Forward" });
     69      // initialize 20 ephemeral random constants in [0..32[
     70      var fastRand = new FastRandom(314159);
     71      for (int i = 0; i < 20; i++) {
     72        g.AddTerminalSymbol(string.Format("{0},{1}", fastRand.Next(0, 32), fastRand.Next(0, 32)));
     73      }
    9174
    92       InitializeOperators();
    93       RegisterEventHandlers();
     75      Encoding = new SymbolicExpressionTreeEncoding(g, 1000, 17);
     76    }
     77
     78    public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results, IRandom random) {
     79      const string bestSolutionResultName = "Best Solution";
     80      var bestQuality = Maximization ? qualities.Max() : qualities.Min();
     81      var bestIdx = Array.IndexOf(qualities, bestQuality);
     82
     83      if (!results.ContainsKey(bestSolutionResultName)) {
     84        results.Add(new Result(bestSolutionResultName, new Solution(trees[bestIdx], LawnLengthParameter.Value.Value, LawnWidthParameter.Value.Value, bestQuality)));
     85      } else if (((Solution)(results[bestSolutionResultName].Value)).Quality < qualities[bestIdx]) {
     86        results[bestSolutionResultName].Value = new Solution(trees[bestIdx], LawnLengthParameter.Value.Value, LawnWidthParameter.Value.Value, bestQuality);
     87      }
    9488    }
    9589
    9690
    9791    [StorableHook(HookType.AfterDeserialization)]
    98     private void AfterDeserialization() {
    99       RegisterEventHandlers();
     92    private void AfterDeserialization() { }
     93
     94    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
     95      var length = LawnLengthParameter.Value.Value;
     96      var width = LawnWidthParameter.Value.Value;
     97
     98      var lawn = Interpreter.EvaluateLawnMowerProgram(length, width, tree);
     99      // count number of squares that have been mowed
     100      int numberOfMowedCells = 0;
     101      for (int i = 0; i < length; i++)
     102        for (int j = 0; j < width; j++)
     103          if (lawn[i, j]) {
     104            numberOfMowedCells++;
     105          }
     106      return numberOfMowedCells;
    100107    }
    101108
     
    103110      return new Problem(this, cloner);
    104111    }
    105 
    106     private void InitializeOperators() {
    107       Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>());
    108       Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer());
    109       Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
    110       Operators.Add(new BestSolutionAnalyzer());
    111       ParameterizeOperators();
    112       ParameterizeAnalyzers();
    113     }
    114 
    115 
    116     private void RegisterEventHandlers() {
    117       Evaluator.QualityParameter.ActualNameChanged += QualityParameterOnActualNameChanged;
    118       SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged +=
    119         SymbolicExpressionTreeParameterOnActualNameChanged;
    120       MaxArgumentDefinitionsParameter.ValueChanged += ParameterizeGrammar;
    121       MaxFunctionDefinitionsParameter.ValueChanged += ParameterizeGrammar;
    122     }
    123 
    124     protected override void OnEvaluatorChanged() {
    125       Evaluator.LawnMowerProgramParameter.ActualName = LawnMowerProgramParameterName;
    126       Evaluator.LawnLengthParameter.ActualName = LawnLengthParameterName;
    127       Evaluator.LawnWidthParameter.ActualName = LawnWidthParameterName;
    128       Evaluator.QualityParameter.ActualNameChanged += QualityParameterOnActualNameChanged;
    129       ParameterizeAnalyzers();
    130       ParameterizeOperators();
    131       base.OnEvaluatorChanged();
    132     }
    133 
    134     protected override void OnSolutionCreatorChanged() {
    135       SolutionCreator.SymbolicExpressionTreeParameter.ActualName = LawnMowerProgramParameterName;
    136       SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += SymbolicExpressionTreeParameterOnActualNameChanged;
    137       ParameterizeAnalyzers();
    138       ParameterizeOperators();
    139       base.OnSolutionCreatorChanged();
    140     }
    141 
    142     private void SymbolicExpressionTreeParameterOnActualNameChanged(object sender, EventArgs eventArgs) {
    143       ParameterizeAnalyzers();
    144       ParameterizeOperators();
    145     }
    146 
    147     private void QualityParameterOnActualNameChanged(object sender, EventArgs eventArgs) {
    148       ParameterizeAnalyzers();
    149       ParameterizeOperators();
    150     }
    151 
    152     private void ParameterizeGrammar(object sender, EventArgs eventArgs) {
    153       GrammarParameter.Value.MaximumFunctionArguments = MaxArgumentDefinitionsParameter.Value.Value;
    154       GrammarParameter.Value.MaximumFunctionDefinitions = MaxFunctionDefinitionsParameter.Value.Value;
    155     }
    156 
    157     private void ParameterizeAnalyzers() {
    158       var analyzers = Operators.OfType<IAnalyzer>();
    159       foreach (var o in analyzers.OfType<ISymbolicExpressionTreeAnalyzer>()) {
    160         o.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    161       }
    162       foreach (var o in analyzers.OfType<BestSolutionAnalyzer>()) {
    163         o.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    164       }
    165     }
    166 
    167     private void ParameterizeOperators() {
    168       var operators = Parameters
    169         .OfType<IValueParameter>()
    170         .Select(p => p.Value)
    171         .OfType<IOperator>()
    172         .Union(Operators);
    173       foreach (var o in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
    174         o.SymbolicExpressionTreeGrammarParameter.ActualName = LawnMowerGrammarParameterName;
    175       }
    176       foreach (var o in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
    177         o.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaxLawnMowerProgramDepthParameterName;
    178         o.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaxLawnMowerProgramLengthParameterName;
    179       }
    180       foreach (var op in operators.OfType<Evaluator>()) {
    181         op.LawnMowerProgramParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    182         op.LawnLengthParameter.ActualName = LawnLengthParameterName;
    183         op.LawnWidthParameter.ActualName = LawnWidthParameterName;
    184       }
    185       foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    186         op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    187         op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    188       }
    189       foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
    190         op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    191       }
    192       foreach (var op in operators.OfType<ISymbolicExpressionTreeCreator>()) {
    193         op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    194       }
    195       foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
    196         op.MaximumFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name;
    197         op.MaximumFunctionArgumentsParameter.ActualName = MaxArgumentDefinitionsParameter.Name;
    198       }
    199     }
    200112  }
    201113}
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.4/Properties/AssemblyInfo.cs.frame

    r12753 r12899  
    5353// by using the '*' as shown below:
    5454// [assembly: AssemblyVersion("1.0.*")]
    55 [assembly: AssemblyVersion("3.3.0.0")]
    56 [assembly: AssemblyFileVersion("3.3.12.$WCREV$")]
     55[assembly: AssemblyVersion("3.4.0.0")]
     56[assembly: AssemblyFileVersion("3.4.0.$WCREV$")]
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.4/Solution.cs

    r12012 r12899  
    2828  [StorableClass]
    2929  public sealed class Solution : NamedItem {
    30     private int width;
    3130    [Storable]
    32     public int Width {
    33       get { return width; }
    34       private set { this.width = value; }
    35     }
    36     private int length;
     31    public int Width { get; private set; }
    3732    [Storable]
    38     public int Length {
    39       get { return length; }
    40       private set { this.length = value; }
    41     }
    42     private ISymbolicExpressionTree tree;
     33    public int Length { get; private set; }
    4334    [Storable]
    44     public ISymbolicExpressionTree Tree {
    45       get { return tree; }
    46       private set { this.tree = value; }
    47     }
     35    public ISymbolicExpressionTree Tree { get; private set; }
     36    [Storable]
     37    public double Quality { get; private set; }
     38
    4839    [StorableConstructor]
    4940    private Solution(bool deserializing) : base(deserializing) { }
    5041    private Solution(Solution original, Cloner cloner)
    5142      : base(original, cloner) {
    52       this.length = original.length;
    53       this.width = original.width;
    54       this.tree = cloner.Clone(tree);
     43      this.Length = original.Length;
     44      this.Width = original.Width;
     45      this.Tree = cloner.Clone(original.Tree);
     46      this.Quality = original.Quality;
    5547    }
    5648
    57     public Solution(ISymbolicExpressionTree tree, int length, int width)
     49    public Solution(ISymbolicExpressionTree tree, int length, int width, double quality)
    5850      : base("Solution", "A lawn mower solution.") {
    59       this.tree = tree;
    60       this.length = length;
    61       this.width = width;
     51      this.Tree = tree;
     52      this.Length = length;
     53      this.Width = width;
     54      this.Quality = quality;
    6255    }
    6356    [StorableHook(HookType.AfterDeserialization)]
Note: See TracChangeset for help on using the changeset viewer.