Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8227


Ignore:
Timestamp:
07/05/12 13:22:38 (12 years ago)
Author:
jkarder
Message:

#1886:

  • added BrokenInheritanceWildcardAnalyzer
  • separated analyzers and data structure creators
  • fixed CalculateBrokenInheritanceOccurrences method
Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3
Files:
6 added
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/BestIndividualSchemaAnalyzer.cs

    r8218 r8227  
    2626using HeuristicLab.Parameters;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Problems.TravelingSalesman;
    2829
    2930namespace HeuristicLab.Analysis.AlgorithmBehavior {
    30   using HeuristicLab.Problems.TravelingSalesman;
    3131
    3232  /// <summary>
     
    6666    public BestIndividualSchemaAnalyzer()
    6767      : base() {
    68       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should are stored."));
     68      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
    6969    }
    7070
     
    7474
    7575    public override IOperation Apply() {
    76       var subtours = SchemaAnalyzer.ExtractSubtours(BestSolution.Permutation);
     76      var subtours = AlgorithmBehaviorHelpers.ExtractSubtours(BestSolution.Permutation);
    7777      Results.Add(new Result(SchemataParameterName, subtours));
    7878      return base.Apply();
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/BrokenInteritanceSchemaAnalyzer.cs

    r8216 r8227  
    3434
    3535  /// <summary>
    36   /// An operator that analyzes broken inheritance of building blocks.
     36  /// An operator that analyzes broken inheritance of schemata.
    3737  /// </summary>
    38   [Item("BrokenInteritanceSchemaAnalyzer", "An operator that analyzes broken inheritance of building blocks.")]
     38  [Item("BrokenInteritanceSchemaAnalyzer", "An operator that analyzes broken inheritance of schemata.")]
    3939  [StorableClass]
    4040  public sealed class BrokenInteritanceSchemaAnalyzer : SingleSuccessorOperator, IAnalyzer {
    4141    private const string ResultsParameterName = "Results";
    42     private const string PopulationGraphResultParameterName = "PopulationGraph";
    43     private const string SchemataParameterName = "Schemata";
    44     private const string BrokenInteritanceSchemaOccurrenceName = "BrokenInteritanceSchemaOccurrenceMatrix";
     42    private const string PopulationGraphResultName = "PopulationGraph";
     43    private const string SchemataResultName = "Schemata";
     44    private const string BrokenInteritanceSchemaOccurrenceMatrixResultName = "BrokenInteritanceSchemaOccurrenceMatrix";
    4545
    4646    #region IAnalyzer Members
     
    6767    public BrokenInteritanceSchemaAnalyzer()
    6868      : base() {
    69       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should are stored."));
     69      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
    7070    }
    7171
     
    7575
    7676    public override IOperation Apply() {
    77       var graph = (GenealogyGraph<Permutation>)Results[PopulationGraphResultParameterName].Value;
    78       var schemata = (ItemArray<IntArray>)Results[SchemataParameterName].Value;
     77      var graph = (GenealogyGraph<Permutation>)Results[PopulationGraphResultName].Value;
     78      var schemata = (ItemArray<IntArray>)Results[SchemataResultName].Value;
    7979      var generationZero = graph.Values.Where(x => x.Rank == 0);
    8080
     
    8888          var individual = generationZero.ElementAt(j);
    8989          if (i == 0) brokenColumnNames.Add(((Permutation)individual.Data).ToString());
    90           brokenInteritanceSchemaOccurrenceMatrix[i, j] = CalculateBrokenInheritanceOccurrences(schema, individual).ToString();
     90          brokenInteritanceSchemaOccurrenceMatrix[i, j] = AlgorithmBehaviorHelpers.CalculateBrokenInheritanceOccurrences(schema, individual);
    9191        }
    9292      }
    9393      brokenInteritanceSchemaOccurrenceMatrix.RowNames = brokenRowNames;
    9494      brokenInteritanceSchemaOccurrenceMatrix.ColumnNames = brokenColumnNames;
    95       Results.Add(new Result(BrokenInteritanceSchemaOccurrenceName, brokenInteritanceSchemaOccurrenceMatrix));
     95      Results.Add(new Result(BrokenInteritanceSchemaOccurrenceMatrixResultName, brokenInteritanceSchemaOccurrenceMatrix));
    9696
    9797      return base.Apply();
    9898    }
    99 
    100     private int CalculateBrokenInheritanceOccurrences(IntArray schema, GenealogyGraphNode individual) {
    101       var filteredDescendants = individual.Descendants().Where(x => IsMatch(schema, ((Permutation)x.Data).ToArray()));
    102       return filteredDescendants.Any() ? (int)filteredDescendants.Max(x => x.Rank) : 0;
    103     }
    104 
    105     // attention: brute force matching
    106     // should be replaced with KMP, BM or RK
    107     private bool IsMatch(IntArray pattern, int[] tour) {
    108       bool match = false;
    109       for (int i = 0; i <= tour.Length - pattern.Length && !match; i++) {
    110         for (int j = 0; j < pattern.Length && (match = pattern[j] == tour[i + j] || pattern[j] == -1); j++) ;
    111       }
    112       return match;
    113     }
    11499  }
    115100}
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/SchemaOccurenceInGenerationsAnalyzer.cs

    r8217 r8227  
    8484    public SchemaOccurenceInGenerationsAnalyzer()
    8585      : base() {
    86       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should are stored."));
     86      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
    8787      Parameters.Add(new LookupParameter<DistanceMatrix>(DistanceMatrixParameterName, "The distance matrix of the TSP."));
    8888      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "Nr of generations."));
     
    9797      var schemata = (ItemArray<IntArray>)Results[SchemataParameterName].Value;
    9898
    99       var schemataMatrix = new Dictionary<IntArray, string>(new HeuristicLab.Analysis.AlgorithmBehavior.SchemaAnalyzer.SchemaEqualityComparer());
     99      var schemataMatrix = new Dictionary<IntArray, string>(new SchemaEqualityComparer());
    100100      foreach (var schema in schemata) {
    101101        if (!schemataMatrix.ContainsKey(schema)) {
     
    125125
    126126      foreach (var individual in graph.Values) {
    127         if (SchemaAnalyzer.IsSubtour(schema, (Permutation)individual.Data)) {
     127        if (AlgorithmBehaviorHelpers.IsSubtour(schema, (Permutation)individual.Data)) {
    128128          occurences[(int)individual.Rank]++;
    129129        }
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/SchemaQualityAnalyzer.cs

    r8217 r8227  
    8484    public SchemaQualityAnalyzer()
    8585      : base() {
    86       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should are stored."));
     86      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
    8787      Parameters.Add(new LookupParameter<DistanceMatrix>(DistanceMatrixParameterName, "The distance matrix of the TSP."));
    8888      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "Nr of generations."));
     
    9797      var schemata = (ItemArray<IntArray>)Results[SchemataParameterName].Value;
    9898
    99       var schemataMatrix = new Dictionary<IntArray, int[]>(new HeuristicLab.Analysis.AlgorithmBehavior.SchemaAnalyzer.SchemaEqualityComparer());
     99      var schemataMatrix = new Dictionary<IntArray, int[]>(new SchemaEqualityComparer());
    100100      int qualityPoints = 0;
    101101      int worseQualityPoints = 0;
     
    135135
    136136      foreach (var individual in graph.Values) {
    137         if (SchemaAnalyzer.IsSubtour(schema, (Permutation)individual.Data)) {
     137        if (AlgorithmBehaviorHelpers.IsSubtour(schema, (Permutation)individual.Data)) {
    138138          occurences[(int)individual.Rank]++;
    139139        }
     
    160160      worstQualityPoint = 0;
    161161      foreach (var individual in graph.Values) {
    162         if (SchemaAnalyzer.IsSubtour(schema, (Permutation)individual.Data)) {
     162        if (AlgorithmBehaviorHelpers.IsSubtour(schema, (Permutation)individual.Data)) {
    163163          occurrences++;
    164164
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/HeuristicLab.Analysis.AlgorithmBehavior-3.3.csproj

    r8218 r8227  
    9595  </ItemGroup>
    9696  <ItemGroup>
    97     <Compile Include="Analyzers\BuildingBlockAnalyzer.cs" />
     97    <Compile Include="AlgorithmBehaviorHelpers.cs" />
     98    <Compile Include="Analyzers\BrokenInheritanceWildcardAnalyzer.cs" />
    9899    <Compile Include="Analyzers\BrokenInteritanceSchemaAnalyzer.cs" />
    99100    <Compile Include="Analyzers\BestIndividualSchemaAnalyzer.cs" />
    100101    <Compile Include="Analyzers\SchemaOccurenceInGenerationsAnalyzer.cs" />
    101102    <Compile Include="Analyzers\SchemaQualityAnalyzer.cs" />
    102     <Compile Include="Analyzers\SchemaAnalyzer.cs" />
     103    <Compile Include="Creators\SchemataCreator.cs" />
     104    <Compile Include="Creators\WildcardsCreator.cs" />
    103105    <Compile Include="Analyzers\GenealogyAnalyzer.cs" />
    104106    <Compile Include="GenealogyGraph.cs" />
     
    106108    <Compile Include="Plugin.cs" />
    107109    <Compile Include="Properties\AssemblyInfo.cs" />
     110    <Compile Include="SchemaEqualityComparer.cs" />
    108111  </ItemGroup>
    109112  <ItemGroup />
Note: See TracChangeset for help on using the changeset viewer.