Changeset 17381 for branches/2521_ProblemRefactoring
- Timestamp:
- 12/18/19 15:06:18 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/EvaluationResult.cs
r17357 r17381 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; … … 42 43 43 44 protected EvaluationResult(EvaluationResult original, Cloner cloner) : base(original, cloner) { 44 //TODO clone data dictionary 45 data = original.data.ToDictionary(entry => entry.Key, 46 entry => entry.Value is DeepCloneable ? cloner.Clone((DeepCloneable)entry.Value) : entry.Value); 45 47 } 46 48 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveAnalyzer.cs
r17363 r17381 82 82 var quality = ((DoubleValue)scope.Variables[QualityParameter.ActualName].Value).Value; 83 83 var solutionContext = new SingleObjectiveSolutionContextScope<TEncodedSolution>(scope, solution); 84 solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality);85 84 return solutionContext; 86 85 }).ToArray(); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SolutionContextScope.cs
r17363 r17381 27 27 //TODO: don't derive from NamedItem, this has been done to have a fast working prototype 28 28 namespace HeuristicLab.Optimization { 29 internal class SolutionContextScope<TEncodedSolution> : SolutionContext<TEncodedSolution>, ISolutionScope29 internal abstract class SolutionContextScope<TEncodedSolution> : SolutionContext<TEncodedSolution>, ISolutionScope 30 30 where TEncodedSolution : class, IEncodedSolution { 31 private readonly IScope scope; 31 protected static string EVALUATION_RESULT_VARIABLE_NAME = "Evaluation Result"; 32 33 protected IScope Scope { get; } 32 34 33 35 public SolutionContextScope(IScope scope, TEncodedSolution solution) : base(solution) { 34 this.scope = scope;36 Scope = scope; 35 37 } 36 38 … … 40 42 41 43 IScope IScope.Parent { 42 get { return scope.Parent; }44 get { return Scope.Parent; } 43 45 set { throw new NotSupportedException(); } 44 46 } 45 47 46 VariableCollection IScope.Variables => scope.Variables;47 ScopeList IScope.SubScopes => scope.SubScopes;48 VariableCollection IScope.Variables => Scope.Variables; 49 ScopeList IScope.SubScopes => Scope.SubScopes; 48 50 49 51 void IScope.Clear() { throw new NotImplementedException(); } 50 52 51 52 53 53 #region INamedItem members 54 string INamedItem.Name { get { return scope.Name; } set => throw new NotImplementedException(); }54 string INamedItem.Name { get { return Scope.Name; } set => throw new NotImplementedException(); } 55 55 bool INamedItem.CanChangeName => false; 56 56 57 string INamedItem.Description { get { return scope.Description; } set => throw new NotImplementedException(); }57 string INamedItem.Description { get { return Scope.Description; } set => throw new NotImplementedException(); } 58 58 bool INamedItem.CanChangeDescription => false; 59 59 … … 78 78 where TEncodedSolution : class, IEncodedSolution { 79 79 80 public new ISingleObjectiveEvaluationResult EvaluationResult { get; set; } 80 public new ISingleObjectiveEvaluationResult EvaluationResult { 81 get { 82 return (ISingleObjectiveEvaluationResult)Scope.Variables[EVALUATION_RESULT_VARIABLE_NAME].Value; 83 } 84 set { 85 Scope.Variables.Remove(EVALUATION_RESULT_VARIABLE_NAME); 86 Scope.Variables.Add(new Variable(EVALUATION_RESULT_VARIABLE_NAME, value)); 87 } 88 } 89 81 90 public SingleObjectiveSolutionContextScope(IScope scope, TEncodedSolution solution) : base(scope, solution) { 82 91 } … … 86 95 where TEncodedSolution : class, IEncodedSolution { 87 96 88 public new IMultiObjectiveEvaluationResult EvaluationResult { get; set; } 97 public new IMultiObjectiveEvaluationResult EvaluationResult { 98 get { 99 return (IMultiObjectiveEvaluationResult)Scope.Variables[EVALUATION_RESULT_VARIABLE_NAME].Value; 100 } 101 set { 102 Scope.Variables.Remove(EVALUATION_RESULT_VARIABLE_NAME); 103 Scope.Variables.Add(new Variable(EVALUATION_RESULT_VARIABLE_NAME, value)); 104 } 105 } 89 106 public MultiObjectiveSolutionContextScope(IScope scope, TEncodedSolution solution) : base(scope, solution) { 90 107 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SolutionContext.cs
r17366 r17381 23 23 using System; 24 24 using System.Collections.Generic; 25 25 using System.Linq; 26 26 using HEAL.Attic; 27 27 using HeuristicLab.Common; … … 58 58 59 59 public SolutionContext(SolutionContext<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { 60 //TODO clone data dictionary61 60 EncodedSolution = cloner.Clone(original.EncodedSolution); 62 61 EvaluationResult = cloner.Clone(original.EvaluationResult); 62 63 64 data = original.data.ToDictionary(entry => entry.Key, 65 entry => entry.Value is DeepCloneable ? cloner.Clone((DeepCloneable)entry.Value) : entry.Value); 63 66 } 64 67 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs
r17363 r17381 102 102 : base(encoding) { } 103 103 104 #region I SingleObjectiveProblemDefinition<TEncoding,TEncodedSolution> Members104 #region IMultiObjectiveProblemDefinition<TEncoding,TEncodedSolution> Members 105 105 public int Objectives => Maximization.Length; 106 106 public abstract bool[] Maximization { get; } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/SingleObjectiveProblem_Template.cs
r17366 r17381 21 21 } 22 22 23 //TODO add other methods 24 25 public override void Evaluate(ISingleObjectiveSolutionContext<SOLUTION_CLASS> solutionContext, IRandom random, CancellationToken cancellationToken) { 26 var quality = Evaluate(solutionContext.EncodedSolution, random, cancellationToken); 27 var evaluationResult = new SingleObjectiveEvaluationResult(quality); 28 solutionContext.EvaluationResult = evaluationResult; 29 } 30 23 31 public override double Evaluate(SOLUTION_CLASS solution, IRandom random, CancellationToken cancellationToken) { 24 32 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 25 33 var quality = 0.0; 26 34 return quality; 35 } 36 37 public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) { 38 var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray(); 39 var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray(); 40 Analyze(solutions, qualities, results, random); 27 41 } 28 42
Note: See TracChangeset
for help on using the changeset viewer.