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.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

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

    r12031 r12105  
    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        var oldParameter = (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"];
     166        Parameters.Remove(oldParameter);
     167        var newParameter = new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.", new ItemSet<ISolutionSimilarityCalculator>(oldParameter.ValidValues));
     168        var selectedSimilarityCalculator = newParameter.ValidValues.SingleOrDefault(x => x.GetType() == oldParameter.Value.GetType());
     169        newParameter.Value = selectedSimilarityCalculator;
     170        Parameters.Add(newParameter);
     171      }
     172      #endregion
    162173      Initialize();
    163174    }
     
    184195      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    185196      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."));
     197      Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    187198      #endregion
    188199
     
    390401    }
    391402    private void UpdateSimilarityCalculators() {
    392       ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     403      ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
    393404      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>())
     405      ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
     406
     407      foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
    400408        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
    401409
    402410      if (oldSimilarityCalculator != null) {
    403         ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     411        ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
    404412        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
    405413        else oldSimilarityCalculator = null;
     
    423431        MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    424432        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;
    427433      }
    428434    }
     
    449455    }
    450456    private void ParameterizeSimilarityCalculators() {
    451       foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
     457      foreach (ISolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
    452458        calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
    453459      }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r12031 r12105  
    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) :
Note: See TracChangeset for help on using the changeset viewer.