Changeset 12069
- Timestamp:
- 02/25/15 10:07:54 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 16 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchImprovementOperator.cs
r12012 r12069 251 251 foreach (IAnalyzer analyzer in problem.Operators.OfType<IAnalyzer>()) { 252 252 if (!IsSubclassOfGeneric(typeof(AlleleFrequencyAnalyzer<>), analyzer.GetType()) && 253 !(analyzer is SingleObjectivePopulationDiversityAnalyzer)) {253 !(analyzer is PopulationSimilarityAnalyzer)) { 254 254 IAnalyzer clone = analyzer.Clone() as IAnalyzer; 255 255 foreach (IScopeTreeLookupParameter param in clone.Parameters.OfType<IScopeTreeLookupParameter>()) -
trunk/sources/HeuristicLab.Algorithms.RAPGA/3.3/DuplicatesSelector.cs
r12012 r12069 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Optimization; 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 using HeuristicLab.Selection; … … 37 38 [Item("DuplicatesSelector", "A selection operator which considers a single solution representation and selects duplicates. The remaining scope then contains unique solutions and the selected scope their duplicates.")] 38 39 [StorableClass] 39 public sealed class DuplicatesSelector : SingleObjectiveSelector, ISimilarityBasedOperator { 40 #region ISimilarityBasedOperator Members 41 [Storable] 42 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 43 #endregion 40 public sealed class DuplicatesSelector : SingleObjectiveSelector { 41 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 42 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 43 } 44 44 45 45 [StorableConstructor] 46 46 private DuplicatesSelector(bool deserializing) : base(deserializing) { } 47 private DuplicatesSelector(DuplicatesSelector original, Cloner cloner) 48 : base(original, cloner) { 49 this.SimilarityCalculator = cloner.Clone(original.SimilarityCalculator); 47 private DuplicatesSelector(DuplicatesSelector original, Cloner cloner) : base(original, cloner) { } 48 public DuplicatesSelector() 49 : base() { 50 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 50 51 } 51 public DuplicatesSelector() : base() { }52 52 53 53 public override IDeepCloneable Clone(Cloner cloner) { 54 54 return new DuplicatesSelector(this, cloner); 55 } 56 57 [StorableHook(HookType.AfterDeserialization)] 58 private void AfterDeserialization() { 59 // BackwardsCompatibility3.3 60 #region Backwards compatible code, remove with 3.4 61 if (!Parameters.ContainsKey("SimilarityCalculator")) 62 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 63 #endregion 55 64 } 56 65 … … 61 70 for (int i = 0; i < scopes.Count; i++) 62 71 for (int j = i + 1; j < scopes.Count; j++) 63 marks[j] = SimilarityCalculator .Equals(scopes[i], scopes[j]);72 marks[j] = SimilarityCalculatorParameter.ActualValue.Equals(scopes[i], scopes[j]); 64 73 65 74 -
trunk/sources/HeuristicLab.Algorithms.RAPGA/3.3/ProgressiveOffspringPreserver.cs
r12012 r12069 38 38 [Item("ProgressiveOffspringPreserver", "An operator that progressively selects offspring by adding it to a scope list. The operator also performs duplication control.")] 39 39 [StorableClass] 40 public sealed class ProgressiveOffspringPreserver : SingleSuccessorOperator, ISimilarityBasedOperator { 41 #region ISimilarityBasedOperator Members 42 [Storable] 43 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 44 #endregion 45 40 public sealed class ProgressiveOffspringPreserver : SingleSuccessorOperator { 46 41 #region Parameter Properties 47 42 public ScopeParameter CurrentScopeParameter { … … 56 51 public ILookupParameter<IntValue> MaximumPopulationSizeParameter { 57 52 get { return (ILookupParameter<IntValue>)Parameters["MaximumPopulationSize"]; } 53 } 54 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 55 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 58 56 } 59 57 #endregion … … 76 74 [StorableConstructor] 77 75 private ProgressiveOffspringPreserver(bool deserializing) : base(deserializing) { } 78 private ProgressiveOffspringPreserver(ProgressiveOffspringPreserver original, Cloner cloner) 79 : base(original, cloner) { 80 this.SimilarityCalculator = cloner.Clone(original.SimilarityCalculator); 81 } 76 private ProgressiveOffspringPreserver(ProgressiveOffspringPreserver original, Cloner cloner) : base(original, cloner) { } 82 77 public ProgressiveOffspringPreserver() 83 78 : base() { 79 #region Create parameters 84 80 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the offspring.")); 85 81 Parameters.Add(new LookupParameter<ScopeList>("OffspringList", "The list that contains the offspring.")); 86 82 Parameters.Add(new LookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); 87 83 Parameters.Add(new LookupParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions.")); 84 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 85 #endregion 88 86 } 89 87 90 88 public override IDeepCloneable Clone(Cloner cloner) { 91 89 return new ProgressiveOffspringPreserver(this, cloner); 90 } 91 92 [StorableHook(HookType.AfterDeserialization)] 93 private void AfterDeserialization() { 94 // BackwardsCompatibility3.3 95 #region Backwards compatible code, remove with 3.4 96 if (!Parameters.ContainsKey("SimilarityCalculator")) 97 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 98 #endregion 92 99 } 93 100 … … 98 105 var storedOffspringScope = new Scope(); 99 106 storedOffspringScope.SubScopes.AddRange(OffspringList); 100 var similarityMatrix = SimilarityCalculator .CalculateSolutionCrowdSimilarity(CurrentScope, storedOffspringScope);107 var similarityMatrix = SimilarityCalculatorParameter.ActualValue.CalculateSolutionCrowdSimilarity(CurrentScope, storedOffspringScope); 101 108 102 109 var createdOffspring = CurrentScope.SubScopes.ToArray(); -
trunk/sources/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs
r12012 r12069 394 394 RAPGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 395 395 RAPGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 396 foreach (ISimilarityBasedOperator op in RAPGAMainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())397 op.SimilarityCalculator = SimilarityCalculator;398 396 } 399 397 private void ParameterizeStochasticOperator(IOperator op) { -
trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs
r12012 r12069 36 36 [Item("ReferenceSetUpdateMethod", "An operator that updates the reference set.")] 37 37 [StorableClass] 38 public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator, ISimilarityBasedOperator { 39 #region ISimilarityBasedOperator Members 40 [Storable] 41 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 42 #endregion 43 38 public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator { 44 39 #region Parameter properties 45 40 public ScopeParameter CurrentScopeParameter { … … 48 43 public IValueLookupParameter<IntValue> ReferenceSetSizeParameter { 49 44 get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; } 45 } 46 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 47 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 50 48 } 51 49 #endregion … … 62 60 [StorableConstructor] 63 61 private ReferenceSetUpdateMethod(bool deserializing) : base(deserializing) { } 64 private ReferenceSetUpdateMethod(ReferenceSetUpdateMethod original, Cloner cloner) 65 : base(original, cloner) { 66 this.SimilarityCalculator = cloner.Clone(original.SimilarityCalculator); 67 } 62 private ReferenceSetUpdateMethod(ReferenceSetUpdateMethod original, Cloner cloner) : base(original, cloner) { } 68 63 public ReferenceSetUpdateMethod() 69 64 : base() { … … 71 66 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the population and the reference set.")); 72 67 Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set.")); 68 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 73 69 #endregion 74 70 } … … 78 74 } 79 75 76 [StorableHook(HookType.AfterDeserialization)] 77 private void AfterDeserialization() { 78 // BackwardsCompatibility3.3 79 #region Backwards compatible code, remove with 3.4 80 if (!Parameters.ContainsKey("SimilarityCalculator")) 81 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 82 #endregion 83 } 84 80 85 public override IOperation Apply() { 81 86 var populationSimilarity = new Dictionary<IScope, double>(); 82 87 var populationScope = CurrentScope.SubScopes[0]; 83 88 var refSetScope = CurrentScope.SubScopes[1]; 84 var similarityMatrix = SimilarityCalculator .CalculateSolutionCrowdSimilarity(populationScope, refSetScope);89 var similarityMatrix = SimilarityCalculatorParameter.ActualValue.CalculateSolutionCrowdSimilarity(populationScope, refSetScope); 85 90 for (int i = 0; i < populationScope.SubScopes.Count; i++) { 86 91 populationSimilarity[populationScope.SubScopes[i]] = similarityMatrix[i].Sum(); -
trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs
r12012 r12069 423 423 MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 424 424 MainLoop.OperatorGraph.Operators.OfType<SolutionPoolUpdateMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 425 foreach (ISimilarityBasedOperator op in MainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())426 op.SimilarityCalculator = SimilarityCalculator;427 425 } 428 426 } -
trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs
r12012 r12069 36 36 [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")] 37 37 [StorableClass] 38 public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, ISimilarityBasedOperator, ISingleObjectiveOperator { 39 #region ISimilarityBasedOperator Members 40 [Storable] 41 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 42 #endregion 43 38 public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, ISingleObjectiveOperator { 44 39 #region Parameter properties 45 40 public ScopeParameter CurrentScopeParameter { … … 57 52 public IValueLookupParameter<IntValue> ReferenceSetSizeParameter { 58 53 get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; } 54 } 55 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 56 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 59 57 } 60 58 #endregion … … 82 80 [StorableConstructor] 83 81 private SolutionPoolUpdateMethod(bool deserializing) : base(deserializing) { } 84 private SolutionPoolUpdateMethod(SolutionPoolUpdateMethod original, Cloner cloner) 85 : base(original, cloner) { 86 this.SimilarityCalculator = cloner.Clone(original.SimilarityCalculator); 87 } 88 public SolutionPoolUpdateMethod() : base() { Initialize(); } 89 90 public override IDeepCloneable Clone(Cloner cloner) { 91 return new SolutionPoolUpdateMethod(this, cloner); 92 } 93 94 private void Initialize() { 82 private SolutionPoolUpdateMethod(SolutionPoolUpdateMethod original, Cloner cloner) : base(original, cloner) { } 83 public SolutionPoolUpdateMethod() 84 : base() { 95 85 #region Create parameters 96 86 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that is the reference set.")); … … 99 89 Parameters.Add(new ValueLookupParameter<IItem>("Quality", "This parameter is used for name translation only.")); 100 90 Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set.")); 91 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 92 #endregion 93 } 94 95 public override IDeepCloneable Clone(Cloner cloner) { 96 return new SolutionPoolUpdateMethod(this, cloner); 97 } 98 99 [StorableHook(HookType.AfterDeserialization)] 100 private void AfterDeserialization() { 101 // BackwardsCompatibility3.3 102 #region Backwards compatible code, remove with 3.4 103 if (!Parameters.ContainsKey("SimilarityCalculator")) 104 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 101 105 #endregion 102 106 } … … 132 136 if (orderedOffspring.Any(hasBetterQuality)) { 133 137 // produce the set union 134 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), SimilarityCalculator );138 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), SimilarityCalculatorParameter.ActualValue); 135 139 if (union.Count() > orderedParents.Count()) { 136 140 var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) : -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingImprovementOperator.cs
r12012 r12069 279 279 foreach (IAnalyzer analyzer in problem.Operators.OfType<IAnalyzer>()) { 280 280 if (!IsSubclassOfGeneric(typeof(AlleleFrequencyAnalyzer<>), analyzer.GetType()) && 281 !(analyzer is SingleObjectivePopulationDiversityAnalyzer)) {281 !(analyzer is PopulationSimilarityAnalyzer)) { 282 282 IAnalyzer clone = analyzer.Clone() as IAnalyzer; 283 283 foreach (IScopeTreeLookupParameter param in clone.Parameters.OfType<IScopeTreeLookupParameter>()) -
trunk/sources/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj
r11914 r12069 148 148 <Compile Include="MultiObjective\ParetoFrontAnalyzer.cs" /> 149 149 <Compile Include="Plugin.cs" /> 150 <Compile Include="PopulationDiversityAnalysis\PopulationDiversityAnalyzer.cs" /> 151 <Compile Include="PopulationDiversityAnalysis\SingleObjectivePopulationDiversityAnalyzer.cs" /> 150 <Compile Include="PopulationSimilarityAnalysis\PopulationDiversityAnalyzer.cs" /> 151 <Compile Include="PopulationSimilarityAnalysis\PopulationSimilarityAnalyzer.cs" /> 152 <Compile Include="PopulationSimilarityAnalysis\SingleObjectivePopulationDiversityAnalyzer.cs" /> 152 153 <Compile Include="QualityAnalysis\BestAverageWorstQualityAnalyzer.cs" /> 153 154 <Compile Include="QualityAnalysis\BestAverageWorstQualityCalculator.cs" /> -
trunk/sources/HeuristicLab.Analysis/3.3/PopulationSimilarityAnalysis/SingleObjectivePopulationDiversityAnalyzer.cs
r12012 r12069 21 21 22 22 using System; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; 26 using HeuristicLab.Data;27 using HeuristicLab.Operators;28 using HeuristicLab.Optimization;29 using HeuristicLab.Parameters;30 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.PluginInfrastructure; 31 27 32 28 namespace HeuristicLab.Analysis { 29 // use HeuristicLab.Analysis.PopulationSimilarityAnalyzer instead 30 // BackwardsCompatibility3.3 31 #region Backwards compatible code, remove with 3.4 33 32 /// <summary> 34 33 /// An operator for analyzing the solution diversity in a population. 35 34 /// </summary> 35 [Obsolete] 36 [NonDiscoverableType] 36 37 [Item("SingleObjectivePopulationDiversityAnalyzer", "An operator for analyzing the solution diversity in a population.")] 37 38 [StorableClass] 38 public class SingleObjectivePopulationDiversityAnalyzer : SingleSuccessorOperator, IAnalyzer, ISimilarityBasedOperator, ISingleObjectiveOperator { 39 #region ISimilarityBasedOperator Members 40 [Storable] 41 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 42 #endregion 43 44 public virtual bool EnabledByDefault { 45 get { return false; } 46 } 47 48 public ScopeParameter CurrentScopeParameter { 49 get { return (ScopeParameter)Parameters["CurrentScope"]; } 50 } 51 public LookupParameter<BoolValue> MaximizationParameter { 52 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 53 } 54 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 55 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 56 } 57 public ValueLookupParameter<ResultCollection> ResultsParameter { 58 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 59 } 60 public ValueParameter<BoolValue> StoreHistoryParameter { 61 get { return (ValueParameter<BoolValue>)Parameters["StoreHistory"]; } 62 } 63 public ValueParameter<IntValue> UpdateIntervalParameter { 64 get { return (ValueParameter<IntValue>)Parameters["UpdateInterval"]; } 65 } 66 public LookupParameter<IntValue> UpdateCounterParameter { 67 get { return (LookupParameter<IntValue>)Parameters["UpdateCounter"]; } 68 } 69 39 public class SingleObjectivePopulationDiversityAnalyzer : PopulationSimilarityAnalyzer { 70 40 [StorableConstructor] 71 41 protected SingleObjectivePopulationDiversityAnalyzer(bool deserializing) : base(deserializing) { } 72 protected SingleObjectivePopulationDiversityAnalyzer(SingleObjectivePopulationDiversityAnalyzer original, Cloner cloner) 73 : base(original, cloner) { 74 SimilarityCalculator = cloner.Clone(original.SimilarityCalculator); 75 } 76 public SingleObjectivePopulationDiversityAnalyzer() 77 : base() { 78 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the solutions which should be analyzed.")); 79 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem.")); 80 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the solutions which should be analyzed.")); 81 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the population diversity analysis results should be stored.")); 82 Parameters.Add(new ValueParameter<BoolValue>("StoreHistory", "True if the history of the population diversity analysis should be stored.", new BoolValue(false))); 83 Parameters.Add(new ValueParameter<IntValue>("UpdateInterval", "The interval in which the population diversity analysis should be applied.", new IntValue(1))); 84 Parameters.Add(new LookupParameter<IntValue>("UpdateCounter", "The value which counts how many times the operator was called since the last update.", "PopulationDiversityAnalyzerUpdateCounter")); 85 86 MaximizationParameter.Hidden = true; 87 QualityParameter.Hidden = true; 88 ResultsParameter.Hidden = true; 89 UpdateCounterParameter.Hidden = true; 90 } 42 protected SingleObjectivePopulationDiversityAnalyzer(SingleObjectivePopulationDiversityAnalyzer original, Cloner cloner) : base(original, cloner) { } 91 43 92 44 public override IDeepCloneable Clone(Cloner cloner) { 93 45 return new SingleObjectivePopulationDiversityAnalyzer(this, cloner); 94 46 } 95 96 public override IOperation Apply() {97 int updateInterval = UpdateIntervalParameter.Value.Value;98 IntValue updateCounter = UpdateCounterParameter.ActualValue;99 // if counter does not yet exist then initialize it with update interval100 // to make sure the solutions are analyzed on the first application of this operator101 if (updateCounter == null) {102 updateCounter = new IntValue(updateInterval);103 UpdateCounterParameter.ActualValue = updateCounter;104 } else updateCounter.Value++;105 106 //analyze solutions only every 'updateInterval' times107 if (updateCounter.Value == updateInterval) {108 updateCounter.Value = 0;109 110 bool max = MaximizationParameter.ActualValue.Value;111 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;112 bool storeHistory = StoreHistoryParameter.Value.Value;113 int count = CurrentScopeParameter.ActualValue.SubScopes.Count;114 115 if (count > 1) {116 // calculate solution similarities117 var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(CurrentScopeParameter.ActualValue);118 119 // sort similarities by quality120 double[][] sortedSimilarityMatrix = null;121 if (max)122 sortedSimilarityMatrix = similarityMatrix123 .Select((x, index) => new { Solutions = x, Quality = qualities[index] })124 .OrderByDescending(x => x.Quality)125 .Select(x => x.Solutions)126 .ToArray();127 else128 sortedSimilarityMatrix = similarityMatrix129 .Select((x, index) => new { Solutions = x, Quality = qualities[index] })130 .OrderBy(x => x.Quality)131 .Select(x => x.Solutions)132 .ToArray();133 134 double[,] similarities = new double[similarityMatrix.Length, similarityMatrix[0].Length];135 for (int i = 0; i < similarityMatrix.Length; i++)136 for (int j = 0; j < similarityMatrix[0].Length; j++)137 similarities[i, j] = similarityMatrix[i][j];138 139 // calculate minimum, average and maximum similarities140 double similarity;141 double[] minSimilarities = new double[count];142 double[] avgSimilarities = new double[count];143 double[] maxSimilarities = new double[count];144 for (int i = 0; i < count; i++) {145 minSimilarities[i] = 1;146 avgSimilarities[i] = 0;147 maxSimilarities[i] = 0;148 for (int j = 0; j < count; j++) {149 if (i != j) {150 similarity = similarities[i, j];151 152 if ((similarity < 0) || (similarity > 1))153 throw new InvalidOperationException("Solution similarities have to be in the interval [0;1].");154 155 if (minSimilarities[i] > similarity) minSimilarities[i] = similarity;156 avgSimilarities[i] += similarity;157 if (maxSimilarities[i] < similarity) maxSimilarities[i] = similarity;158 }159 }160 avgSimilarities[i] = avgSimilarities[i] / (count - 1);161 }162 double avgMinSimilarity = minSimilarities.Average();163 double avgAvgSimilarity = avgSimilarities.Average();164 double avgMaxSimilarity = maxSimilarities.Average();165 166 // fetch results collection167 ResultCollection results;168 if (!ResultsParameter.ActualValue.ContainsKey(Name + " Results")) {169 results = new ResultCollection();170 ResultsParameter.ActualValue.Add(new Result(Name + " Results", results));171 } else {172 results = (ResultCollection)ResultsParameter.ActualValue[Name + " Results"].Value;173 }174 175 // store similarities176 HeatMap similaritiesHeatMap = new HeatMap(similarities, "Solution Similarities", 0.0, 1.0);177 if (!results.ContainsKey("Solution Similarities"))178 results.Add(new Result("Solution Similarities", similaritiesHeatMap));179 else180 results["Solution Similarities"].Value = similaritiesHeatMap;181 182 // store similarities history183 if (storeHistory) {184 if (!results.ContainsKey("Solution Similarities History")) {185 HeatMapHistory history = new HeatMapHistory();186 history.Add(similaritiesHeatMap);187 results.Add(new Result("Solution Similarities History", history));188 } else {189 ((HeatMapHistory)results["Solution Similarities History"].Value).Add(similaritiesHeatMap);190 }191 }192 193 // store average minimum, average and maximum similarity194 if (!results.ContainsKey("Average Minimum Solution Similarity"))195 results.Add(new Result("Average Minimum Solution Similarity", new DoubleValue(avgMinSimilarity)));196 else197 ((DoubleValue)results["Average Minimum Solution Similarity"].Value).Value = avgMinSimilarity;198 199 if (!results.ContainsKey("Average Average Solution Similarity"))200 results.Add(new Result("Average Average Solution Similarity", new DoubleValue(avgAvgSimilarity)));201 else202 ((DoubleValue)results["Average Average Solution Similarity"].Value).Value = avgAvgSimilarity;203 204 if (!results.ContainsKey("Average Maximum Solution Similarity"))205 results.Add(new Result("Average Maximum Solution Similarity", new DoubleValue(avgMaxSimilarity)));206 else207 ((DoubleValue)results["Average Maximum Solution Similarity"].Value).Value = avgMaxSimilarity;208 209 // store average minimum, average and maximum solution similarity data table210 DataTable minAvgMaxSimilarityDataTable;211 if (!results.ContainsKey("Average Minimum/Average/Maximum Solution Similarity")) {212 minAvgMaxSimilarityDataTable = new DataTable("Average Minimum/Average/Maximum Solution Similarity");213 minAvgMaxSimilarityDataTable.VisualProperties.XAxisTitle = "Iteration";214 minAvgMaxSimilarityDataTable.VisualProperties.YAxisTitle = "Solution Similarity";215 minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Minimum Solution Similarity", null));216 minAvgMaxSimilarityDataTable.Rows["Average Minimum Solution Similarity"].VisualProperties.StartIndexZero = true;217 minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Average Solution Similarity", null));218 minAvgMaxSimilarityDataTable.Rows["Average Average Solution Similarity"].VisualProperties.StartIndexZero = true;219 minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Maximum Solution Similarity", null));220 minAvgMaxSimilarityDataTable.Rows["Average Maximum Solution Similarity"].VisualProperties.StartIndexZero = true;221 results.Add(new Result("Average Minimum/Average/Maximum Solution Similarity", minAvgMaxSimilarityDataTable));222 } else {223 minAvgMaxSimilarityDataTable = (DataTable)results["Average Minimum/Average/Maximum Solution Similarity"].Value;224 }225 minAvgMaxSimilarityDataTable.Rows["Average Minimum Solution Similarity"].Values.Add(avgMinSimilarity);226 minAvgMaxSimilarityDataTable.Rows["Average Average Solution Similarity"].Values.Add(avgAvgSimilarity);227 minAvgMaxSimilarityDataTable.Rows["Average Maximum Solution Similarity"].Values.Add(avgMaxSimilarity);228 229 // store minimum, average, maximum similarities data table230 DataTable minAvgMaxSimilaritiesDataTable = new DataTable("Minimum/Average/Maximum Solution Similarities");231 minAvgMaxSimilaritiesDataTable.VisualProperties.XAxisTitle = "Solution Index";232 minAvgMaxSimilaritiesDataTable.VisualProperties.YAxisTitle = "Solution Similarity";233 minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Minimum Solution Similarity", null, minSimilarities));234 minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;235 minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Average Solution Similarity", null, avgSimilarities));236 minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;237 minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Maximum Solution Similarity", null, maxSimilarities));238 minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;239 if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities")) {240 results.Add(new Result("Minimum/Average/Maximum Solution Similarities", minAvgMaxSimilaritiesDataTable));241 } else {242 results["Minimum/Average/Maximum Solution Similarities"].Value = minAvgMaxSimilaritiesDataTable;243 }244 245 // store minimum, average, maximum similarities history246 if (storeHistory) {247 if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities History")) {248 DataTableHistory history = new DataTableHistory();249 history.Add(minAvgMaxSimilaritiesDataTable);250 results.Add(new Result("Minimum/Average/Maximum Solution Similarities History", history));251 } else {252 ((DataTableHistory)results["Minimum/Average/Maximum Solution Similarities History"].Value).Add(minAvgMaxSimilaritiesDataTable);253 }254 }255 }256 }257 return base.Apply();258 }259 47 } 48 #endregion 260 49 } -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ISimilarityBasedOperator.cs
r12012 r12069 24 24 namespace HeuristicLab.Optimization { 25 25 public interface ISimilarityBasedOperator : IOperator { 26 I SolutionSimilarityCalculator SimilarityCalculator { get; set; }26 IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { get; } 27 27 } 28 28 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r12012 r12069 233 233 Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()); 234 234 Operators.Add(new SymbolicExpressionTreeLengthAnalyzer()); 235 Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());235 Operators.Add(new PopulationSimilarityAnalyzer(new[] { new SymbolicExpressionTreeBottomUpSimilarityCalculator() })); 236 236 ParameterizeOperators(); 237 237 } … … 357 357 op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 358 358 } 359 foreach (var op in operators.OfType<SingleObjectivePopulationDiversityAnalyzer>()) {360 op.SimilarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator();361 }362 359 } 363 360 -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r12012 r12069 82 82 get { return Operators.OfType<BestKnapsackSolutionAnalyzer>().FirstOrDefault(); } 83 83 } 84 private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {85 get { return Operators.OfType< SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }84 private PopulationSimilarityAnalyzer PopulationSimilarityAnalyzer { 85 get { return Operators.OfType<PopulationSimilarityAnalyzer>().FirstOrDefault(); } 86 86 } 87 87 #endregion … … 248 248 BestKnapsackSolutionAnalyzer.ValuesParameter.Hidden = true; 249 249 } 250 251 if (SingleObjectivePopulationDiversityAnalyzer != null) {252 SingleObjectivePopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;253 SingleObjectivePopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;254 SingleObjectivePopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results";255 SingleObjectivePopulationDiversityAnalyzer.SimilarityCalculator = Operators.OfType<KnapsackSimilarityCalculator>().SingleOrDefault();256 }257 250 } 258 251 private void InitializeOperators() { … … 263 256 264 257 Operators.Add(new BestKnapsackSolutionAnalyzer()); 265 Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());258 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 266 259 ParameterizeAnalyzer(); 267 260 foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) { -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r12012 r12069 72 72 get { return Operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); } 73 73 } 74 private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {75 get { return Operators.OfType< SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }74 private PopulationSimilarityAnalyzer PopulationSimilarityAnalyzer { 75 get { return Operators.OfType<PopulationSimilarityAnalyzer>().FirstOrDefault(); } 76 76 } 77 77 #endregion … … 258 258 BestSingleObjectiveTestFunctionSolutionAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name; 259 259 } 260 261 if (SingleObjectivePopulationDiversityAnalyzer != null) {262 SingleObjectivePopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;263 SingleObjectivePopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;264 SingleObjectivePopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results";265 SingleObjectivePopulationDiversityAnalyzer.SimilarityCalculator = Operators.OfType<SingleObjectiveTestFunctionSimilarityCalculator>().SingleOrDefault();266 }267 260 } 268 261 private void InitializeOperators() { … … 272 265 273 266 Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer()); 274 Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());267 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 275 268 ParameterizeAnalyzers(); 276 269 Operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>()); -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r12012 r12069 82 82 get { return Operators.OfType<TSPAlleleFrequencyAnalyzer>().FirstOrDefault(); } 83 83 } 84 private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {85 get { return Operators.OfType< SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }84 private PopulationSimilarityAnalyzer PopulationSimilarityAnalyzer { 85 get { return Operators.OfType<PopulationSimilarityAnalyzer>().FirstOrDefault(); } 86 86 } 87 87 #endregion … … 239 239 Operators.Add(new BestTSPSolutionAnalyzer()); 240 240 Operators.Add(new TSPAlleleFrequencyAnalyzer()); 241 Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());241 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 242 242 ParameterizeAnalyzers(); 243 243 var operators = new HashSet<IPermutationOperator>(new IPermutationOperator[] { … … 318 318 TSPAlleleFrequencyAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 319 319 TSPAlleleFrequencyAnalyzer.ResultsParameter.ActualName = "Results"; 320 }321 322 if (SingleObjectivePopulationDiversityAnalyzer != null) {323 SingleObjectivePopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;324 SingleObjectivePopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;325 SingleObjectivePopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results";326 SingleObjectivePopulationDiversityAnalyzer.SimilarityCalculator = Operators.OfType<TSPSimilarityCalculator>().SingleOrDefault();327 320 } 328 321 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
r12012 r12069 114 114 set { SolutionCreatorParameter.Value = value; } 115 115 } 116 private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {117 get { return Operators.OfType< SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }116 private PopulationSimilarityAnalyzer PopulationSimilarityAnalyzer { 117 get { return Operators.OfType<PopulationSimilarityAnalyzer>().FirstOrDefault(); } 118 118 } 119 119 #endregion … … 256 256 ApplicationManager.Manager.GetInstances<IGeneralVRPOperator>().Cast<IOperator>()).OrderBy(op => op.Name)); 257 257 Operators.Add(new VRPSimilarityCalculator()); 258 Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());258 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 259 259 260 260 IVRPCreator defaultCreator = null; … … 291 291 op.QualityVariableName = ProblemInstance.SolutionEvaluator.QualityParameter.ActualName; 292 292 op.ProblemInstance = ProblemInstance; 293 }294 if (SingleObjectivePopulationDiversityAnalyzer != null) {295 SingleObjectivePopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;296 SingleObjectivePopulationDiversityAnalyzer.QualityParameter.ActualName = ProblemInstance.SolutionEvaluator.QualityParameter.ActualName;297 SingleObjectivePopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results";298 SingleObjectivePopulationDiversityAnalyzer.SimilarityCalculator = Operators.OfType<VRPSimilarityCalculator>().SingleOrDefault();299 293 } 300 294 }
Note: See TracChangeset
for help on using the changeset viewer.