Changeset 12069 for trunk/sources/HeuristicLab.Algorithms.ScatterSearch
- Timestamp:
- 02/25/15 10:07:54 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs
r12012 r12069 36 36 [Item("ReferenceSetUpdateMethod", "An operator that updates the reference set.")] 37 37 [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 { 44 39 #region Parameter properties 45 40 public ScopeParameter CurrentScopeParameter { … … 48 43 public IValueLookupParameter<IntValue> ReferenceSetSizeParameter { 49 44 get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; } 45 } 46 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 47 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 50 48 } 51 49 #endregion … … 62 60 [StorableConstructor] 63 61 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) { } 68 63 public ReferenceSetUpdateMethod() 69 64 : base() { … … 71 66 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the population and the reference set.")); 72 67 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.")); 73 69 #endregion 74 70 } … … 78 74 } 79 75 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 80 85 public override IOperation Apply() { 81 86 var populationSimilarity = new Dictionary<IScope, double>(); 82 87 var populationScope = CurrentScope.SubScopes[0]; 83 88 var refSetScope = CurrentScope.SubScopes[1]; 84 var similarityMatrix = SimilarityCalculator .CalculateSolutionCrowdSimilarity(populationScope, refSetScope);89 var similarityMatrix = SimilarityCalculatorParameter.ActualValue.CalculateSolutionCrowdSimilarity(populationScope, refSetScope); 85 90 for (int i = 0; i < populationScope.SubScopes.Count; i++) { 86 91 populationSimilarity[populationScope.SubScopes[i]] = similarityMatrix[i].Sum(); -
trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs
r12012 r12069 423 423 MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 424 424 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;427 425 } 428 426 } -
trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs
r12012 r12069 36 36 [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")] 37 37 [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 { 44 39 #region Parameter properties 45 40 public ScopeParameter CurrentScopeParameter { … … 57 52 public IValueLookupParameter<IntValue> ReferenceSetSizeParameter { 58 53 get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; } 54 } 55 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 56 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 59 57 } 60 58 #endregion … … 82 80 [StorableConstructor] 83 81 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() { 95 85 #region Create parameters 96 86 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that is the reference set.")); … … 99 89 Parameters.Add(new ValueLookupParameter<IItem>("Quality", "This parameter is used for name translation only.")); 100 90 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.")); 101 105 #endregion 102 106 } … … 132 136 if (orderedOffspring.Any(hasBetterQuality)) { 133 137 // produce the set union 134 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), SimilarityCalculator );138 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), SimilarityCalculatorParameter.ActualValue); 135 139 if (union.Count() > orderedParents.Count()) { 136 140 var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
Note: See TracChangeset
for help on using the changeset viewer.