Changeset 12280


Ignore:
Timestamp:
04/01/15 17:06:17 (5 years ago)
Author:
mkommend
Message:

#2332: Merged all changes from this ticket into stable.

Location:
stable
Files:
5 deleted
37 edited
3 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchImprovementOperator.cs

    r12009 r12280  
    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>())
  • stable/HeuristicLab.Algorithms.RAPGA/3.3/DuplicatesSelector.cs

    r12009 r12280  
    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
  • stable/HeuristicLab.Algorithms.RAPGA/3.3/ProgressiveOffspringPreserver.cs

    r12009 r12280  
    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();
  • stable/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs

    r12009 r12280  
    103103      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
    104104    }
    105     public IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
    106       get { return (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     105    public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     106      get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    107107    }
    108108    #endregion
     
    173173      set { MaximumGenerationsParameter.Value = value; }
    174174    }
    175     public ISingleObjectiveSolutionSimilarityCalculator SimilarityCalculator {
     175    public ISolutionSimilarityCalculator SimilarityCalculator {
    176176      get { return SimilarityCalculatorParameter.Value; }
    177177      set { SimilarityCalculatorParameter.Value = value; }
     
    204204      if (!Parameters.ContainsKey("ReevaluateElites")) {
    205205        Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", (BoolValue)new BoolValue(false).AsReadOnly()) { Hidden = true });
     206      }
     207      if (Parameters.ContainsKey("SimilarityCalculator")) {
     208#pragma warning disable 0618
     209        var oldParameter = (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"];
     210#pragma warning restore 0618
     211        Parameters.Remove(oldParameter);
     212        var newParameter = new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.", new ItemSet<ISolutionSimilarityCalculator>(oldParameter.ValidValues));
     213        var selectedSimilarityCalculator = newParameter.ValidValues.SingleOrDefault(x => x.GetType() == oldParameter.Value.GetType());
     214        newParameter.Value = selectedSimilarityCalculator;
     215        Parameters.Add(newParameter);
    206216      }
    207217      #endregion
     
    234244      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    235245      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    236       Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
     246      Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    237247
    238248      RandomCreator randomCreator = new RandomCreator();
     
    394404      RAPGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    395405      RAPGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    396       foreach (ISimilarityBasedOperator op in RAPGAMainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
    397         op.SimilarityCalculator = SimilarityCalculator;
    398406    }
    399407    private void ParameterizeStochasticOperator(IOperator op) {
     
    450458    }
    451459    private void ParameterizeSimilarityCalculators() {
    452       foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
     460      foreach (ISolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
    453461        calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
    454462      }
     
    495503    }
    496504    private void UpdateSimilarityCalculators() {
    497       ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     505      ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
    498506      SimilarityCalculatorParameter.ValidValues.Clear();
    499       ISingleObjectiveSolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
    500 
    501       SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
    502       SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator());
    503 
    504       foreach (ISingleObjectiveSolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>())
     507      ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
     508
     509      foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
    505510        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
    506511
     512      if (!SimilarityCalculatorParameter.ValidValues.OfType<QualitySimilarityCalculator>().Any())
     513        SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator {
     514          QualityVariableName = Problem.Evaluator.QualityParameter.ActualName
     515        });
     516      if (!SimilarityCalculatorParameter.ValidValues.OfType<NoSimilarityCalculator>().Any())
     517        SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator());
     518
    507519      if (oldSimilarityCalculator != null) {
    508         ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     520        ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
    509521        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
    510522        else oldSimilarityCalculator = null;
  • stable/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r12009 r12280  
    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();
  • stable/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r12009 r12280  
    8888      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    8989    }
    90     public IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
    91       get { return (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     90    public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     91      get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    9292    }
    9393    #endregion
     
    138138      set { SetSeedRandomlyParameter.Value = value; }
    139139    }
    140     public ISingleObjectiveSolutionSimilarityCalculator SimilarityCalculator {
     140    public ISolutionSimilarityCalculator SimilarityCalculator {
    141141      get { return SimilarityCalculatorParameter.Value; }
    142142      set { SimilarityCalculatorParameter.Value = value; }
     
    160160    [StorableHook(HookType.AfterDeserialization)]
    161161    private void AfterDeserialization() {
     162      // BackwardsCompatibility3.3
     163      #region Backwards compatible code, remove with 3.4
     164      if (Parameters.ContainsKey("SimilarityCalculator")) {
     165#pragma warning disable 0618
     166        var oldParameter = (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"];
     167#pragma warning restore 0618
     168        Parameters.Remove(oldParameter);
     169        var newParameter = new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.", new ItemSet<ISolutionSimilarityCalculator>(oldParameter.ValidValues));
     170        var selectedSimilarityCalculator = newParameter.ValidValues.SingleOrDefault(x => x.GetType() == oldParameter.Value.GetType());
     171        newParameter.Value = selectedSimilarityCalculator;
     172        Parameters.Add(newParameter);
     173      }
     174      #endregion
    162175      Initialize();
    163176    }
     
    184197      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    185198      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    186       Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
     199      Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    187200      #endregion
    188201
     
    390403    }
    391404    private void UpdateSimilarityCalculators() {
    392       ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     405      ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
    393406      SimilarityCalculatorParameter.ValidValues.Clear();
    394       ISingleObjectiveSolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
    395 
    396       SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
    397       SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
    398 
    399       foreach (ISingleObjectiveSolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>())
     407      ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
     408
     409      foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
    400410        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
    401411
     412      if (!SimilarityCalculatorParameter.ValidValues.OfType<QualitySimilarityCalculator>().Any())
     413        SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator {
     414          QualityVariableName = Problem.Evaluator.QualityParameter.ActualName
     415        });
     416      if (!SimilarityCalculatorParameter.ValidValues.OfType<NoSimilarityCalculator>().Any())
     417        SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator());
     418
    402419      if (oldSimilarityCalculator != null) {
    403         ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     420        ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
    404421        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
    405422        else oldSimilarityCalculator = null;
     
    423440        MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    424441        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;
    427442      }
    428443    }
     
    449464    }
    450465    private void ParameterizeSimilarityCalculators() {
    451       foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
     466      foreach (ISolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
    452467        calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
    453468      }
  • stable/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r12009 r12280  
    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) :
  • stable/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingImprovementOperator.cs

    r12009 r12280  
    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>())
  • stable/HeuristicLab.Analysis

  • stable/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r12154 r12280  
    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" />
  • stable/HeuristicLab.Analysis/3.3/PopulationSimilarityAnalysis/PopulationSimilarityAnalyzer.cs

    r12069 r12280  
    125125        updateCounter = new IntValue(updateInterval);
    126126        UpdateCounterParameter.ActualValue = updateCounter;
    127       } else updateCounter.Value++;
    128 
     127      }
    129128      //analyze solutions only every 'updateInterval' times
    130       if (updateCounter.Value == updateInterval) {
    131         updateCounter.Value = 0;
    132 
    133         bool storeHistory = StoreHistoryParameter.Value.Value;
    134         int count = CurrentScopeParameter.ActualValue.SubScopes.Count;
    135 
    136         if (count > 1) {
    137           var similarityCalculator = SimilarityCalculatorParameter.Value;
    138           // calculate solution similarities
    139           var similarityMatrix = similarityCalculator.CalculateSolutionCrowdSimilarity(CurrentScopeParameter.ActualValue);
    140           double[,] similarities = new double[similarityMatrix.Length, similarityMatrix[0].Length];
    141           for (int i = 0; i < similarityMatrix.Length; i++)
    142             for (int j = 0; j < similarityMatrix[0].Length; j++)
    143               similarities[i, j] = similarityMatrix[i][j];
    144 
    145           // calculate minimum, average and maximum similarities
    146           double similarity;
    147           double[] minSimilarities = new double[count];
    148           double[] avgSimilarities = new double[count];
    149           double[] maxSimilarities = new double[count];
    150           for (int i = 0; i < count; i++) {
    151             minSimilarities[i] = 1;
    152             avgSimilarities[i] = 0;
    153             maxSimilarities[i] = 0;
    154             for (int j = 0; j < count; j++) {
    155               if (i != j) {
    156                 similarity = similarities[i, j];
    157 
    158                 if ((similarity < 0) || (similarity > 1))
    159                   throw new InvalidOperationException("Solution similarities have to be in the interval [0;1].");
    160 
    161                 if (minSimilarities[i] > similarity) minSimilarities[i] = similarity;
    162                 avgSimilarities[i] += similarity;
    163                 if (maxSimilarities[i] < similarity) maxSimilarities[i] = similarity;
    164               }
    165             }
    166             avgSimilarities[i] = avgSimilarities[i] / (count - 1);
    167           }
    168           double avgMinSimilarity = minSimilarities.Average();
    169           double avgAvgSimilarity = avgSimilarities.Average();
    170           double avgMaxSimilarity = maxSimilarities.Average();
    171 
    172           // fetch results collection
    173           ResultCollection results;
    174           if (!ResultsParameter.ActualValue.ContainsKey(DiversityResultName)) {
    175             results = new ResultCollection();
    176             ResultsParameter.ActualValue.Add(new Result(DiversityResultName, results));
    177           } else {
    178             results = (ResultCollection)ResultsParameter.ActualValue[DiversityResultName].Value;
    179           }
    180 
    181           // store similarities
    182           HeatMap similaritiesHeatMap = new HeatMap(similarities, "Solution Similarities", 0.0, 1.0);
    183           if (!results.ContainsKey("Solution Similarities"))
    184             results.Add(new Result("Solution Similarities", similaritiesHeatMap));
    185           else
    186             results["Solution Similarities"].Value = similaritiesHeatMap;
    187 
    188           // store similarities history
    189           if (storeHistory) {
    190             if (!results.ContainsKey("Solution Similarities History")) {
    191               HeatMapHistory history = new HeatMapHistory();
    192               history.Add(similaritiesHeatMap);
    193               results.Add(new Result("Solution Similarities History", history));
    194             } else {
    195               ((HeatMapHistory)results["Solution Similarities History"].Value).Add(similaritiesHeatMap);
     129      if (updateCounter.Value != updateInterval) {
     130        updateCounter.Value++;
     131        return base.Apply();
     132      }
     133      updateCounter.Value = 1;
     134
     135      bool storeHistory = StoreHistoryParameter.Value.Value;
     136      int count = CurrentScopeParameter.ActualValue.SubScopes.Count;
     137
     138      if (count > 1) {
     139        var similarityCalculator = SimilarityCalculatorParameter.Value;
     140        // calculate solution similarities
     141        var similarityMatrix = similarityCalculator.CalculateSolutionCrowdSimilarity(CurrentScopeParameter.ActualValue);
     142        double[,] similarities = new double[similarityMatrix.Length, similarityMatrix[0].Length];
     143        for (int i = 0; i < similarityMatrix.Length; i++)
     144          for (int j = 0; j < similarityMatrix[0].Length; j++)
     145            similarities[i, j] = similarityMatrix[i][j];
     146
     147        // calculate minimum, average and maximum similarities
     148        double similarity;
     149        double[] minSimilarities = new double[count];
     150        double[] avgSimilarities = new double[count];
     151        double[] maxSimilarities = new double[count];
     152        for (int i = 0; i < count; i++) {
     153          minSimilarities[i] = 1;
     154          avgSimilarities[i] = 0;
     155          maxSimilarities[i] = 0;
     156          for (int j = 0; j < count; j++) {
     157            if (i != j) {
     158              similarity = similarities[i, j];
     159
     160              if ((similarity < 0) || (similarity > 1))
     161                throw new InvalidOperationException("Solution similarities have to be in the interval [0;1].");
     162
     163              if (minSimilarities[i] > similarity) minSimilarities[i] = similarity;
     164              avgSimilarities[i] += similarity;
     165              if (maxSimilarities[i] < similarity) maxSimilarities[i] = similarity;
    196166            }
    197167          }
    198 
    199           // store average minimum, average and maximum similarity
    200           if (!results.ContainsKey("Average Minimum Solution Similarity"))
    201             results.Add(new Result("Average Minimum Solution Similarity", new DoubleValue(avgMinSimilarity)));
    202           else
    203             ((DoubleValue)results["Average Minimum Solution Similarity"].Value).Value = avgMinSimilarity;
    204 
    205           if (!results.ContainsKey("Average Average Solution Similarity"))
    206             results.Add(new Result("Average Average Solution Similarity", new DoubleValue(avgAvgSimilarity)));
    207           else
    208             ((DoubleValue)results["Average Average Solution Similarity"].Value).Value = avgAvgSimilarity;
    209 
    210           if (!results.ContainsKey("Average Maximum Solution Similarity"))
    211             results.Add(new Result("Average Maximum Solution Similarity", new DoubleValue(avgMaxSimilarity)));
    212           else
    213             ((DoubleValue)results["Average Maximum Solution Similarity"].Value).Value = avgMaxSimilarity;
    214 
    215           // store average minimum, average and maximum solution similarity data table
    216           DataTable minAvgMaxSimilarityDataTable;
    217           if (!results.ContainsKey("Average Minimum/Average/Maximum Solution Similarity")) {
    218             minAvgMaxSimilarityDataTable = new DataTable("Average Minimum/Average/Maximum Solution Similarity");
    219             minAvgMaxSimilarityDataTable.VisualProperties.XAxisTitle = "Iteration";
    220             minAvgMaxSimilarityDataTable.VisualProperties.YAxisTitle = "Solution Similarity";
    221             minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Minimum Solution Similarity", null));
    222             minAvgMaxSimilarityDataTable.Rows["Average Minimum Solution Similarity"].VisualProperties.StartIndexZero = true;
    223             minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Average Solution Similarity", null));
    224             minAvgMaxSimilarityDataTable.Rows["Average Average Solution Similarity"].VisualProperties.StartIndexZero = true;
    225             minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Maximum Solution Similarity", null));
    226             minAvgMaxSimilarityDataTable.Rows["Average Maximum Solution Similarity"].VisualProperties.StartIndexZero = true;
    227             results.Add(new Result("Average Minimum/Average/Maximum Solution Similarity", minAvgMaxSimilarityDataTable));
     168          avgSimilarities[i] = avgSimilarities[i] / (count - 1);
     169        }
     170        double avgMinSimilarity = minSimilarities.Average();
     171        double avgAvgSimilarity = avgSimilarities.Average();
     172        double avgMaxSimilarity = maxSimilarities.Average();
     173
     174        // fetch results collection
     175        ResultCollection results;
     176        if (!ResultsParameter.ActualValue.ContainsKey(DiversityResultName)) {
     177          results = new ResultCollection();
     178          ResultsParameter.ActualValue.Add(new Result(DiversityResultName, results));
     179        } else {
     180          results = (ResultCollection)ResultsParameter.ActualValue[DiversityResultName].Value;
     181        }
     182
     183        // store similarities
     184        HeatMap similaritiesHeatMap = new HeatMap(similarities, "Solution Similarities", 0.0, 1.0);
     185        if (!results.ContainsKey("Solution Similarities"))
     186          results.Add(new Result("Solution Similarities", similaritiesHeatMap));
     187        else
     188          results["Solution Similarities"].Value = similaritiesHeatMap;
     189
     190        // store similarities history
     191        if (storeHistory) {
     192          if (!results.ContainsKey("Solution Similarities History")) {
     193            HeatMapHistory history = new HeatMapHistory();
     194            history.Add(similaritiesHeatMap);
     195            results.Add(new Result("Solution Similarities History", history));
    228196          } else {
    229             minAvgMaxSimilarityDataTable = (DataTable)results["Average Minimum/Average/Maximum Solution Similarity"].Value;
     197            ((HeatMapHistory)results["Solution Similarities History"].Value).Add(similaritiesHeatMap);
    230198          }
    231           minAvgMaxSimilarityDataTable.Rows["Average Minimum Solution Similarity"].Values.Add(avgMinSimilarity);
    232           minAvgMaxSimilarityDataTable.Rows["Average Average Solution Similarity"].Values.Add(avgAvgSimilarity);
    233           minAvgMaxSimilarityDataTable.Rows["Average Maximum Solution Similarity"].Values.Add(avgMaxSimilarity);
    234 
    235           // store minimum, average, maximum similarities data table
    236           DataTable minAvgMaxSimilaritiesDataTable = new DataTable("Minimum/Average/Maximum Solution Similarities");
    237           minAvgMaxSimilaritiesDataTable.VisualProperties.XAxisTitle = "Solution Index";
    238           minAvgMaxSimilaritiesDataTable.VisualProperties.YAxisTitle = "Solution Similarity";
    239           minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Minimum Solution Similarity", null, minSimilarities));
    240           minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
    241           minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Average Solution Similarity", null, avgSimilarities));
    242           minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
    243           minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Maximum Solution Similarity", null, maxSimilarities));
    244           minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
    245           if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities")) {
    246             results.Add(new Result("Minimum/Average/Maximum Solution Similarities", minAvgMaxSimilaritiesDataTable));
     199        }
     200
     201        // store average minimum, average and maximum similarity
     202        if (!results.ContainsKey("Average Minimum Solution Similarity"))
     203          results.Add(new Result("Average Minimum Solution Similarity", new DoubleValue(avgMinSimilarity)));
     204        else
     205          ((DoubleValue)results["Average Minimum Solution Similarity"].Value).Value = avgMinSimilarity;
     206
     207        if (!results.ContainsKey("Average Average Solution Similarity"))
     208          results.Add(new Result("Average Average Solution Similarity", new DoubleValue(avgAvgSimilarity)));
     209        else
     210          ((DoubleValue)results["Average Average Solution Similarity"].Value).Value = avgAvgSimilarity;
     211
     212        if (!results.ContainsKey("Average Maximum Solution Similarity"))
     213          results.Add(new Result("Average Maximum Solution Similarity", new DoubleValue(avgMaxSimilarity)));
     214        else
     215          ((DoubleValue)results["Average Maximum Solution Similarity"].Value).Value = avgMaxSimilarity;
     216
     217        // store average minimum, average and maximum solution similarity data table
     218        DataTable minAvgMaxSimilarityDataTable;
     219        if (!results.ContainsKey("Average Minimum/Average/Maximum Solution Similarity")) {
     220          minAvgMaxSimilarityDataTable = new DataTable("Average Minimum/Average/Maximum Solution Similarity");
     221          minAvgMaxSimilarityDataTable.VisualProperties.XAxisTitle = "Iteration";
     222          minAvgMaxSimilarityDataTable.VisualProperties.YAxisTitle = "Solution Similarity";
     223          minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Minimum Solution Similarity", null));
     224          minAvgMaxSimilarityDataTable.Rows["Average Minimum Solution Similarity"].VisualProperties.StartIndexZero = true;
     225          minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Average Solution Similarity", null));
     226          minAvgMaxSimilarityDataTable.Rows["Average Average Solution Similarity"].VisualProperties.StartIndexZero = true;
     227          minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Maximum Solution Similarity", null));
     228          minAvgMaxSimilarityDataTable.Rows["Average Maximum Solution Similarity"].VisualProperties.StartIndexZero = true;
     229          results.Add(new Result("Average Minimum/Average/Maximum Solution Similarity", minAvgMaxSimilarityDataTable));
     230        } else {
     231          minAvgMaxSimilarityDataTable = (DataTable)results["Average Minimum/Average/Maximum Solution Similarity"].Value;
     232        }
     233        minAvgMaxSimilarityDataTable.Rows["Average Minimum Solution Similarity"].Values.Add(avgMinSimilarity);
     234        minAvgMaxSimilarityDataTable.Rows["Average Average Solution Similarity"].Values.Add(avgAvgSimilarity);
     235        minAvgMaxSimilarityDataTable.Rows["Average Maximum Solution Similarity"].Values.Add(avgMaxSimilarity);
     236
     237        // store minimum, average, maximum similarities data table
     238        DataTable minAvgMaxSimilaritiesDataTable = new DataTable("Minimum/Average/Maximum Solution Similarities");
     239        minAvgMaxSimilaritiesDataTable.VisualProperties.XAxisTitle = "Solution Index";
     240        minAvgMaxSimilaritiesDataTable.VisualProperties.YAxisTitle = "Solution Similarity";
     241        minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Minimum Solution Similarity", null, minSimilarities));
     242        minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
     243        minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Average Solution Similarity", null, avgSimilarities));
     244        minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
     245        minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Maximum Solution Similarity", null, maxSimilarities));
     246        minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
     247        if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities")) {
     248          results.Add(new Result("Minimum/Average/Maximum Solution Similarities", minAvgMaxSimilaritiesDataTable));
     249        } else {
     250          results["Minimum/Average/Maximum Solution Similarities"].Value = minAvgMaxSimilaritiesDataTable;
     251        }
     252
     253        // store minimum, average, maximum similarities history
     254        if (storeHistory) {
     255          if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities History")) {
     256            DataTableHistory history = new DataTableHistory();
     257            history.Add(minAvgMaxSimilaritiesDataTable);
     258            results.Add(new Result("Minimum/Average/Maximum Solution Similarities History", history));
    247259          } else {
    248             results["Minimum/Average/Maximum Solution Similarities"].Value = minAvgMaxSimilaritiesDataTable;
    249           }
    250 
    251           // store minimum, average, maximum similarities history
    252           if (storeHistory) {
    253             if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities History")) {
    254               DataTableHistory history = new DataTableHistory();
    255               history.Add(minAvgMaxSimilaritiesDataTable);
    256               results.Add(new Result("Minimum/Average/Maximum Solution Similarities History", history));
    257             } else {
    258               ((DataTableHistory)results["Minimum/Average/Maximum Solution Similarities History"].Value).Add(minAvgMaxSimilaritiesDataTable);
    259             }
     260            ((DataTableHistory)results["Minimum/Average/Maximum Solution Similarities History"].Value).Add(minAvgMaxSimilaritiesDataTable);
    260261          }
    261262        }
  • stable/HeuristicLab.Optimization

  • stable/HeuristicLab.Optimization.Operators/3.3/NoSimilarityCalculator.cs

    r12009 r12280  
    3232  [Item("NoSimilarityCalculator", "An item that performs similarity calculation between two solutions. The item always considers two solutions to be distinct.")]
    3333  public sealed class NoSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
     34    protected override bool IsCommutative { get { return true; } }
     35
    3436    private NoSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3537    private NoSimilarityCalculator(NoSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
  • stable/HeuristicLab.Optimization.Operators/3.3/QualitySimilarityCalculator.cs

    r12009 r12280  
    3434  [Item("QualitySimilarityCalculator", "An item that performs similarity calculation between two solutions. The item only considers the qualities of the two solutions.")]
    3535  public sealed class QualitySimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
     36    protected override bool IsCommutative { get { return true; } }
     37
    3638    private QualitySimilarityCalculator(bool deserializing) : base(deserializing) { }
    3739    private QualitySimilarityCalculator(QualitySimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
  • stable/HeuristicLab.Optimization.Operators/3.3/SingleObjectiveSolutionSimilarityCalculator.cs

    r12009 r12280  
    3131  [Item("SimilarityCalculator", "A base class for items that perform similarity calculation between two solutions.")]
    3232  [StorableClass]
     33#pragma warning disable 0618
    3334  public abstract class SingleObjectiveSolutionSimilarityCalculator : SolutionSimilarityCalculator, ISingleObjectiveSolutionSimilarityCalculator {
    34     #region Properties
    35     [Storable]
    36     public string SolutionVariableName { get; set; }
    37     [Storable]
    38     public string QualityVariableName { get; set; }
    39     #endregion
    40 
     35#pragma warning restore 0618
    4136    [StorableConstructor]
    4237    protected SingleObjectiveSolutionSimilarityCalculator(bool deserializing) : base(deserializing) { }
    4338    protected SingleObjectiveSolutionSimilarityCalculator(SingleObjectiveSolutionSimilarityCalculator original, Cloner cloner)
    4439      : base(original, cloner) {
    45       this.SolutionVariableName = original.SolutionVariableName;
    46       this.QualityVariableName = original.QualityVariableName;
     40
    4741    }
    4842    protected SingleObjectiveSolutionSimilarityCalculator() : base() { }
  • stable/HeuristicLab.Optimization.Operators/3.3/SolutionSimilarityCalculator.cs

    r12009 r12280  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2627using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
     
    3334  [StorableClass]
    3435  public abstract class SolutionSimilarityCalculator : Item, ISolutionSimilarityCalculator {
     36    protected abstract bool IsCommutative { get; }
     37
     38    #region Properties
     39    [Storable]
     40    public string SolutionVariableName { get; set; }
     41    [Storable]
     42    public string QualityVariableName { get; set; }
     43    #endregion
     44
    3545    [StorableConstructor]
    3646    protected SolutionSimilarityCalculator(bool deserializing) : base(deserializing) { }
    37     protected SolutionSimilarityCalculator(SolutionSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
     47
     48    protected SolutionSimilarityCalculator(SolutionSimilarityCalculator original, Cloner cloner)
     49      : base(original, cloner) {
     50      this.SolutionVariableName = original.SolutionVariableName;
     51      this.QualityVariableName = original.QualityVariableName;
     52    }
    3853    protected SolutionSimilarityCalculator() : base() { }
    3954
     
    7186      for (int i = 0; i < individuals.Count; i++) similarityMatrix[i] = new double[individuals.Count];
    7287
    73       for (int i = 0; i < individuals.Count; i++) {
    74         for (int j = i; j < individuals.Count; j++) {
    75           similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]);
     88      if (IsCommutative) {
     89        for (int i = 0; i < individuals.Count; i++) {
     90          for (int j = i; j < individuals.Count; j++) {
     91            similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]);
     92          }
     93        }
     94      } else {
     95        for (int i = 0; i < individuals.Count; i++) {
     96          for (int j = i; j < individuals.Count; j++) {
     97            similarityMatrix[i][j] = CalculateSolutionSimilarity(individuals[i], individuals[j]);
     98            if (i == j) continue;
     99            similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[j], individuals[i]);
     100          }
    76101        }
    77102      }
     
    81106
    82107    public abstract double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution);
    83     public abstract bool Equals(IScope x, IScope y);
    84     public abstract int GetHashCode(IScope obj);
     108
     109    public virtual bool Equals(IScope x, IScope y) {
     110      if (ReferenceEquals(x, y)) return true;
     111      if (x == null || y == null) return false;
     112
     113      var q1 = x.Variables[QualityVariableName].Value;
     114      var q2 = y.Variables[QualityVariableName].Value;
     115
     116      return CheckQualityEquality(q1, q2) && CalculateSolutionSimilarity(x, y).IsAlmost(1.0);
     117    }
     118
     119    public virtual int GetHashCode(IScope scope) {
     120      var quality = scope.Variables[QualityVariableName].Value;
     121      var dv = quality as DoubleValue;
     122      if (dv != null)
     123        return dv.Value.GetHashCode();
     124
     125      var da = quality as DoubleArray;
     126      if (da != null) {
     127        int hash = 17;
     128        unchecked {
     129          for (int i = 0; i < da.Length; ++i) {
     130            hash += hash * 23 + da[i].GetHashCode();
     131          }
     132          return hash;
     133        }
     134      }
     135      return 0;
     136    }
     137
     138    private static bool CheckQualityEquality(IItem q1, IItem q2) {
     139      var d1 = q1 as DoubleValue;
     140      var d2 = q2 as DoubleValue;
     141
     142      if (d1 != null && d2 != null)
     143        return d1.Value.IsAlmost(d2.Value);
     144
     145      var da1 = q1 as DoubleArray;
     146      var da2 = q2 as DoubleArray;
     147
     148      if (da1 != null && da2 != null) {
     149        if (da1.Length != da2.Length)
     150          throw new ArgumentException("The quality arrays must have the same length.");
     151
     152        for (int i = 0; i < da1.Length; ++i) {
     153          if (!da1[i].IsAlmost(da2[i]))
     154            return false;
     155        }
     156
     157        return true;
     158      }
     159
     160      throw new ArgumentException("Could not determine quality equality.");
     161    }
    85162  }
    86163}
  • stable/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r12005 r12280  
    148148      <DependentUpon>CreateNewSingleEncodingDialog.cs</DependentUpon>
    149149    </Compile>
    150     <Compile Include="ISingleObjectiveSolutionSimilarityCalculatorView.cs">
    151       <SubType>UserControl</SubType>
    152     </Compile>
    153     <Compile Include="ISingleObjectiveSolutionSimilarityCalculatorView.Designer.cs">
    154       <DependentUpon>ISingleObjectiveSolutionSimilarityCalculatorView.cs</DependentUpon>
     150    <Compile Include="ISolutionSimilarityCalculatorView.cs">
     151      <SubType>UserControl</SubType>
     152    </Compile>
     153    <Compile Include="ISolutionSimilarityCalculatorView.Designer.cs">
     154      <DependentUpon>ISolutionSimilarityCalculatorView.cs</DependentUpon>
    155155    </Compile>
    156156    <Compile Include="ExperimentListView.cs">
     
    159159    <Compile Include="ExperimentListView.Designer.cs">
    160160      <DependentUpon>ExperimentListView.cs</DependentUpon>
    161     </Compile>
    162     <Compile Include="ISimilarityCalculatorView.cs">
    163       <SubType>UserControl</SubType>
    164     </Compile>
    165     <Compile Include="ISimilarityCalculatorView.Designer.cs">
    166       <DependentUpon>ISimilarityCalculatorView.cs</DependentUpon>
    167161    </Compile>
    168162    <Compile Include="MultiEncodingView.cs">
  • stable/HeuristicLab.Optimization/3.3/Interfaces/ISimilarityBasedOperator.cs

    r12009 r12280  
    2424namespace HeuristicLab.Optimization {
    2525  public interface ISimilarityBasedOperator : IOperator {
    26     ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
     26    IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { get; }
    2727  }
    2828}
  • stable/HeuristicLab.Optimization/3.3/Interfaces/ISingleObjectiveSolutionSimilarityCalculator.cs

    r12009 r12280  
    2020#endregion
    2121
     22using System;
     23
    2224namespace HeuristicLab.Optimization {
     25  // use HeuristicLab.Optimization.ISolutionSimilarityCalculator instead
     26  // BackwardsCompatibility3.3
     27  #region Backwards compatible code, remove with 3.4
    2328  /// <summary>
    2429  /// An interface which represents an operator for similarity calculation between single objective solutions.
    2530  /// </summary>
     31  [Obsolete("use HeuristicLab.Optimization.ISolutionSimilarityCalculator instead")]
    2632  public interface ISingleObjectiveSolutionSimilarityCalculator : ISolutionSimilarityCalculator, ISingleObjectiveOperator {
    27     string SolutionVariableName { get; set; }
    28     string QualityVariableName { get; set; }
     33
    2934  }
     35  #endregion
    3036}
  • stable/HeuristicLab.Optimization/3.3/Interfaces/ISolutionSimilarityCalculator.cs

    r12009 r12280  
    2828  /// </summary>
    2929  public interface ISolutionSimilarityCalculator : IItem, IEqualityComparer<IScope> {
     30    string SolutionVariableName { get; set; }
     31    string QualityVariableName { get; set; }
     32
    3033    /// <summary>
    3134    /// Calculates the similarity of two solutions.
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r12009 r12280  
    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
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs

    r11986 r12280  
    3636  public class SymbolicExpressionTreeBottomUpSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    3737    private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" };
     38
     39    protected override bool IsCommutative { get { return true; } }
     40
    3841    public SymbolicExpressionTreeBottomUpSimilarityCalculator() { }
    3942
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.cs

    r12009 r12280  
    3131  [Item("SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")]
    3232  public class SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
     33    protected override bool IsCommutative { get { return true; } }
     34
    3335    [Storable]
    3436    private readonly SymbolicExpressionTreeNodeEqualityComparer comparer;
  • stable/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r12009 r12280  
    2929using HeuristicLab.Encodings.BinaryVectorEncoding;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    8182    private BestKnapsackSolutionAnalyzer BestKnapsackSolutionAnalyzer {
    8283      get { return Operators.OfType<BestKnapsackSolutionAnalyzer>().FirstOrDefault(); }
    83     }
    84     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    85       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }
    8684    }
    8785    #endregion
     
    248246        BestKnapsackSolutionAnalyzer.ValuesParameter.Hidden = true;
    249247      }
    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       }
    257248    }
    258249    private void InitializeOperators() {
     
    261252      Operators.Add(new KnapsackSimultaneousPathRelinker());
    262253      Operators.Add(new KnapsackSimilarityCalculator());
     254      Operators.Add(new QualitySimilarityCalculator());
     255      Operators.Add(new NoSimilarityCalculator());
    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>()) {
     
    317310        op.ParentsParameter.Hidden = true;
    318311      }
    319       foreach (KnapsackSimilarityCalculator op in Operators.OfType<KnapsackSimilarityCalculator>()) {
     312      foreach (ISolutionSimilarityCalculator op in Operators.OfType<ISolutionSimilarityCalculator>()) {
    320313        op.SolutionVariableName = SolutionCreator.BinaryVectorParameter.ActualName;
    321314        op.QualityVariableName = Evaluator.QualityParameter.ActualName;
  • stable/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs

    r12009 r12280  
    3535  [Item("KnapsackSimilarityCalculator", "An operator that performs similarity calculation between two knapsack solutions. The operator calculates the similarity based on the number of elements the two solutions have in common.")]
    3636  public sealed class KnapsackSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
     37    protected override bool IsCommutative { get { return true; } }
     38
    3739    private KnapsackSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3840    private KnapsackSimilarityCalculator(KnapsackSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
  • stable/HeuristicLab.Problems.QuadraticAssignment

  • stable/HeuristicLab.Problems.QuadraticAssignment/3.3/QAPSimilarityCalculator.cs

    r12009 r12280  
    3535  [Item("QAPSimilarityCalculator", "An operator that performs similarity calculation between two quadratic assignment solutions. The operator calculates the similarity based on the number of edges the two solutions have in common.")]
    3636  public sealed class QAPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
     37    protected override bool IsCommutative { get { return true; } }
     38
    3739    private QAPSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3840    private QAPSimilarityCalculator(QAPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
  • stable/HeuristicLab.Problems.TestFunctions

  • stable/HeuristicLab.Problems.TestFunctions/3.3/SimilarityCalculators/SingleObjectiveTestFunctionSimilarityCalculator.cs

    r12009 r12280  
    3838  [StorableClass]
    3939  public sealed class SingleObjectiveTestFunctionSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    40     #region Properties
     40    protected override bool IsCommutative { get { return true; } }
     41
    4142    [Storable]
    4243    public DoubleMatrix Bounds { get; set; }
    43     #endregion
    4444
    4545    [StorableConstructor]
  • stable/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r12009 r12280  
    2929using HeuristicLab.Encodings.RealVectorEncoding;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    7172    private BestSingleObjectiveTestFunctionSolutionAnalyzer BestSingleObjectiveTestFunctionSolutionAnalyzer {
    7273      get { return Operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); }
    73     }
    74     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    75       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }
    7674    }
    7775    #endregion
     
    258256        BestSingleObjectiveTestFunctionSolutionAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name;
    259257      }
    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       }
    267258    }
    268259    private void InitializeOperators() {
     
    270261      Operators.Add(new SingleObjectiveTestFunctionPathRelinker());
    271262      Operators.Add(new SingleObjectiveTestFunctionSimilarityCalculator());
     263      Operators.Add(new QualitySimilarityCalculator());
     264      Operators.Add(new NoSimilarityCalculator());
    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>());
     
    325318      try {
    326319        BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);
    327       } catch (ArgumentException e) {
     320      }
     321      catch (ArgumentException e) {
    328322        ErrorHandling.ShowErrorDialog(e);
    329323        ProblemSize.Value = Evaluator.MinimumProblemSize;
     
    391385        op.ParentsParameter.Hidden = true;
    392386      }
    393       foreach (var op in Operators.OfType<SingleObjectiveTestFunctionSimilarityCalculator>()) {
     387      foreach (var op in Operators.OfType<ISolutionSimilarityCalculator>()) {
    394388        op.SolutionVariableName = SolutionCreator.RealVectorParameter.ActualName;
    395389        op.QualityVariableName = Evaluator.QualityParameter.ActualName;
    396         op.Bounds = Bounds;
     390        var calc = op as SingleObjectiveTestFunctionSimilarityCalculator;
     391        if (calc != null) calc.Bounds = Bounds;
    397392      }
    398393    }
  • stable/HeuristicLab.Problems.TravelingSalesman/3.3/SimilarityCalculators/TSPSimilarityCalculator.cs

    r12009 r12280  
    3535  [Item("TSPSimilarityCalculator", "An operator that performs similarity calculation between two traveling salesman solutions. The operator calculates the similarity based on the number of edges the two solutions have in common.")]
    3636  public sealed class TSPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
     37    protected override bool IsCommutative { get { return true; } }
     38
    3739    private TSPSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3840    private TSPSimilarityCalculator(TSPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
  • stable/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r12009 r12280  
    3030using HeuristicLab.Encodings.PermutationEncoding;
    3131using HeuristicLab.Optimization;
     32using HeuristicLab.Optimization.Operators;
    3233using HeuristicLab.Parameters;
    3334using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    8182    private TSPAlleleFrequencyAnalyzer TSPAlleleFrequencyAnalyzer {
    8283      get { return Operators.OfType<TSPAlleleFrequencyAnalyzer>().FirstOrDefault(); }
    83     }
    84     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    85       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }
    8684    }
    8785    #endregion
     
    236234      Operators.Add(new TSPSimultaneousPathRelinker());
    237235      Operators.Add(new TSPSimilarityCalculator());
     236      Operators.Add(new QualitySimilarityCalculator());
     237      Operators.Add(new NoSimilarityCalculator());
    238238
    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[] {
     
    319319        TSPAlleleFrequencyAnalyzer.ResultsParameter.ActualName = "Results";
    320320      }
    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       }
    328321    }
    329322    private void ParameterizeOperators() {
     
    366359        op.ParentsParameter.Hidden = true;
    367360      }
    368       foreach (TSPSimilarityCalculator op in Operators.OfType<TSPSimilarityCalculator>()) {
     361      foreach (ISolutionSimilarityCalculator op in Operators.OfType<ISolutionSimilarityCalculator>()) {
    369362        op.SolutionVariableName = SolutionCreator.PermutationParameter.ActualName;
    370363        op.QualityVariableName = Evaluator.QualityParameter.ActualName;
  • stable/HeuristicLab.Problems.VehicleRouting

  • stable/HeuristicLab.Problems.VehicleRouting/3.4/SimilarityCalculators/VRPSimilarityCalculator.cs

    r12009 r12280  
    4040  [StorableClass]
    4141  public sealed class VRPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    42     #region Properties
     42    protected override bool IsCommutative { get { return true; } }
     43
    4344    [Storable]
    4445    public IVRPProblemInstance ProblemInstance { get; set; }
    45     #endregion
    4646
    4747    private VRPSimilarityCalculator(bool deserializing) : base(deserializing) { }
  • stable/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r12009 r12280  
    2929using HeuristicLab.Data;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    114115      set { SolutionCreatorParameter.Value = value; }
    115116    }
    116     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    117       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().FirstOrDefault(); }
    118     }
    119117    #endregion
    120118
     
    256254          ApplicationManager.Manager.GetInstances<IGeneralVRPOperator>().Cast<IOperator>()).OrderBy(op => op.Name));
    257255        Operators.Add(new VRPSimilarityCalculator());
    258         Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());
     256        Operators.Add(new QualitySimilarityCalculator());
     257        Operators.Add(new NoSimilarityCalculator());
     258        Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    259259
    260260        IVRPCreator defaultCreator = null;
     
    287287          op.ParentsParameter.Hidden = true;
    288288        }
    289         foreach (VRPSimilarityCalculator op in Operators.OfType<VRPSimilarityCalculator>()) {
     289        foreach (ISolutionSimilarityCalculator op in Operators.OfType<ISolutionSimilarityCalculator>()) {
    290290          op.SolutionVariableName = SolutionCreator.VRPToursParameter.ActualName;
    291291          op.QualityVariableName = ProblemInstance.SolutionEvaluator.QualityParameter.ActualName;
    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();
     292          var calc = op as VRPSimilarityCalculator;
     293          if (calc != null) calc.ProblemInstance = ProblemInstance;
    299294        }
    300295      }
Note: See TracChangeset for help on using the changeset viewer.