Changeset 16949
- Timestamp:
- 05/13/19 16:20:11 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj
r16723 r16949 115 115 <ItemGroup> 116 116 <Compile Include="Creators\NormalDistributedRealVectorCreator.cs" /> 117 <Compile Include="RealVectorMultiObjectiveProblem.cs" /> 118 <Compile Include="RealVectorProblem.cs" /> 117 119 <Compile Include="Interfaces\IRealVectorAdditiveMoveQualityOperator.cs" /> 118 120 <Compile Include="Interfaces\IRealVectorBoundedOperator.cs" /> … … 205 207 </ItemGroup> 206 208 <ItemGroup> 209 <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj"> 210 <Project>{887425b4-4348-49ed-a457-b7d2c26ddbf9}</Project> 211 <Name>HeuristicLab.Analysis-3.3</Name> 212 <Private>False</Private> 213 </ProjectReference> 207 214 <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> 208 215 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs
r16813 r16949 46 46 } 47 47 48 protected SymbolicExpressionTreeProblem(SymbolicExpressionTreeEncoding encoding) : base(encoding) { } 48 protected SymbolicExpressionTreeProblem(SymbolicExpressionTreeEncoding encoding) 49 : base(encoding) { 50 EncodingParameter.ReadOnly = true; 51 } 49 52 50 53 public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results, -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs
r16807 r16949 35 35 [Creatable(CreatableAttribute.Categories.Problems, Priority = 95)] 36 36 [Item("Test Function (multi-objective)", "Test functions with real valued inputs and multiple objectives.")] 37 public class MultiObjectiveTestFunctionProblem : MultiObjectiveProblem<RealVectorEncoding, RealVector>, IProblemInstanceConsumer<MOTFData> { 37 public class MultiObjectiveTestFunctionProblem : RealVectorMultiObjectiveProblem, 38 IProblemInstanceConsumer<MOTFData> { 38 39 39 40 #region Parameter Properties -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs
r16749 r16949 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 24 using HEAL.Attic; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 28 30 using HeuristicLab.Optimization; 29 31 using HeuristicLab.Parameters; 30 using H EAL.Attic;32 using HeuristicLab.PluginInfrastructure; 31 33 32 34 namespace HeuristicLab.Problems.TestFunctions { 35 // BackwardsCompatibility3.3 36 #region Backwards compatible code, remove with 3.4 33 37 /// <summary> 34 38 /// An operator for analyzing the best solution for a SingleObjectiveTestFunction problem. … … 36 40 [Item("BestSingleObjectiveTestFunctionSolutionAnalyzer", "An operator for analyzing the best solution for a SingleObjectiveTestFunction problem.")] 37 41 [StorableType("A0F04F9F-DD27-44D8-A1F6-B289F1F40DE2")] 42 [NonDiscoverableType] 43 [Obsolete("Use the Analyze method of the test function problem class")] 38 44 public class BestSingleObjectiveTestFunctionSolutionAnalyzer : SingleSuccessorOperator, IBestSingleObjectiveTestFunctionSolutionAnalyzer { 39 45 public virtual bool EnabledByDefault { … … 145 151 } 146 152 } 153 #endregion 147 154 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r16723 r16949 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Analysis; 26 27 using HeuristicLab.Common; … … 29 30 using HeuristicLab.Encodings.RealVectorEncoding; 30 31 using HeuristicLab.Optimization; 31 using HeuristicLab.Optimization.Operators;32 32 using HeuristicLab.Parameters; 33 using HEAL.Attic;34 33 using HeuristicLab.Problems.Instances; 35 34 … … 38 37 [StorableType("F0AB7236-2C9B-49DC-9D4F-A3558FD9E992")] 39 38 [Creatable(CreatableAttribute.Categories.Problems, Priority = 90)] 40 public sealed class SingleObjectiveTestFunctionProblem : 41 SingleObjectiveProblem<RealVectorEncoding, RealVector>, 39 public sealed class SingleObjectiveTestFunctionProblem : RealVectorProblem, 42 40 IProblemInstanceConsumer<SOTFData> { 43 41 … … 73 71 get { return TestFunctionParameter.Value; } 74 72 set { TestFunctionParameter.Value = value; } 75 }76 77 private BestSingleObjectiveTestFunctionSolutionAnalyzer BestSingleObjectiveTestFunctionSolutionAnalyzer {78 get { return Operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); }79 73 } 80 74 #endregion … … 121 115 } 122 116 117 public override void Analyze(RealVector[] realVectors, double[] qualities, ResultCollection results, IRandom random) { 118 119 bool max = Maximization; 120 DoubleValue bestKnownQuality = BestKnownQualityParameter.Value; 121 SingleObjectiveTestFunctionSolution solution = null; 122 if (results.TryGetValue("Best Solution", out var res)) { 123 solution = (SingleObjectiveTestFunctionSolution)res.Value; 124 } 125 126 int i = -1; 127 if (!max) i = qualities.Select((x, index) => new { index, quality = x }).OrderBy(x => x.quality).First().index; 128 else i = qualities.Select((x, index) => new { index, quality = x }).OrderByDescending(x => x.quality).First().index; 129 130 if (bestKnownQuality == null || 131 max && qualities[i] > bestKnownQuality.Value 132 || !max && qualities[i] < bestKnownQuality.Value) { 133 BestKnownQualityParameter.Value = new DoubleValue(qualities[i]); 134 BestKnownSolutionParameter.Value = (RealVector)realVectors[i].Clone(); 135 if (solution != null) 136 solution.BestKnownRealVector = BestKnownSolutionParameter.Value; 137 } 138 139 if (solution == null) { 140 solution = new SingleObjectiveTestFunctionSolution((RealVector)realVectors[i].Clone(), 141 new DoubleValue(qualities[i]), 142 TestFunctionParameter.Value); 143 solution.Population = realVectors[i].Length == 2 144 ? new ItemArray<RealVector>(realVectors.Select(x => x.Clone()).Cast<RealVector>()) 145 : null; 146 solution.BestKnownRealVector = BestKnownSolutionParameter.Value; 147 solution.Bounds = BoundsParameter.Value; 148 results.Add(new Result("Best Solution", solution)); 149 } else { 150 if (max && qualities[i] > solution.BestQuality.Value 151 || !max && qualities[i] < solution.BestQuality.Value) { 152 solution.BestRealVector = (RealVector)realVectors[i].Clone(); 153 solution.BestQuality = new DoubleValue(qualities[i]); 154 } 155 solution.Population = realVectors[i].Length == 2 156 ? new ItemArray<RealVector>(realVectors.Select(x => x.Clone()).Cast<RealVector>()) 157 : null; 158 } 159 } 160 123 161 #region Events 124 162 protected override void OnEncodingChanged() { … … 162 200 Operators.Add(new SingleObjectiveTestFunctionPathRelinker()); 163 201 Operators.Add(new SingleObjectiveTestFunctionSimilarityCalculator()); 164 Operators.Add(new HammingSimilarityCalculator());165 202 Operators.Add(new EuclideanSimilarityCalculator()); 166 Operators.Add(new QualitySimilarityCalculator());167 203 Operators.Add(new AdditiveMoveEvaluator()); 168 204 169 Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer());170 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));171 205 Parameterize(); 172 206 } … … 174 208 private void Parameterize() { 175 209 var operators = new List<IItem>(); 176 if (BestSingleObjectiveTestFunctionSolutionAnalyzer != null) { 177 operators.Add(BestSingleObjectiveTestFunctionSolutionAnalyzer); 178 BestSingleObjectiveTestFunctionSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 179 BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 180 BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 181 BestSingleObjectiveTestFunctionSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 182 BestSingleObjectiveTestFunctionSolutionAnalyzer.TestFunctionParameter.ActualName = TestFunctionParameter.Name; 210 foreach (var op in Operators.OfType<PopulationSimilarityAnalyzer>()) { 211 var calcs = Operators.OfType<ISolutionSimilarityCalculator>().ToArray(); 212 op.SimilarityCalculatorParameter.ValidValues.Clear(); 213 foreach (var c in calcs) { 214 // TODO: unified encoding parameters 215 c.SolutionVariableName = ((IRealVectorSolutionOperator)Encoding.SolutionCreator).RealVectorParameter.ActualName; 216 c.QualityVariableName = Evaluator.QualityParameter.ActualName; 217 op.SimilarityCalculatorParameter.ValidValues.Add(c); 218 } 183 219 } 184 220 foreach (var op in Operators.OfType<ISingleObjectiveTestFunctionAdditiveMoveEvaluator>()) {
Note: See TracChangeset
for help on using the changeset viewer.