- Timestamp:
- 03/03/15 11:18:07 (10 years ago)
- Location:
- branches/HeuristicLab.DatasetRefactor/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DatasetRefactor/sources
- Property svn:mergeinfo changed
/trunk/sources merged: 12037,12041,12057,12059-12060,12067,12069-12070,12072,12074,12076-12078,12085,12087-12091,12093,12095-12096,12100-12104
- Property svn:mergeinfo changed
-
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.RAPGA/3.3/DuplicatesSelector.cs
r12031 r12105 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Optimization; 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 using HeuristicLab.Selection; … … 37 38 [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.")] 38 39 [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 } 44 44 45 45 [StorableConstructor] 46 46 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.")); 50 51 } 51 public DuplicatesSelector() : base() { }52 52 53 53 public override IDeepCloneable Clone(Cloner cloner) { 54 54 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 55 64 } 56 65 … … 61 70 for (int i = 0; i < scopes.Count; i++) 62 71 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]); 64 73 65 74 -
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.RAPGA/3.3/ProgressiveOffspringPreserver.cs
r12031 r12105 38 38 [Item("ProgressiveOffspringPreserver", "An operator that progressively selects offspring by adding it to a scope list. The operator also performs duplication control.")] 39 39 [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 { 46 41 #region Parameter Properties 47 42 public ScopeParameter CurrentScopeParameter { … … 56 51 public ILookupParameter<IntValue> MaximumPopulationSizeParameter { 57 52 get { return (ILookupParameter<IntValue>)Parameters["MaximumPopulationSize"]; } 53 } 54 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 55 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 58 56 } 59 57 #endregion … … 76 74 [StorableConstructor] 77 75 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) { } 82 77 public ProgressiveOffspringPreserver() 83 78 : base() { 79 #region Create parameters 84 80 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the offspring.")); 85 81 Parameters.Add(new LookupParameter<ScopeList>("OffspringList", "The list that contains the offspring.")); 86 82 Parameters.Add(new LookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); 87 83 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 88 86 } 89 87 90 88 public override IDeepCloneable Clone(Cloner cloner) { 91 89 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 92 99 } 93 100 … … 98 105 var storedOffspringScope = new Scope(); 99 106 storedOffspringScope.SubScopes.AddRange(OffspringList); 100 var similarityMatrix = SimilarityCalculator .CalculateSolutionCrowdSimilarity(CurrentScope, storedOffspringScope);107 var similarityMatrix = SimilarityCalculatorParameter.ActualValue.CalculateSolutionCrowdSimilarity(CurrentScope, storedOffspringScope); 101 108 102 109 var createdOffspring = CurrentScope.SubScopes.ToArray(); -
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs
r12031 r12105 103 103 get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; } 104 104 } 105 public IConstrainedValueParameter<IS ingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {106 get { return (IConstrainedValueParameter<IS ingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }105 public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 106 get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 107 107 } 108 108 #endregion … … 173 173 set { MaximumGenerationsParameter.Value = value; } 174 174 } 175 public IS ingleObjectiveSolutionSimilarityCalculator SimilarityCalculator {175 public ISolutionSimilarityCalculator SimilarityCalculator { 176 176 get { return SimilarityCalculatorParameter.Value; } 177 177 set { SimilarityCalculatorParameter.Value = value; } … … 204 204 if (!Parameters.ContainsKey("ReevaluateElites")) { 205 205 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); 206 214 } 207 215 #endregion … … 234 242 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 235 243 Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000))); 236 Parameters.Add(new ConstrainedValueParameter<IS ingleObjectiveSolutionSimilarityCalculator>("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.")); 237 245 238 246 RandomCreator randomCreator = new RandomCreator(); … … 394 402 RAPGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 395 403 RAPGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 396 foreach (ISimilarityBasedOperator op in RAPGAMainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())397 op.SimilarityCalculator = SimilarityCalculator;398 404 } 399 405 private void ParameterizeStochasticOperator(IOperator op) { … … 450 456 } 451 457 private void ParameterizeSimilarityCalculators() { 452 foreach (IS ingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {458 foreach (ISolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) { 453 459 calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName; 454 460 } … … 495 501 } 496 502 private void UpdateSimilarityCalculators() { 497 IS ingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;503 ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value; 498 504 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>()) 505 508 SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator); 506 509 507 510 if (oldSimilarityCalculator != null) { 508 IS ingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());511 ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType()); 509 512 if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator; 510 513 else oldSimilarityCalculator = null;
Note: See TracChangeset
for help on using the changeset viewer.