Changeset 17625
- Timestamp:
- 06/23/20 04:23:45 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Interfaces/IParticleCreator.cs
r17226 r17625 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Core; 23 using HEAL.Attic;24 24 25 25 namespace HeuristicLab.Optimization { … … 28 28 /// Interface to represent an operator that generates a particle. 29 29 /// </summary> 30 public interface IParticleCreator : I SolutionCreator {30 public interface IParticleCreator : IOperator { 31 31 ILookupParameter<ISolutionCreator> SolutionCreatorParameter { get; } 32 32 } -
branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/OptionalConstrainedValueParameter.cs
r17614 r17625 55 55 set { 56 56 if (ReadOnly) throw new InvalidOperationException("Cannot set the value of a readonly parameter."); 57 DoSetValue(value); 58 } 59 } 60 public virtual void ForceValue(T value) { 61 DoSetValue(value); 62 } 63 private void DoSetValue(T value) { 64 if (value != this.value) { 65 if ((value != null) && !validValues.Contains(value)) throw new ArgumentException("Invalid value."); 66 DeregisterValueEvents(); 67 this.value = value; 68 RegisterValueEvents(); 69 OnValueChanged(); 70 } 71 } 57 if (value != this.value) { 58 if ((value != null) && !validValues.Contains(value)) throw new ArgumentException("Invalid value."); 59 DeregisterValueEvents(); 60 this.value = value; 61 RegisterValueEvents(); 62 OnValueChanged(); 63 } 64 } 65 } 66 72 67 IItem IValueParameter.Value { 73 68 get { return Value; } … … 170 165 #endregion 171 166 172 public v oid Populate(IEnumerable<IItem> items) {167 public virtual void Populate(IEnumerable<IItem> items) { 173 168 ValidValues.Clear(); 174 169 ValidValues.UnionWith(items.OfType<T>()); … … 187 182 if (item != null) Value = item; 188 183 } 184 } 185 186 public virtual IItem SetValueToFirstOf(Type itemType) { 187 var item = ValidValues.Where(i => itemType.IsAssignableFrom(i.GetType())).FirstOrDefault(); 188 if (item != null) Value = item; 189 return item; 189 190 } 190 191 -
branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/ScopeTreeLookupParameter.cs
r17257 r17625 133 133 j++; 134 134 } 135 CachedActualValue = values; 135 136 } 136 137 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r17614 r17625 25 25 using System.Threading; 26 26 using HEAL.Attic; 27 using HeuristicLab.Analysis;28 27 using HeuristicLab.Common; 29 28 using HeuristicLab.Core; … … 71 70 BestKnownQuality = TestFunction.BestKnownQuality; 72 71 Bounds = (DoubleMatrix)TestFunction.Bounds.Clone(); 73 Dimension = TestFunction.MinimumProblemSize;72 Dimension = Math.Min(Math.Max(2, TestFunction.MinimumProblemSize), TestFunction.MaximumProblemSize); 74 73 BestKnownSolutionParameter.Value = TestFunction.GetBestKnownSolution(Dimension); 75 InitializeOperators(); 74 75 76 Operators.AddRange(new IItem[] { 77 new SingleObjectiveTestFunctionImprovementOperator(), 78 new SingleObjectiveTestFunctionPathRelinker(), 79 new SingleObjectiveTestFunctionSimilarityCalculator(), 80 new EuclideanSimilarityCalculator(), 81 new AdditiveMoveEvaluator() }); 82 83 SolutionCreatorParameter.SetValueToFirstOf(typeof(UniformRandomRealVectorCreator)); 84 85 Parameterize(); 76 86 RegisterEventHandlers(); 77 87 } … … 87 97 88 98 private void RegisterEventHandlers() { 89 Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;90 99 TestFunctionParameter.ValueChanged += TestFunctionParameterOnValueChanged; 91 100 } … … 109 118 110 119 SingleObjectiveTestFunctionSolution solution = null; 111 if (results.TryGetValue("Best Solution", out var res) ) {120 if (results.TryGetValue("Best Solution", out var res) && res.Value != null) { 112 121 solution = (SingleObjectiveTestFunctionSolution)res.Value; 113 122 if (IsBetter(best.Item2, solution.BestQuality.Value)) { … … 122 131 Bounds = BoundsRefParameter.Value 123 132 }; 124 results.Add (new Result("Best Solution", solution));133 results.AddOrUpdateResult("Best Solution", solution); 125 134 } 126 135 if (best.Item1.Length == 2) solution.Population = new ItemArray<RealVector>(realVectors.Select(x => (RealVector)x.Clone())); … … 129 138 130 139 #region Events 131 protected override void OnEncodingChanged() { 132 base.OnEncodingChanged(); 133 Parameterize(); 134 } 135 protected override void OnEvaluatorChanged() { 136 base.OnEvaluatorChanged(); 137 Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged; 140 protected override void ParameterizeOperators() { 141 base.ParameterizeOperators(); 138 142 Parameterize(); 139 143 } … … 145 149 protected override void BoundsOnChanged() { 146 150 base.BoundsOnChanged(); 147 Parameterize();148 }149 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {150 151 Parameterize(); 151 152 } … … 167 168 168 169 #region Helpers 169 private void InitializeOperators() {170 Operators.Add(new SingleObjectiveTestFunctionImprovementOperator());171 Operators.Add(new SingleObjectiveTestFunctionPathRelinker());172 Operators.Add(new SingleObjectiveTestFunctionSimilarityCalculator());173 Operators.Add(new EuclideanSimilarityCalculator());174 Operators.Add(new AdditiveMoveEvaluator());175 176 Parameterize();177 }178 179 170 private void Parameterize() { 180 171 var operators = new List<IItem>(); 181 172 182 //TODO correct wiring code, because most of the parameters are wired in the encoding183 foreach (var op in Operators.OfType<PopulationSimilarityAnalyzer>()) {184 var calcs = Operators.OfType<ISolutionSimilarityCalculator>().ToArray();185 op.SimilarityCalculatorParameter.ValidValues.Clear();186 foreach (var c in calcs) {187 // TODO: unified encoding parameters188 c.SolutionVariableName = Encoding.Name;189 c.QualityVariableName = Evaluator.QualityParameter.ActualName;190 op.SimilarityCalculatorParameter.ValidValues.Add(c);191 }192 }193 foreach (var op in Operators.OfType<ISingleObjectiveTestFunctionAdditiveMoveEvaluator>()) {194 operators.Add(op);195 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;196 op.QualityParameter.Hidden = true;197 foreach (var movOp in Encoding.Operators.OfType<IRealVectorAdditiveMoveQualityOperator>())198 movOp.MoveQualityParameter.ActualName = op.MoveQualityParameter.ActualName;199 }200 foreach (var op in Operators.OfType<IRealVectorParticleCreator>()) {201 // TODO: unified encoding parameters202 op.RealVectorParameter.ActualName = Encoding.Name;203 op.RealVectorParameter.Hidden = true;204 op.BoundsParameter.ActualName = BoundsRefParameter.Name;205 op.BoundsParameter.Hidden = true;206 }207 foreach (var op in Operators.OfType<IRealVectorParticleUpdater>()) {208 // TODO: unified encoding parameters209 op.RealVectorParameter.ActualName = Encoding.Name;210 op.RealVectorParameter.Hidden = true;211 op.BoundsParameter.ActualName = BoundsRefParameter.Name;212 op.BoundsParameter.Hidden = true;213 }214 foreach (var op in Operators.OfType<IRealVectorSwarmUpdater>()) {215 op.MaximizationParameter.ActualName = MaximizationParameter.Name;216 op.MaximizationParameter.Hidden = true;217 }218 foreach (var op in Operators.OfType<ISingleObjectiveImprovementOperator>()) {219 operators.Add(op);220 op.SolutionParameter.ActualName = Encoding.Name;221 op.SolutionParameter.Hidden = true;222 }223 173 foreach (var op in Operators.OfType<ITestFunctionSolutionSimilarityCalculator>()) { 224 174 operators.Add(op); 225 op.SolutionVariableName = Encoding.Name;226 op.QualityVariableName = Evaluator.QualityParameter.ActualName;227 175 op.Bounds = Bounds; 228 176 }
Note: See TracChangeset
for help on using the changeset viewer.