Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12079


Ignore:
Timestamp:
02/25/15 23:08:19 (10 years ago)
Author:
ascheibe
Message:

#2267 adapted branch to changes from #2332

Location:
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Comparators/PopulationDiversityComparator.cs

    r11845 r12079  
    3636  [Item("PopulationDiversityComparator", "Structural comparison of child to population.")]
    3737  [StorableClass]
    38   public class PopulationDiversityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator, ISimilarityBasedOperator {
     38  public class PopulationDiversityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator {
    3939    [Storable]
    4040    public ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
     41    public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     42      get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     43    }
    4144    public IValueLookupParameter<BoolValue> MaximizationParameter {
    4245      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    126129      Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations."));
    127130      Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(true)));
     131      Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity."));
    128132
    129133      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
     
    136140    public override IDeepCloneable Clone(Cloner cloner) {
    137141      return new PopulationDiversityComparator(this, cloner);
     142    }
     143
     144    [StorableHook(HookType.AfterDeserialization)]
     145    private void AfterDeserialization() {
     146      // BackwardsCompatibility3.3
     147      #region Backwards compatible code, remove with 3.4
     148      if (!Parameters.ContainsKey("SimilarityCalculator"))
     149        Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity."));
     150      #endregion
    138151    }
    139152
     
    207220        Scope fakeScope = new Scope();
    208221        fakeScope.SubScopes.Add((IScope)ExecutionContext.Scope.Clone());
    209         var similarities = SimilarityCalculator.CalculateSolutionCrowdSimilarity(fakeScope, remainingScope);
     222        var similarities = SimilarityCalculatorParameter.ActualValue.CalculateSolutionCrowdSimilarity(fakeScope, remainingScope);
    210223        double averageSimilarity = similarities[0].Average();
    211224        resultDiversity = averageSimilarity < diversityComFact;
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Comparators/PopulationQualityComparator.cs

    r11845 r12079  
    2020#endregion
    2121
    22 using System;
    2322using System.Linq;
    2423using HeuristicLab.Analysis;
     
    3635  [Item("PopulationQualityComparator", "Compares the quality of the child to the population.")]
    3736  [StorableClass]
    38   public class PopulationQualityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator, ISimilarityBasedOperator {
     37  public class PopulationQualityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator {
    3938    [Storable]
    4039    public ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
     40    public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     41      get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     42    }
    4143    public IValueLookupParameter<BoolValue> MaximizationParameter {
    4244      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    126128      Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations."));
    127129      Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(false)));
     130      Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity."));
    128131
    129132      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
     
    136139    public override IDeepCloneable Clone(Cloner cloner) {
    137140      return new PopulationQualityComparator(this, cloner);
     141    }
     142
     143    [StorableHook(HookType.AfterDeserialization)]
     144    private void AfterDeserialization() {
     145      // BackwardsCompatibility3.3
     146      #region Backwards compatible code, remove with 3.4
     147      if (!Parameters.ContainsKey("SimilarityCalculator"))
     148        Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity."));
     149      #endregion
    138150    }
    139151
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Comparators/UnwantedMutationsComparator.cs

    r11884 r12079  
    3737  [Item("UnwantedMutationsComparator", "Compares the similarity against that of its parents (assumes the parents are subscopes to the child scope). This operator works with any number of subscopes > 0.")]
    3838  [StorableClass]
    39   public class UnwantedMutationsComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator, ISimilarityBasedOperator {
     39  public class UnwantedMutationsComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator {
    4040    [Storable]
    4141    public ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
     42    public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     43      get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     44    }
    4245    public IValueLookupParameter<BoolValue> MaximizationParameter {
    4346      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    135138      Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(true)));
    136139      Parameters.Add(new ValueParameter<BoolValue>("EnableQualityCriteria", "Use quality as additional offspring selection criteria.", new BoolValue(false)));
     140      Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity."));
    137141
    138142      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
     
    145149    public override IDeepCloneable Clone(Cloner cloner) {
    146150      return new UnwantedMutationsComparator(this, cloner);
     151    }
     152
     153    [StorableHook(HookType.AfterDeserialization)]
     154    private void AfterDeserialization() {
     155      // BackwardsCompatibility3.3
     156      #region Backwards compatible code, remove with 3.4
     157      if (!Parameters.ContainsKey("SimilarityCalculator"))
     158        Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity."));
     159      #endregion
    147160    }
    148161
     
    203216      }
    204217
    205       string solutionVariableName = ((ISingleObjectiveSolutionSimilarityCalculator)SimilarityCalculator).SolutionVariableName;
     218      string solutionVariableName = ((ISingleObjectiveSolutionSimilarityCalculator)SimilarityCalculatorParameter.ActualValue).SolutionVariableName;
    206219      double resultVal = AnalyzeUnwantedMutations(ExecutionContext.Scope.SubScopes[0],
    207220        ExecutionContext.Scope.SubScopes[1], ExecutionContext.Scope, solutionVariableName);
     
    237250      if (EnableDivCriteriaParameter.Value.Value && !EnableQualityCriteriaParameter.Value.Value) {
    238251        result = resultDiversity;
    239       }                         
     252      }
    240253      //use diveristiy criteria or not
    241254      if (EnableDivCriteriaParameter.Value.Value && EnableQualityCriteriaParameter.Value.Value) {
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Comparators/WeightedParentsDiversityComparator.cs

    r11844 r12079  
    3636  [Item("WeightedParentsDiversityComparator", "Compares the similarity against that of its parents (assumes the parents are subscopes to the child scope). This operator works with any number of subscopes > 0.")]
    3737  [StorableClass]
    38   public class WeightedParentsDiversityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator, ISimilarityBasedOperator {
     38  public class WeightedParentsDiversityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator {
    3939    [Storable]
    4040    public ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
     41    public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     42      get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     43    }
    4144    public IValueLookupParameter<BoolValue> MaximizationParameter {
    4245      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    126129      Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations."));
    127130      Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(true)));
     131      Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity."));
    128132
    129133      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
     
    146150      if (!Parameters.ContainsKey("EnableDivCriteria"))
    147151        Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(true)));
     152      // BackwardsCompatibility3.3
     153      #region Backwards compatible code, remove with 3.4
     154      if (!Parameters.ContainsKey("SimilarityCalculator"))
     155        Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity."));
     156      #endregion
    148157    }
    149158
     
    202211      #region Calculate threshold
    203212      if (rightQualities.Length == 2) {
    204         var sim1 = SimilarityCalculator.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes[0]);
    205         var sim2 = SimilarityCalculator.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes[1]);
     213        var sim1 = SimilarityCalculatorParameter.ActualValue.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes[0]);
     214        var sim2 = SimilarityCalculatorParameter.ActualValue.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes[1]);
    206215        var simAvg = (sim1 + sim2) / 2.0;
    207216
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/VOffspringSelectionGeneticAlgorithm.cs

    r11516 r12079  
    444444        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    445445      }
    446       SimilarityCalculatorParameter.ValueChanged += SimilarityCalculatorParameter_ValueChanged;
    447     }
    448     void SimilarityCalculatorParameter_ValueChanged(object sender, EventArgs e) {
    449       foreach (ISimilarityBasedOperator op in SubScopesQualityComparatorParameter.ValidValues.OfType<ISimilarityBasedOperator>())
    450         op.SimilarityCalculator = SimilarityCalculator;
    451446    }
    452447    private void ParameterizeSolutionsCreator() {
Note: See TracChangeset for help on using the changeset viewer.