Changeset 17612
- Timestamp:
- 06/19/20 16:38:33 (3 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r17594 r17612 45 45 public class HillClimber : BasicAlgorithm { 46 46 [Storable] 47 private IRandom random;47 private readonly IRandom random; 48 48 49 49 [Storable] public IFixedValueParameter<IntValue> MaximumIterationsParameter { get; private set; } … … 65 65 get { return MaximumIterationsParameter.Value.Value; } 66 66 set { MaximumIterationsParameter.Value.Value = value; } 67 } 68 69 private int Iterations { 70 get => IterationsResult.Value.Value; 71 set => IterationsResult.Value.Value = value; 72 } 73 74 private double BestQuality { 75 get => BestQualityResult.Value.Value; 76 set => BestQualityResult.Value.Value = value; 67 77 } 68 78 … … 88 98 } 89 99 100 protected override void Initialize(CancellationToken cancellationToken) { 101 base.Initialize(cancellationToken); 102 103 IterationsResult.Value = new IntValue(); 104 BestQualityResult.Value = new DoubleValue(double.NaN); 105 } 106 90 107 91 108 92 109 protected override void Run(CancellationToken cancellationToken) { 93 IterationsResult.Value = new IntValue();94 BestQualityResult.Value = new DoubleValue(double.NaN);95 96 110 while (IterationsResult.Value.Value < MaximumIterations) { 97 111 cancellationToken.ThrowIfCancellationRequested(); … … 106 120 107 121 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 108 var bestSoFar = BestQuality Result.Value.Value;122 var bestSoFar = BestQuality; 109 123 if (double.IsNaN(bestSoFar) || Problem.IsBetter(fitness, bestSoFar)) { 110 BestQuality Result.Value.Value= fitness;124 BestQuality = fitness; 111 125 } 112 126 113 Iterations Result.Value.Value++;127 Iterations++; 114 128 } 115 129 } -
branches/2521_ProblemRefactoring/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBProblem.cs
r17334 r17612 72 72 } 73 73 74 public ResultCollection Results { get => Problem.Results; } 75 74 76 [Storable] 75 private ItemList<OKBSolution> solutions; 77 private ItemList<OKBSolution> solutions; 76 78 public ItemList<OKBSolution> Solutions { 77 79 get { return solutions; } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorMultiObjectiveProblem.cs
r17594 r17612 33 33 public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> { 34 34 [Storable] protected IResultParameter<ParetoFrontScatterPlot<BinaryVector>> BestResultParameter { get; private set; } 35 //public IResultDefinition<ParetoFrontScatterPlot<BinaryVector>> BestResult { get { return BestResultParameter; }}36 35 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 37 36 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs
r17594 r17612 33 33 [StorableType("2F6FEB34-BD19-47AF-9484-7F48565C0C43")] 34 34 public abstract class BinaryVectorProblem : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> { 35 [Storable] protected IResultParameter<ISingleObjectiveSolutionContext<BinaryVector>> BestResultParameter { get; private set; }36 //public IResultDefinition<ISingleObjectiveSolutionContext<BinaryVector>> BestResult => BestResultParameter;37 35 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 36 [Storable] public IResult<ISingleObjectiveSolutionContext<BinaryVector>> BestSolutionResult { get; private set; } 37 38 private ISingleObjectiveSolutionContext<BinaryVector> BestSolution { 39 get => BestSolutionResult.Value; 40 set => BestSolutionResult.Value = value; 41 } 38 42 39 43 public int Dimension { … … 51 55 protected BinaryVectorProblem(BinaryVectorProblem original, Cloner cloner) 52 56 : base(original, cloner) { 53 BestResultParameter = cloner.Clone(original.BestResultParameter);54 57 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 58 BestSolutionResult = cloner.Clone(original.BestSolutionResult); 55 59 RegisterEventHandlers(); 56 60 } … … 59 63 protected BinaryVectorProblem(BinaryVectorEncoding encoding) : base(encoding) { 60 64 EncodingParameter.ReadOnly = true; 61 Parameters.Add(BestResultParameter = new ResultParameter<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution", "The best solution."));62 65 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter)); 66 Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution")); 63 67 64 68 Operators.Add(new HammingSimilarityCalculator()); … … 73 77 base.Analyze(solutionContexts, results, random); 74 78 var best = GetBest(solutionContexts); 75 var currentBest = BestResultParameter.ActualValue; 76 if (currentBest == null || IsBetter(best.EvaluationResult.Quality, currentBest.EvaluationResult.Quality)) 77 BestResultParameter.ActualValue = best.Clone() as SingleObjectiveSolutionContext<BinaryVector>; 79 if (BestSolution == null || IsBetter(best, BestSolution)) 80 BestSolution = best.Clone() as SingleObjectiveSolutionContext<BinaryVector>; 78 81 } 79 82 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs
r17594 r17612 35 35 public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> { 36 36 [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; } 37 //public IResultDefinition<ParetoFrontScatterPlot<IntegerVector>> BestResult { get { return BestResultParameter; } }38 37 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 39 38 [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs
r17594 r17612 36 36 public abstract class IntegerVectorProblem : SingleObjectiveProblem<IntegerVectorEncoding, IntegerVector> { 37 37 [Storable] protected IResultParameter<IntegerVector> BestResultParameter { get; private set; } 38 //public IResultDefinition<IntegerVector> BestResult { get => BestResultParameter; }39 38 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 40 39 [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs
r17594 r17612 86 86 if (problem != value) { 87 87 if ((value != null) && !ProblemType.IsInstanceOfType(value)) throw new ArgumentException("Invalid problem type."); 88 if (problem != null) DeregisterProblemEvents(); 88 if (problem != null) { 89 Results.RemoveRange(problem.Results); 90 DeregisterProblemEvents(); 91 } 89 92 problem = value; 90 if (problem != null) RegisterProblemEvents(); 93 if (problem != null) { 94 Results.AddRange(problem.Results); 95 RegisterProblemEvents(); 96 } 91 97 OnProblemChanged(); 92 98 Prepare(); … … 203 209 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 204 210 211 //TODO Reset all results 205 212 Results.Reset(); 206 213 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IProblem.cs
r17513 r17612 32 32 /// </summary> 33 33 public interface IProblem : IParameterizedNamedItem, IStorableContent { 34 //TODO extract into interface? ResultsProducingItems? Problem and Algorithm 35 ResultCollection Results { get; } 34 36 35 37 event EventHandler Reset; … … 48 50 public interface IProblem<TEncoding, TEncodedSolution> : IHeuristicOptimizationProblem 49 51 where TEncoding : class, IEncoding<TEncodedSolution> 50 where TEncodedSolution : class, IEncodedSolution { } 52 where TEncodedSolution : class, IEncodedSolution { 53 } 51 54 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IProblemDefinition.cs
r17586 r17612 34 34 where TEncodedSolution : class, IEncodedSolution { 35 35 TEncoding Encoding { get; } 36 37 36 } 38 37 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs
r17610 r17612 52 52 } 53 53 54 54 55 ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator { 55 56 get { return Encoding.SolutionCreator; } … … 67 68 } 68 69 69 //TODO is a parameter for the evaluator really necessary, only single-objective or multi-objective ev ulators calling the func are possible70 //TODO is a parameter for the evaluator really necessary, only single-objective or multi-objective evaluators calling the func are possible 70 71 public ValueParameter<TEvaluator> EvaluatorParameter { 71 72 get { return (ValueParameter<TEvaluator>)Parameters["Evaluator"]; } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
r17610 r17612 130 130 public virtual bool IsBetter(double quality, double bestQuality) { 131 131 return IsBetter(Maximization, quality, bestQuality); 132 } 133 134 public virtual bool IsBetter(ISingleObjectiveSolutionContext<TEncodedSolution> solution, ISingleObjectiveSolutionContext<TEncodedSolution> otherSolution) { 135 return IsBetter(Maximization, solution.EvaluationResult.Quality, otherSolution.EvaluationResult.Quality); 132 136 } 133 137 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/Problem.cs
r17570 r17612 39 39 } 40 40 41 41 [Storable] 42 public ResultCollection Results { get; } = new ResultCollection(); 42 43 43 44 [StorableConstructor] 44 45 protected Problem(StorableConstructorFlag _) : base(_) { } 45 protected Problem(Problem original, Cloner cloner) : base(original, cloner) { } 46 protected Problem(Problem original, Cloner cloner) : base(original, cloner) { 47 Results = cloner.Clone(original.Results); 48 } 46 49 public Problem() : base() { } 47 50 … … 157 160 158 161 159 protected virtual void ParameterizeOperators() { 160 161 } 162 protected virtual void ParameterizeOperators() { } 162 163 163 164 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/UserDefinedProblem.cs
r17226 r17612 40 40 [Creatable(CreatableAttribute.Categories.Problems, Priority = 120)] 41 41 [StorableType("9F18A098-A8B8-4F70-93CF-79FF1496AC8A")] 42 public sealed class UserDefinedProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent { 43 public string Filename { get; set; } 42 public sealed class UserDefinedProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent { 44 43 45 44 public static new Image StaticItemImage { … … 170 169 private void OnOperatorsChanged() { 171 170 EventHandler handler = OperatorsChanged; 172 if (handler != null) handler(this, EventArgs.Empty);173 }174 public event EventHandler Reset;175 private void OnReset() {176 EventHandler handler = Reset;177 171 if (handler != null) handler(this, EventArgs.Empty); 178 172 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisProblem.cs
r17226 r17612 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;25 25 using HeuristicLab.Optimization; 26 using HEAL.Attic;27 26 28 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 51 50 52 51 [StorableType("07b08ca0-40cb-433e-8aed-72df06a87d62")] 53 public interface ISymbolicDataAnalysisSingleObjectiveProblem : ISymbolicDataAnalysisProblem, ISingleObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { } 52 public interface ISymbolicDataAnalysisSingleObjectiveProblem : ISymbolicDataAnalysisProblem, ISingleObjectiveHeuristicOptimizationProblem 53 //ISingleObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> 54 { } 54 55 [StorableType("1c5a0cf4-1286-45d8-b126-a6f5ddccf7bf")] 55 public interface ISymbolicDataAnalysisMultiObjectiveProblem : ISymbolicDataAnalysisProblem, IMultiObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { } 56 public interface ISymbolicDataAnalysisMultiObjectiveProblem : ISymbolicDataAnalysisProblem, IMultiObjectiveHeuristicOptimizationProblem 57 //IMultiObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> 58 { } 56 59 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs
r17594 r17612 47 47 [Storable] public OptionalValueParameter<OrienteeringSolution> BestKnownSolutionParameter { get; private set; } 48 48 [Storable] private IResultParameter<OrienteeringSolution> BestOrienteeringSolutionParameter { get; set; } 49 //public IResultDefinition<OrienteeringSolution> BestOrienteeringSolution => BestOrienteeringSolutionParameter;50 49 51 50 public IOrienteeringProblemData OrienteeringProblemData { … … 122 121 } 123 122 var bestSoFar = BestOrienteeringSolutionParameter.ActualValue; 124 123 125 124 if (bestSoFar == null || IsBetter(quality, bestSoFar.Quality.Value)) { 126 125 bestSoFar = data.GetSolution((IntegerVector)best.Clone(), quality, score, travelCosts); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs
r17594 r17612 48 48 [Storable] public IValueParameter<ITSPSolution> BestKnownSolutionParameter { get; private set; } 49 49 [Storable] protected IResultParameter<ITSPSolution> BestTSPSolutionParameter { get; private set; } 50 //public IResultDefinition<ITSPSolution> BestTSPSolution => BestTSPSolutionParameter;51 50 52 51 public ITSPData TSPData {
Note: See TracChangeset
for help on using the changeset viewer.