Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8267


Ignore:
Timestamp:
07/10/12 00:10:14 (12 years ago)
Author:
ascheibe
Message:

#1886 added wild card analyzer for the best individual

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3
Files:
2 added
4 edited

Legend:

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

    r8247 r8267  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    5758    }
    5859
     60    public static IList<IntArray> GenerateWildcardSchemata(IntArray schema) {
     61      string formatString = "{0:d" + schema.Length + "}";
     62      var combs = new List<bool[]>();
     63      string comb = string.Empty;
     64
     65      // create all desired wildcard combinations
     66      long i = 0;
     67      int wildcardCount = 0; // first wildcard combination contains no wildcards
     68      while (wildcardCount < schema.Length) {
     69        wildcardCount = (comb = Convert.ToString(i++, 2)).PadLeft(schema.Length, '0').Count(x => x == '1');
     70        if (wildcardCount > (schema.Length / 8) && wildcardCount < (schema.Length / 2)) // only include wildcards within certain limits
     71          combs.Add(comb.Select(x => x == '1').ToArray()); // '1' becomes true which indicates a wildcard
     72      }
     73
     74      // create all desired wildcard instances
     75      var wildcardSchemata = new List<IntArray>();
     76      foreach (var c in combs) {
     77        wildcardSchemata.Add(new IntArray(schema.Select((x, index) => c[index] ? -1 : x).ToArray())); // -1 is a wildcard in the schema
     78      }
     79
     80      return wildcardSchemata;
     81    }
     82
    5983    public static string CalculateBrokenInheritanceOccurrences(IntArray schema, GenealogyGraphNode individual) {
    6084      ISet<int> generations = new SortedSet<int>();
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/BestIndividualSchemataAnalyzer.cs

    r8250 r8267  
    7979        var graph = (GenealogyGraph<Permutation>)Results[PopulationGraphResultName].Value;
    8080        int maxGen = (int)graph.Values.Max(x => x.Rank.Max()); // find last generation
     81        SchemaEqualityComparer comparer = new SchemaEqualityComparer();
     82
     83        double curMaxGen = maxGen;
     84        IEnumerable<GenealogyGraphNode> lastGen = null;
     85        IEnumerable<GenealogyGraphNode> parents = null;
     86        lastGen = graph.Values.Where(x => x.Rank.Contains(curMaxGen));
     87        parents = lastGen.Where(x => comparer.Equals((IntArray)x.Data, schemata.Last()));
     88
     89        while (parents.Count() == 0) {
     90          lastGen = graph.Values.Where(x => x.Rank.Contains(curMaxGen));
     91          parents = lastGen.Where(x => comparer.Equals((IntArray)x.Data, schemata.Last()));
     92          curMaxGen -= 0.5;
     93        }
     94        var bestIndividual = parents.First();
     95        var ancestors = parents.First().Ancestors().Where(x => AlgorithmBehaviorHelpers.IsSubtour(schemata.Last(), (Permutation)x.Data));
     96
     97
    8198
    8299        // locate best individual in graph
    83         var bestIndividual = graph.Values.First(x => x.Rank.Max() == maxGen && AlgorithmBehaviorHelpers.IsMatch(new IntArray(((Permutation)x.Data).ToArray()), (schemata.Last()).ToArray()));
     100        /*GenealogyGraphNode bestIndividual = null;
     101        try {
     102          var parents = lastGen.Where(x => comparer.Equals((IntArray)x.Data, parent));
     103          bestIndividual = graph.Values.First(x => x.Rank.Max() == maxGen && AlgorithmBehaviorHelpers.IsMatch(new IntArray(((Permutation)x.Data).ToArray()), (schemata.Last()).ToArray()));
     104        }
     105        catch (Exception ex) {
     106          ex.ToString();
     107        } */
    84108        var bestSchemata = schemata.Take(schemata.Count() - 1);
    85109
    86110        // group ancestors by generation
    87         var generations = new IList<GenealogyGraphNode>[maxGen + 1];
     111        var generations = new IList<GenealogyGraphNode>[((int)maxGen) + 1];
    88112        for (int i = 0; i <= maxGen; i++)
    89113          generations[i] = bestIndividual.Ancestors().Where(x => x.Rank.Contains(i) || x.Rank.Contains(i - 0.5)).ToList();
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Creators/WildcardsCreator.cs

    r8227 r8267  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Linq;
    2523using HeuristicLab.Common;
    2624using HeuristicLab.Core;
     
    7775      var wildcards = new List<IntArray>();
    7876      foreach (var schema in schemata) {
    79         wildcards.AddRange(GenerateWildcardSchemata(schema));
     77        wildcards.AddRange(AlgorithmBehaviorHelpers.GenerateWildcardSchemata(schema));
    8078      }
    8179
    8280      Results.Add(new Result(WildcardsResultName, new ItemArray<IntArray>(wildcards)));
    83 
    8481      return base.Apply();
    85     }
    86 
    87     private IList<IntArray> GenerateWildcardSchemata(IntArray schema) {
    88       string formatString = "{0:d" + schema.Length + "}";
    89       var combs = new List<bool[]>();
    90       string comb = string.Empty;
    91 
    92       // create all desired wildcard combinations
    93       int i = 0;
    94       int wildcardCount = 0; // first wildcard combination contains no wildcards
    95       while (wildcardCount < schema.Length) {
    96         wildcardCount = (comb = string.Format(formatString, Convert.ToInt32(Convert.ToString(i++, 2)))).Count(x => x == '1');
    97         if (wildcardCount > schema.Length / 8 && wildcardCount <= schema.Length / 2) // only include wildcards within certain limits
    98           combs.Add(comb.Select(x => x == '1').ToArray()); // '1' becomes true which indicates a wildcard
    99       }
    100 
    101       // create all desired wildcard instances
    102       var wildcardSchemata = new List<IntArray>();
    103       foreach (var c in combs) {
    104         wildcardSchemata.Add(new IntArray(schema.Select((x, index) => c[index] ? -1 : x).ToArray())); // -1 is a wildcard in the schema
    105       }
    106 
    107       return wildcardSchemata;
    10882    }
    10983  }
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/HeuristicLab.Analysis.AlgorithmBehavior-3.3.csproj

    r8250 r8267  
    9999    <Compile Include="Analyzers\BrokenInheritanceWildcardAnalyzer.cs" />
    100100    <Compile Include="Analyzers\BrokenInteritanceSchemaAnalyzer.cs" />
     101    <Compile Include="Analyzers\BestIndividualWildcardAnalyzer.cs" />
    101102    <Compile Include="Creators\BestIndividualSchemataCreator.cs" />
    102103    <Compile Include="Analyzers\BestIndividualQualityAnalyzer.cs" />
    103104    <Compile Include="Analyzers\SchemaOccurenceInGenerationsAnalyzer.cs" />
    104105    <Compile Include="Analyzers\SchemaQualityAnalyzer.cs" />
     106    <Compile Include="Creators\BestIndividualWildcardCreator.cs" />
    105107    <Compile Include="Creators\SchemataCreator.cs" />
    106108    <Compile Include="Creators\WildcardsCreator.cs" />
Note: See TracChangeset for help on using the changeset viewer.