Changeset 8227
- Timestamp:
- 07/05/12 13:22:38 (12 years ago)
- 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 26 26 using HeuristicLab.Parameters; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.TravelingSalesman; 28 29 29 30 namespace HeuristicLab.Analysis.AlgorithmBehavior { 30 using HeuristicLab.Problems.TravelingSalesman;31 31 32 32 /// <summary> … … 66 66 public BestIndividualSchemaAnalyzer() 67 67 : 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.")); 69 69 } 70 70 … … 74 74 75 75 public override IOperation Apply() { 76 var subtours = SchemaAnalyzer.ExtractSubtours(BestSolution.Permutation);76 var subtours = AlgorithmBehaviorHelpers.ExtractSubtours(BestSolution.Permutation); 77 77 Results.Add(new Result(SchemataParameterName, subtours)); 78 78 return base.Apply(); -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/BrokenInteritanceSchemaAnalyzer.cs
r8216 r8227 34 34 35 35 /// <summary> 36 /// An operator that analyzes broken inheritance of building blocks.36 /// An operator that analyzes broken inheritance of schemata. 37 37 /// </summary> 38 [Item("BrokenInteritanceSchemaAnalyzer", "An operator that analyzes broken inheritance of building blocks.")]38 [Item("BrokenInteritanceSchemaAnalyzer", "An operator that analyzes broken inheritance of schemata.")] 39 39 [StorableClass] 40 40 public sealed class BrokenInteritanceSchemaAnalyzer : SingleSuccessorOperator, IAnalyzer { 41 41 private const string ResultsParameterName = "Results"; 42 private const string PopulationGraphResult ParameterName = "PopulationGraph";43 private const string Schemata ParameterName = "Schemata";44 private const string BrokenInteritanceSchemaOccurrence Name = "BrokenInteritanceSchemaOccurrenceMatrix";42 private const string PopulationGraphResultName = "PopulationGraph"; 43 private const string SchemataResultName = "Schemata"; 44 private const string BrokenInteritanceSchemaOccurrenceMatrixResultName = "BrokenInteritanceSchemaOccurrenceMatrix"; 45 45 46 46 #region IAnalyzer Members … … 67 67 public BrokenInteritanceSchemaAnalyzer() 68 68 : 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.")); 70 70 } 71 71 … … 75 75 76 76 public override IOperation Apply() { 77 var graph = (GenealogyGraph<Permutation>)Results[PopulationGraphResult ParameterName].Value;78 var schemata = (ItemArray<IntArray>)Results[Schemata ParameterName].Value;77 var graph = (GenealogyGraph<Permutation>)Results[PopulationGraphResultName].Value; 78 var schemata = (ItemArray<IntArray>)Results[SchemataResultName].Value; 79 79 var generationZero = graph.Values.Where(x => x.Rank == 0); 80 80 … … 88 88 var individual = generationZero.ElementAt(j); 89 89 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); 91 91 } 92 92 } 93 93 brokenInteritanceSchemaOccurrenceMatrix.RowNames = brokenRowNames; 94 94 brokenInteritanceSchemaOccurrenceMatrix.ColumnNames = brokenColumnNames; 95 Results.Add(new Result(BrokenInteritanceSchemaOccurrence Name, brokenInteritanceSchemaOccurrenceMatrix));95 Results.Add(new Result(BrokenInteritanceSchemaOccurrenceMatrixResultName, brokenInteritanceSchemaOccurrenceMatrix)); 96 96 97 97 return base.Apply(); 98 98 } 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 matching106 // should be replaced with KMP, BM or RK107 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 }114 99 } 115 100 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/SchemaOccurenceInGenerationsAnalyzer.cs
r8217 r8227 84 84 public SchemaOccurenceInGenerationsAnalyzer() 85 85 : 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.")); 87 87 Parameters.Add(new LookupParameter<DistanceMatrix>(DistanceMatrixParameterName, "The distance matrix of the TSP.")); 88 88 Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "Nr of generations.")); … … 97 97 var schemata = (ItemArray<IntArray>)Results[SchemataParameterName].Value; 98 98 99 var schemataMatrix = new Dictionary<IntArray, string>(new HeuristicLab.Analysis.AlgorithmBehavior.SchemaAnalyzer.SchemaEqualityComparer());99 var schemataMatrix = new Dictionary<IntArray, string>(new SchemaEqualityComparer()); 100 100 foreach (var schema in schemata) { 101 101 if (!schemataMatrix.ContainsKey(schema)) { … … 125 125 126 126 foreach (var individual in graph.Values) { 127 if ( SchemaAnalyzer.IsSubtour(schema, (Permutation)individual.Data)) {127 if (AlgorithmBehaviorHelpers.IsSubtour(schema, (Permutation)individual.Data)) { 128 128 occurences[(int)individual.Rank]++; 129 129 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Analyzers/SchemaQualityAnalyzer.cs
r8217 r8227 84 84 public SchemaQualityAnalyzer() 85 85 : 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.")); 87 87 Parameters.Add(new LookupParameter<DistanceMatrix>(DistanceMatrixParameterName, "The distance matrix of the TSP.")); 88 88 Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "Nr of generations.")); … … 97 97 var schemata = (ItemArray<IntArray>)Results[SchemataParameterName].Value; 98 98 99 var schemataMatrix = new Dictionary<IntArray, int[]>(new HeuristicLab.Analysis.AlgorithmBehavior.SchemaAnalyzer.SchemaEqualityComparer());99 var schemataMatrix = new Dictionary<IntArray, int[]>(new SchemaEqualityComparer()); 100 100 int qualityPoints = 0; 101 101 int worseQualityPoints = 0; … … 135 135 136 136 foreach (var individual in graph.Values) { 137 if ( SchemaAnalyzer.IsSubtour(schema, (Permutation)individual.Data)) {137 if (AlgorithmBehaviorHelpers.IsSubtour(schema, (Permutation)individual.Data)) { 138 138 occurences[(int)individual.Rank]++; 139 139 } … … 160 160 worstQualityPoint = 0; 161 161 foreach (var individual in graph.Values) { 162 if ( SchemaAnalyzer.IsSubtour(schema, (Permutation)individual.Data)) {162 if (AlgorithmBehaviorHelpers.IsSubtour(schema, (Permutation)individual.Data)) { 163 163 occurrences++; 164 164 -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/HeuristicLab.Analysis.AlgorithmBehavior-3.3.csproj
r8218 r8227 95 95 </ItemGroup> 96 96 <ItemGroup> 97 <Compile Include="Analyzers\BuildingBlockAnalyzer.cs" /> 97 <Compile Include="AlgorithmBehaviorHelpers.cs" /> 98 <Compile Include="Analyzers\BrokenInheritanceWildcardAnalyzer.cs" /> 98 99 <Compile Include="Analyzers\BrokenInteritanceSchemaAnalyzer.cs" /> 99 100 <Compile Include="Analyzers\BestIndividualSchemaAnalyzer.cs" /> 100 101 <Compile Include="Analyzers\SchemaOccurenceInGenerationsAnalyzer.cs" /> 101 102 <Compile Include="Analyzers\SchemaQualityAnalyzer.cs" /> 102 <Compile Include="Analyzers\SchemaAnalyzer.cs" /> 103 <Compile Include="Creators\SchemataCreator.cs" /> 104 <Compile Include="Creators\WildcardsCreator.cs" /> 103 105 <Compile Include="Analyzers\GenealogyAnalyzer.cs" /> 104 106 <Compile Include="GenealogyGraph.cs" /> … … 106 108 <Compile Include="Plugin.cs" /> 107 109 <Compile Include="Properties\AssemblyInfo.cs" /> 110 <Compile Include="SchemaEqualityComparer.cs" /> 108 111 </ItemGroup> 109 112 <ItemGroup />
Note: See TracChangeset
for help on using the changeset viewer.