Changeset 8267
- Timestamp:
- 07/10/12 00:10:14 (12 years ago)
- 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 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 57 58 } 58 59 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 59 83 public static string CalculateBrokenInheritanceOccurrences(IntArray schema, GenealogyGraphNode individual) { 60 84 ISet<int> generations = new SortedSet<int>(); -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/BestIndividualSchemataAnalyzer.cs
r8250 r8267 79 79 var graph = (GenealogyGraph<Permutation>)Results[PopulationGraphResultName].Value; 80 80 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 81 98 82 99 // 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 } */ 84 108 var bestSchemata = schemata.Take(schemata.Count() - 1); 85 109 86 110 // group ancestors by generation 87 var generations = new IList<GenealogyGraphNode>[ maxGen+ 1];111 var generations = new IList<GenealogyGraphNode>[((int)maxGen) + 1]; 88 112 for (int i = 0; i <= maxGen; i++) 89 113 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 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Linq;25 23 using HeuristicLab.Common; 26 24 using HeuristicLab.Core; … … 77 75 var wildcards = new List<IntArray>(); 78 76 foreach (var schema in schemata) { 79 wildcards.AddRange( GenerateWildcardSchemata(schema));77 wildcards.AddRange(AlgorithmBehaviorHelpers.GenerateWildcardSchemata(schema)); 80 78 } 81 79 82 80 Results.Add(new Result(WildcardsResultName, new ItemArray<IntArray>(wildcards))); 83 84 81 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 combinations93 int i = 0;94 int wildcardCount = 0; // first wildcard combination contains no wildcards95 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 limits98 combs.Add(comb.Select(x => x == '1').ToArray()); // '1' becomes true which indicates a wildcard99 }100 101 // create all desired wildcard instances102 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 schema105 }106 107 return wildcardSchemata;108 82 } 109 83 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/HeuristicLab.Analysis.AlgorithmBehavior-3.3.csproj
r8250 r8267 99 99 <Compile Include="Analyzers\BrokenInheritanceWildcardAnalyzer.cs" /> 100 100 <Compile Include="Analyzers\BrokenInteritanceSchemaAnalyzer.cs" /> 101 <Compile Include="Analyzers\BestIndividualWildcardAnalyzer.cs" /> 101 102 <Compile Include="Creators\BestIndividualSchemataCreator.cs" /> 102 103 <Compile Include="Analyzers\BestIndividualQualityAnalyzer.cs" /> 103 104 <Compile Include="Analyzers\SchemaOccurenceInGenerationsAnalyzer.cs" /> 104 105 <Compile Include="Analyzers\SchemaQualityAnalyzer.cs" /> 106 <Compile Include="Creators\BestIndividualWildcardCreator.cs" /> 105 107 <Compile Include="Creators\SchemataCreator.cs" /> 106 108 <Compile Include="Creators\WildcardsCreator.cs" />
Note: See TracChangeset
for help on using the changeset viewer.