Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/03/15 11:18:07 (10 years ago)
Author:
bburlacu
Message:

#2276: Merged trunk changes.

Location:
branches/HeuristicLab.DatasetRefactor/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatasetRefactor/sources

  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.RAPGA/3.3/DuplicatesSelector.cs

    r12031 r12105  
    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
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.RAPGA/3.3/ProgressiveOffspringPreserver.cs

    r12031 r12105  
    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();
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs

    r12031 r12105  
    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        var oldParameter = (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"];
     209        Parameters.Remove(oldParameter);
     210        var newParameter = new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.", new ItemSet<ISolutionSimilarityCalculator>(oldParameter.ValidValues));
     211        var selectedSimilarityCalculator = newParameter.ValidValues.SingleOrDefault(x => x.GetType() == oldParameter.Value.GetType());
     212        newParameter.Value = selectedSimilarityCalculator;
     213        Parameters.Add(newParameter);
    206214      }
    207215      #endregion
     
    234242      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    235243      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."));
     244      Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    237245
    238246      RandomCreator randomCreator = new RandomCreator();
     
    394402      RAPGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    395403      RAPGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    396       foreach (ISimilarityBasedOperator op in RAPGAMainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
    397         op.SimilarityCalculator = SimilarityCalculator;
    398404    }
    399405    private void ParameterizeStochasticOperator(IOperator op) {
     
    450456    }
    451457    private void ParameterizeSimilarityCalculators() {
    452       foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
     458      foreach (ISolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
    453459        calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
    454460      }
     
    495501    }
    496502    private void UpdateSimilarityCalculators() {
    497       ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     503      ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
    498504      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>())
     505      ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
     506
     507      foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
    505508        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
    506509
    507510      if (oldSimilarityCalculator != null) {
    508         ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     511        ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
    509512        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
    510513        else oldSimilarityCalculator = null;
Note: See TracChangeset for help on using the changeset viewer.