Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12069


Ignore:
Timestamp:
02/25/15 10:07:54 (10 years ago)
Author:
jkarder
Message:

#2332: refactored operators and analyzers

  • removed quality and maximization parameters in SingleObjectivePopulationDiversityAnalyzer
  • renamed SingleObjectivePopulationDiversityAnalyzer to PopulationSimilarityAnalyzer
  • added ConstrainedValueParameter for similarity calculators of analyzer
  • added ValueLookupParameter for similarity calculator of the following operators:
    • DuplicatesSelector, ProgressiveOffspringPreserver, ReferenceSetUpdateMethod, SolutionPoolUpdateMethod
  • removed some wiring code in specific problems
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  
    251251        foreach (IAnalyzer analyzer in problem.Operators.OfType<IAnalyzer>()) {
    252252          if (!IsSubclassOfGeneric(typeof(AlleleFrequencyAnalyzer<>), analyzer.GetType()) &&
    253               !(analyzer is SingleObjectivePopulationDiversityAnalyzer)) {
     253              !(analyzer is PopulationSimilarityAnalyzer)) {
    254254            IAnalyzer clone = analyzer.Clone() as IAnalyzer;
    255255            foreach (IScopeTreeLookupParameter param in clone.Parameters.OfType<IScopeTreeLookupParameter>())
  • trunk/sources/HeuristicLab.Algorithms.RAPGA/3.3/DuplicatesSelector.cs

    r12012 r12069  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Optimization;
     27using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829using HeuristicLab.Selection;
     
    3738  [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.")]
    3839  [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    }
    4444
    4545    [StorableConstructor]
    4646    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."));
    5051    }
    51     public DuplicatesSelector() : base() { }
    5252
    5353    public override IDeepCloneable Clone(Cloner cloner) {
    5454      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
    5564    }
    5665
     
    6170      for (int i = 0; i < scopes.Count; i++)
    6271        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]);
    6473
    6574
  • trunk/sources/HeuristicLab.Algorithms.RAPGA/3.3/ProgressiveOffspringPreserver.cs

    r12012 r12069  
    3838  [Item("ProgressiveOffspringPreserver", "An operator that progressively selects offspring by adding it to a scope list. The operator also performs duplication control.")]
    3939  [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 {
    4641    #region Parameter Properties
    4742    public ScopeParameter CurrentScopeParameter {
     
    5651    public ILookupParameter<IntValue> MaximumPopulationSizeParameter {
    5752      get { return (ILookupParameter<IntValue>)Parameters["MaximumPopulationSize"]; }
     53    }
     54    public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     55      get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    5856    }
    5957    #endregion
     
    7674    [StorableConstructor]
    7775    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) { }
    8277    public ProgressiveOffspringPreserver()
    8378      : base() {
     79      #region Create parameters
    8480      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the offspring."));
    8581      Parameters.Add(new LookupParameter<ScopeList>("OffspringList", "The list that contains the offspring."));
    8682      Parameters.Add(new LookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
    8783      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
    8886    }
    8987
    9088    public override IDeepCloneable Clone(Cloner cloner) {
    9189      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
    9299    }
    93100
     
    98105          var storedOffspringScope = new Scope();
    99106          storedOffspringScope.SubScopes.AddRange(OffspringList);
    100           var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(CurrentScope, storedOffspringScope);
     107          var similarityMatrix = SimilarityCalculatorParameter.ActualValue.CalculateSolutionCrowdSimilarity(CurrentScope, storedOffspringScope);
    101108
    102109          var createdOffspring = CurrentScope.SubScopes.ToArray();
  • trunk/sources/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs

    r12012 r12069  
    394394      RAPGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    395395      RAPGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    396       foreach (ISimilarityBasedOperator op in RAPGAMainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
    397         op.SimilarityCalculator = SimilarityCalculator;
    398396    }
    399397    private void ParameterizeStochasticOperator(IOperator op) {
  • trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r12012 r12069  
    3636  [Item("ReferenceSetUpdateMethod", "An operator that updates the reference set.")]
    3737  [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 {
    4439    #region Parameter properties
    4540    public ScopeParameter CurrentScopeParameter {
     
    4843    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    4944      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     45    }
     46    public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     47      get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    5048    }
    5149    #endregion
     
    6260    [StorableConstructor]
    6361    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) { }
    6863    public ReferenceSetUpdateMethod()
    6964      : base() {
     
    7166      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the population and the reference set."));
    7267      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."));
    7369      #endregion
    7470    }
     
    7874    }
    7975
     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
    8085    public override IOperation Apply() {
    8186      var populationSimilarity = new Dictionary<IScope, double>();
    8287      var populationScope = CurrentScope.SubScopes[0];
    8388      var refSetScope = CurrentScope.SubScopes[1];
    84       var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(populationScope, refSetScope);
     89      var similarityMatrix = SimilarityCalculatorParameter.ActualValue.CalculateSolutionCrowdSimilarity(populationScope, refSetScope);
    8590      for (int i = 0; i < populationScope.SubScopes.Count; i++) {
    8691        populationSimilarity[populationScope.SubScopes[i]] = similarityMatrix[i].Sum();
  • trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r12012 r12069  
    423423        MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    424424        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;
    427425      }
    428426    }
  • trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r12012 r12069  
    3636  [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")]
    3737  [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 {
    4439    #region Parameter properties
    4540    public ScopeParameter CurrentScopeParameter {
     
    5752    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    5853      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     54    }
     55    public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     56      get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    5957    }
    6058    #endregion
     
    8280    [StorableConstructor]
    8381    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() {
    9585      #region Create parameters
    9686      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that is the reference set."));
     
    9989      Parameters.Add(new ValueLookupParameter<IItem>("Quality", "This parameter is used for name translation only."));
    10090      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."));
    101105      #endregion
    102106    }
     
    132136      if (orderedOffspring.Any(hasBetterQuality)) {
    133137        // produce the set union
    134         var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), SimilarityCalculator);
     138        var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), SimilarityCalculatorParameter.ActualValue);
    135139        if (union.Count() > orderedParents.Count()) {
    136140          var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingImprovementOperator.cs

    r12012 r12069  
    279279        foreach (IAnalyzer analyzer in problem.Operators.OfType<IAnalyzer>()) {
    280280          if (!IsSubclassOfGeneric(typeof(AlleleFrequencyAnalyzer<>), analyzer.GetType()) &&
    281               !(analyzer is SingleObjectivePopulationDiversityAnalyzer)) {
     281              !(analyzer is PopulationSimilarityAnalyzer)) {
    282282            IAnalyzer clone = analyzer.Clone() as IAnalyzer;
    283283            foreach (IScopeTreeLookupParameter param in clone.Parameters.OfType<IScopeTreeLookupParameter>())
  • trunk/sources/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r11914 r12069  
    148148    <Compile Include="MultiObjective\ParetoFrontAnalyzer.cs" />
    149149    <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" />
    152153    <Compile Include="QualityAnalysis\BestAverageWorstQualityAnalyzer.cs" />
    153154    <Compile Include="QualityAnalysis\BestAverageWorstQualityCalculator.cs" />
  • trunk/sources/HeuristicLab.Analysis/3.3/PopulationSimilarityAnalysis/SingleObjectivePopulationDiversityAnalyzer.cs

    r12012 r12069  
    2121
    2222using System;
    23 using System.Linq;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    27 using HeuristicLab.Operators;
    28 using HeuristicLab.Optimization;
    29 using HeuristicLab.Parameters;
    3025using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.PluginInfrastructure;
    3127
    3228namespace HeuristicLab.Analysis {
     29  // use HeuristicLab.Analysis.PopulationSimilarityAnalyzer instead
     30  // BackwardsCompatibility3.3
     31  #region Backwards compatible code, remove with 3.4
    3332  /// <summary>
    3433  /// An operator for analyzing the solution diversity in a population.
    3534  /// </summary>
     35  [Obsolete]
     36  [NonDiscoverableType]
    3637  [Item("SingleObjectivePopulationDiversityAnalyzer", "An operator for analyzing the solution diversity in a population.")]
    3738  [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 {
    7040    [StorableConstructor]
    7141    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) { }
    9143
    9244    public override IDeepCloneable Clone(Cloner cloner) {
    9345      return new SingleObjectivePopulationDiversityAnalyzer(this, cloner);
    9446    }
    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 interval
    100       // to make sure the solutions are analyzed on the first application of this operator
    101       if (updateCounter == null) {
    102         updateCounter = new IntValue(updateInterval);
    103         UpdateCounterParameter.ActualValue = updateCounter;
    104       } else updateCounter.Value++;
    105 
    106       //analyze solutions only every 'updateInterval' times
    107       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 similarities
    117           var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(CurrentScopeParameter.ActualValue);
    118 
    119           // sort similarities by quality
    120           double[][] sortedSimilarityMatrix = null;
    121           if (max)
    122             sortedSimilarityMatrix = similarityMatrix
    123               .Select((x, index) => new { Solutions = x, Quality = qualities[index] })
    124               .OrderByDescending(x => x.Quality)
    125               .Select(x => x.Solutions)
    126               .ToArray();
    127           else
    128             sortedSimilarityMatrix = similarityMatrix
    129               .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 similarities
    140           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 collection
    167           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 similarities
    176           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           else
    180             results["Solution Similarities"].Value = similaritiesHeatMap;
    181 
    182           // store similarities history
    183           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 similarity
    194           if (!results.ContainsKey("Average Minimum Solution Similarity"))
    195             results.Add(new Result("Average Minimum Solution Similarity", new DoubleValue(avgMinSimilarity)));
    196           else
    197             ((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           else
    202             ((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           else
    207             ((DoubleValue)results["Average Maximum Solution Similarity"].Value).Value = avgMaxSimilarity;
    208 
    209           // store average minimum, average and maximum solution similarity data table
    210           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 table
    230           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 history
    246           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     }
    25947  }
     48  #endregion
    26049}
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ISimilarityBasedOperator.cs

    r12012 r12069  
    2424namespace HeuristicLab.Optimization {
    2525  public interface ISimilarityBasedOperator : IOperator {
    26     ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
     26    IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { get; }
    2727  }
    2828}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r12012 r12069  
    233233      Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer());
    234234      Operators.Add(new SymbolicExpressionTreeLengthAnalyzer());
    235       Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());
     235      Operators.Add(new PopulationSimilarityAnalyzer(new[] { new SymbolicExpressionTreeBottomUpSimilarityCalculator() }));
    236236      ParameterizeOperators();
    237237    }
     
    357357        op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    358358      }
    359       foreach (var op in operators.OfType<SingleObjectivePopulationDiversityAnalyzer>()) {
    360         op.SimilarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator();
    361       }
    362359    }
    363360
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r12012 r12069  
    8282      get { return Operators.OfType<BestKnapsackSolutionAnalyzer>().FirstOrDefault(); }
    8383    }
    84     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    85       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }
     84    private PopulationSimilarityAnalyzer PopulationSimilarityAnalyzer {
     85      get { return Operators.OfType<PopulationSimilarityAnalyzer>().FirstOrDefault(); }
    8686    }
    8787    #endregion
     
    248248        BestKnapsackSolutionAnalyzer.ValuesParameter.Hidden = true;
    249249      }
    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       }
    257250    }
    258251    private void InitializeOperators() {
     
    263256
    264257      Operators.Add(new BestKnapsackSolutionAnalyzer());
    265       Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());
     258      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    266259      ParameterizeAnalyzer();
    267260      foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r12012 r12069  
    7272      get { return Operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); }
    7373    }
    74     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    75       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }
     74    private PopulationSimilarityAnalyzer PopulationSimilarityAnalyzer {
     75      get { return Operators.OfType<PopulationSimilarityAnalyzer>().FirstOrDefault(); }
    7676    }
    7777    #endregion
     
    258258        BestSingleObjectiveTestFunctionSolutionAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name;
    259259      }
    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       }
    267260    }
    268261    private void InitializeOperators() {
     
    272265
    273266      Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer());
    274       Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());
     267      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    275268      ParameterizeAnalyzers();
    276269      Operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r12012 r12069  
    8282      get { return Operators.OfType<TSPAlleleFrequencyAnalyzer>().FirstOrDefault(); }
    8383    }
    84     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    85       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }
     84    private PopulationSimilarityAnalyzer PopulationSimilarityAnalyzer {
     85      get { return Operators.OfType<PopulationSimilarityAnalyzer>().FirstOrDefault(); }
    8686    }
    8787    #endregion
     
    239239      Operators.Add(new BestTSPSolutionAnalyzer());
    240240      Operators.Add(new TSPAlleleFrequencyAnalyzer());
    241       Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());
     241      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    242242      ParameterizeAnalyzers();
    243243      var operators = new HashSet<IPermutationOperator>(new IPermutationOperator[] {
     
    318318        TSPAlleleFrequencyAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
    319319        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();
    327320      }
    328321    }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r12012 r12069  
    114114      set { SolutionCreatorParameter.Value = value; }
    115115    }
    116     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    117       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }
     116    private PopulationSimilarityAnalyzer PopulationSimilarityAnalyzer {
     117      get { return Operators.OfType<PopulationSimilarityAnalyzer>().FirstOrDefault(); }
    118118    }
    119119    #endregion
     
    256256          ApplicationManager.Manager.GetInstances<IGeneralVRPOperator>().Cast<IOperator>()).OrderBy(op => op.Name));
    257257        Operators.Add(new VRPSimilarityCalculator());
    258         Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());
     258        Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    259259
    260260        IVRPCreator defaultCreator = null;
     
    291291          op.QualityVariableName = ProblemInstance.SolutionEvaluator.QualityParameter.ActualName;
    292292          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();
    299293        }
    300294      }
Note: See TracChangeset for help on using the changeset viewer.