Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3631


Ignore:
Timestamp:
05/05/10 13:52:16 (15 years ago)
Author:
gkronber
Message:

Added best solution analyzer for artificial ant problem. #999 (Refactor algorithm analysis and tracing)

Location:
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3
Files:
1 added
1 deleted
3 edited
2 moved

Legend:

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

    r3628 r3631  
    2727using HeuristicLab.Data;
    2828
    29 namespace HeuristicLab.Problems.ArtificialAnt {
    30   public interface IAntTrailVisualizer : IAnalyzer {
     29namespace HeuristicLab.Problems.ArtificialAnt.Analyzers {
     30  public interface IAntTrailPopulationAnalyzer : IPopulationAnalyzer {
     31    ILookupParameter<ItemArray<DoubleValue>> QualityParameter { get; }
    3132    ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter { get; }
    3233    ILookupParameter<BoolMatrix> WorldParameter { get; }
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Analyzers/PopulationBestAntTrailAnalyzer.cs

    r3628 r3631  
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3131
    32 namespace HeuristicLab.Problems.ArtificialAnt {
     32namespace HeuristicLab.Problems.ArtificialAnt.Analyzers {
    3333  /// <summary>
    3434  /// An operator for visualizing the best ant trail of an artificial ant problem.
    3535  /// </summary>
    36   [Item("BestAntTrailVisualizer", "An operator for visualizing the best ant trail of an artificial ant problem.")]
     36  [Item("PopulationBestAntTrailAnalyzer", "An operator for visualizing the best ant trail of an artificial ant problem.")]
    3737  [StorableClass]
    38   public sealed class BestAntTrailVisualizer : SingleSuccessorOperator, IAntTrailVisualizer {
     38  public sealed class PopulationBestAntTrailAnalyzer : SingleSuccessorOperator, IAntTrailPopulationAnalyzer {
    3939    public ILookupParameter<BoolMatrix> WorldParameter {
    4040      get { return (ILookupParameter<BoolMatrix>)Parameters["World"]; }
     
    4949      get { return (ILookupParameter<IntValue>)Parameters["MaxTimeSteps"]; }
    5050    }
    51 
    52     public ILookupParameter<AntTrail> AntTrailParameter {
    53       get { return (ILookupParameter<AntTrail>)Parameters["AntTrail"]; }
     51    public ILookupParameter<AntTrail> BestSolutionParameter {
     52      get { return (ILookupParameter<AntTrail>)Parameters["BestSolution"]; }
     53    }
     54    public ValueLookupParameter<ResultCollection> ResultsParameter {
     55      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    5456    }
    5557
    56     public BestAntTrailVisualizer()
     58    public PopulationBestAntTrailAnalyzer()
    5759      : base() {
    5860      Parameters.Add(new LookupParameter<BoolMatrix>("World", "The world with food items for the artificial ant."));
    5961      Parameters.Add(new SubScopesLookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The artificial ant solutions from which the best solution should be visualized."));
    6062      Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the artificial ant solutions which should be visualized."));
    61       Parameters.Add(new LookupParameter<AntTrail>("AntTrail", "The visual representation of the best ant trail."));
     63      Parameters.Add(new LookupParameter<AntTrail>("BestSolution", "The visual representation of the best ant trail."));
    6264      Parameters.Add(new LookupParameter<IntValue>("MaxTimeSteps", "The maximal time steps that the artificial ant has available to collect all food items."));
     65      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best artificial ant solution should be stored."));
    6366    }
    6467
     
    6871      BoolMatrix world = WorldParameter.ActualValue;
    6972      IntValue maxTimeSteps = MaxTimeStepsParameter.ActualValue;
     73      ResultCollection results = ResultsParameter.ActualValue;
    7074
    7175      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => -x.Value).First().index;
    7276
    73       AntTrail antTrail = AntTrailParameter.ActualValue;
    74       if (antTrail == null) AntTrailParameter.ActualValue = new AntTrail(world, expressions[i], maxTimeSteps);
    75       else {
     77      AntTrail antTrail = BestSolutionParameter.ActualValue;
     78      if (antTrail == null) {
     79        var bestAntTrail = new AntTrail(world, expressions[i], maxTimeSteps);
     80        BestSolutionParameter.ActualValue = bestAntTrail;
     81        results.Add(new Result("Best Artificial Ant Solution", bestAntTrail));
     82      } else {
    7683        antTrail.World = world;
    7784        antTrail.SymbolicExpressionTree = expressions[i];
    7885        antTrail.MaxTimeSteps = maxTimeSteps;
     86        results["Best Artificial Ant Solution"].Value = antTrail;
    7987      }
    8088      return base.Apply();
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs

    r3616 r3631  
    3737using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;
    3838using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
     39using HeuristicLab.Problems.ArtificialAnt.Analyzers;
    3940
    4041namespace HeuristicLab.Problems.ArtificialAnt {
     
    181182      get { return BestKnownQualityParameter.Value; }
    182183    }
    183     private List<ISymbolicExpressionTreeOperator> operators;
     184    private List<IOperator> operators;
    184185    public IEnumerable<IOperator> Operators {
    185       get { return operators.Cast<IOperator>(); }
     186      get { return operators; }
     187    }
     188
     189    public IEnumerable<IAntTrailPopulationAnalyzer> AntTrailAnalyzers {
     190      get { return operators.OfType<IAntTrailPopulationAnalyzer>(); }
    186191    }
    187192    #endregion
     
    209214      ParameterizeSolutionCreator();
    210215      ParameterizeEvaluator();
    211       ParameterizeVisualizer();
    212 
    213216      Initialize();
    214217    }
     
    248251      ParameterizeSolutionCreator();
    249252      ParameterizeEvaluator();
    250       ParameterizeVisualizer();
     253      ParameterizeAnalyzers();
    251254      ParameterizeOperators();
    252255      OnSolutionCreatorChanged();
     
    254257    private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
    255258      ParameterizeEvaluator();
    256       ParameterizeVisualizer();
     259      ParameterizeAnalyzers();
    257260      ParameterizeOperators();
    258261    }
     
    260263      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    261264      ParameterizeEvaluator();
    262       ParameterizeVisualizer();
     265      ParameterizeAnalyzers();
    263266      OnEvaluatorChanged();
    264267    }
    265268
    266269    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    267       ParameterizeVisualizer();
     270      ParameterizeAnalyzers();
    268271    }
    269272
     
    293296
    294297    private void InitializeOperators() {
    295       operators = new List<ISymbolicExpressionTreeOperator>();
    296       operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>());
     298      operators = new List<IOperator>();
     299      operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>());
     300      operators.Add(new PopulationBestAntTrailAnalyzer());
     301      ParameterizeAnalyzers();
    297302      ParameterizeOperators();
    298303    }
     
    308313      Evaluator.WorldParameter.ActualName = WorldParameter.Name;
    309314    }
    310     private void ParameterizeVisualizer() {
    311       //if (Visualizer != null) {
    312       //  Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    313       //  var antTrailVisualizer = Visualizer as IAntTrailVisualizer;
    314       //  if (antTrailVisualizer != null) {
    315       //    antTrailVisualizer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    316       //    antTrailVisualizer.WorldParameter.ActualName = WorldParameter.Name;
    317       //    antTrailVisualizer.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
    318       //  }
    319       //  var bestSymExpressionVisualizer = Visualizer as BestSymbolicExpressionTreeVisualizer;
    320       //  if (bestSymExpressionVisualizer != null) {
    321       //    bestSymExpressionVisualizer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    322       //  }
    323       //}
     315    private void ParameterizeAnalyzers() {
     316      foreach (IAntTrailPopulationAnalyzer analyzer in AntTrailAnalyzers) {
     317        analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     318        analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     319        analyzer.WorldParameter.ActualName = WorldParameter.Name;
     320        analyzer.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
     321      }
    324322    }
    325323
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/HeuristicLab.Problems.ArtificialAnt-3.3.csproj

    r3384 r3631  
    8181  </ItemGroup>
    8282  <ItemGroup>
     83    <Compile Include="Analyzers\IAntTrailPopulationAnalyzer.cs" />
     84    <Compile Include="Analyzers\PopulationBestAntTrailAnalyzer.cs" />
    8385    <Compile Include="AntInterpreter.cs" />
    84     <Compile Include="BestAntTrailVisualizer.cs" />
    85     <Compile Include="BestSymbolicExpressionTreeVisualizer.cs" />
    8686    <Compile Include="HeuristicLabProblemsArtificialAntPlugin.cs" />
    87     <Compile Include="IAntTrailVisualizer.cs" />
    8887    <Compile Include="Evaluator.cs" />
    8988    <Compile Include="ArtificialAntExpressionGrammar.cs" />
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/HeuristicLabProblemsArtificialAntPlugin.cs.frame

    r3239 r3631  
    2929  [PluginFile("HeuristicLab.Problems.ArtificialAnt-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Collections", "3.3.0.0")]
     31  [PluginDependency("HeuristicLab.Common", "3.3.0.0")]
    3132  [PluginDependency("HeuristicLab.Common.Resources", "3.2.0.0")]
    3233  [PluginDependency("HeuristicLab.Core", "3.3.0.0")]
Note: See TracChangeset for help on using the changeset viewer.