Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3238


Ignore:
Timestamp:
03/30/10 19:40:13 (15 years ago)
Author:
gkronber
Message:

Implemented a solution visualizer for the artificial ant problem. #952 (Artificial Ant Problem for 3.3)

Location:
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/AntInterpreter.cs

    r3223 r3238  
    8383    internal void Run(SymbolicExpressionTree tree) {
    8484      while (FoodEaten < N_FOOD_ITEMS && ElapsedTime < MaxTimeSteps) {
    85         Step(tree.Root);
     85        Step(tree.Root.SubTrees[0]);
    8686      }
    8787    }
     
    117117        Step(currentNode.SubTrees[2]);
    118118        return;
    119       } else {
     119      } else  {
    120120        throw new InvalidOperationException(currentNode.Symbol.ToString());
    121121      }
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs

    r3223 r3238  
    2424using System.Collections.Generic;
    2525using System;
     26using System.Linq;
    2627using HeuristicLab.Core;
    2728namespace HeuristicLab.Problems.ArtificialAnt {
     
    142143
    143144    #endregion
     145
     146    #region ISymbolicExpressionGrammar Members
     147
     148
     149    public bool IsValidExpression(SymbolicExpressionTree expression) {
     150      if (expression.Root.Symbol != StartSymbol) return false;
     151      return IsValidExpression(expression.Root);
     152    }
     153
     154    #endregion
     155
     156    private bool IsValidExpression(SymbolicExpressionTreeNode root) {
     157      if (root.SubTrees.Count < MinSubTrees(root.Symbol)) return false;
     158      if (root.SubTrees.Count > MaxSubTrees(root.Symbol)) return false;
     159      for (int i = 0; i < root.SubTrees.Count; i++) {
     160        if (!AllowedSymbols(root.Symbol, i).Contains(root.SubTrees[i].Symbol)) return false;
     161        if (!IsValidExpression(root.SubTrees[i])) return false;
     162      }
     163      return true;
     164    }
    144165  }
    145166}
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs

    r3223 r3238  
    127127      Evaluator evaluator = new Evaluator();
    128128      ArtificialAntExpressionGrammar grammar = new ArtificialAntExpressionGrammar();
     129      BestAntTrailVisualizer visualizer = new BestAntTrailVisualizer();
    129130
    130131      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true)));
    131132      Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator));
    132133      Parameters.Add(new ValueParameter<Evaluator>("Evaluator", "The operator which should be used to evaluate artificial ant solutions.", evaluator));
    133       Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this OneMax instance.", new DoubleValue(200)));
     134      Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this OneMax instance.", new DoubleValue(89)));
    134135      Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", grammar));
    135136      Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100)));
    136137      Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10)));
    137       Parameters.Add(new ValueParameter<IAntTrailVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", null));
     138      Parameters.Add(new ValueParameter<IAntTrailVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", visualizer));
    138139
    139140      creator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution";
     
    141142      ParameterizeSolutionCreator();
    142143      ParameterizeEvaluator();
     144      ParameterizeVisualizer();
    143145
    144146      Initialize();
     
    212214      operators.Add(Evaluator);
    213215      operators.Add(SolutionCreator);
     216      operators.Add(new SubtreeCrossover());
    214217      ParameterizeOperators();
    215218    }
     
    224227        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    225228      }
    226     }
     229      foreach (SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) {
     230        op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
     231        op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
     232        op.SymbolicExpressionGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name;
     233        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     234        op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     235      }
     236    }
     237    private void ParameterizeVisualizer() {
     238      if (Visualizer != null) {
     239        Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     240        if (Visualizer is IAntTrailVisualizer)
     241          ((IAntTrailVisualizer)Visualizer).SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     242      }
     243    }
     244
    227245    #endregion
    228246  }
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/HeuristicLab.Problems.ArtificialAnt-3.3.csproj

    r3223 r3238  
    8686  <ItemGroup>
    8787    <Compile Include="AntInterpreter.cs" />
     88    <Compile Include="BestAntTrailVisualizer.cs" />
    8889    <Compile Include="HeuristicLabProblemsArtificialAntPlugin.cs" />
    8990    <Compile Include="IAntTrailVisualizer.cs" />
     
    9697    <Compile Include="ArtificialAntProblemView.Designer.cs">
    9798      <DependentUpon>ArtificialAntProblemView.cs</DependentUpon>
     99    </Compile>
     100    <Compile Include="AntTrail.cs" />
     101    <Compile Include="AntTrailView.cs">
     102      <SubType>UserControl</SubType>
     103    </Compile>
     104    <Compile Include="AntTrailView.Designer.cs">
     105      <DependentUpon>AntTrailView.cs</DependentUpon>
    98106    </Compile>
    99107    <Compile Include="Properties\AssemblyInfo.cs" />
     
    117125      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
    118126      <Name>HeuristicLab.Common.Resources-3.2</Name>
     127    </ProjectReference>
     128    <ProjectReference Include="..\..\HeuristicLab.Common\3.2\HeuristicLab.Common-3.2.csproj">
     129      <Project>{1FC004FC-59AF-4249-B1B6-FF25873A20E4}</Project>
     130      <Name>HeuristicLab.Common-3.2</Name>
    119131    </ProjectReference>
    120132    <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/IAntTrailVisualizer.cs

    r3223 r3238  
    2323using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2424using HeuristicLab.Optimization;
     25using HeuristicLab.Core;
    2526
    2627namespace HeuristicLab.Problems.ArtificialAnt {
    27   public interface IAntTrailVisualizer : ISolutionsVisualizer {
     28  public interface IAntTrailVisualizer : ISolutionsVisualizer, ISingleObjectiveSolutionsVisualizer {
     29    ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter { get; }
    2830  }
    2931}
Note: See TracChangeset for help on using the changeset viewer.