Changeset 16751 for branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveImprover.cs
- Timestamp:
- 04/03/19 15:37:38 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveImprover.cs
r16723 r16751 33 33 [Item("Single-objective Improver", "Improves a solution by calling GetNeighbors and Evaluate of the corresponding problem definition.")] 34 34 [StorableType("7A917E09-920C-4B47-9599-67371101B35F")] 35 public sealed class SingleObjectiveImprover<T Solution> : SingleSuccessorOperator, INeighborBasedOperator<TSolution>, IImprovementOperator, ISingleObjectiveEvaluationOperator<TSolution>, IStochasticOperator36 where T Solution : class, ISolution {35 public sealed class SingleObjectiveImprover<TEncodedSolution> : SingleSuccessorOperator, INeighborBasedOperator<TEncodedSolution>, IImprovementOperator, ISingleObjectiveEvaluationOperator<TEncodedSolution>, IStochasticOperator 36 where TEncodedSolution : class, IEncodedSolution { 37 37 public ILookupParameter<IRandom> RandomParameter { 38 38 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 39 39 } 40 40 41 public ILookupParameter<IEncoding<T Solution>> EncodingParameter {42 get { return (ILookupParameter<IEncoding<T Solution>>)Parameters["Encoding"]; }41 public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter { 42 get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; } 43 43 } 44 44 … … 63 63 } 64 64 65 public Func<T Solution, IRandom, double> EvaluateFunc { get; set; }66 public Func<T Solution, IRandom, IEnumerable<TSolution>> GetNeighborsFunc { get; set; }65 public Func<TEncodedSolution, IRandom, double> EvaluateFunc { get; set; } 66 public Func<TEncodedSolution, IRandom, IEnumerable<TEncodedSolution>> GetNeighborsFunc { get; set; } 67 67 68 68 [StorableConstructor] 69 69 private SingleObjectiveImprover(StorableConstructorFlag _) : base(_) { } 70 private SingleObjectiveImprover(SingleObjectiveImprover<T Solution> original, Cloner cloner) : base(original, cloner) { }70 private SingleObjectiveImprover(SingleObjectiveImprover<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 71 71 public SingleObjectiveImprover() { 72 72 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 73 Parameters.Add(new LookupParameter<IEncoding<T Solution>>("Encoding", "An item that holds the problem's encoding."));73 Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding.")); 74 74 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); 75 75 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Whether the problem should be minimized or maximized.")); … … 80 80 81 81 public override IDeepCloneable Clone(Cloner cloner) { 82 return new SingleObjectiveImprover<T Solution>(this, cloner);82 return new SingleObjectiveImprover<TEncodedSolution>(this, cloner); 83 83 } 84 84 … … 89 89 var maxAttempts = ImprovementAttemptsParameter.ActualValue.Value; 90 90 var sampleSize = SampleSizeParameter.ActualValue.Value; 91 var solution = ScopeUtil.Get Solution(ExecutionContext.Scope, encoding);91 var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding); 92 92 var quality = QualityParameter.ActualValue == null ? EvaluateFunc(solution, random) : QualityParameter.ActualValue.Value; 93 93 94 94 var count = 0; 95 95 for (var i = 0; i < maxAttempts; i++) { 96 T Solution best = default(TSolution);96 TEncodedSolution best = default(TEncodedSolution); 97 97 var bestQuality = quality; 98 98 foreach (var neighbor in GetNeighborsFunc(solution, random).Take(sampleSize)) { … … 111 111 QualityParameter.ActualValue = new DoubleValue(quality); 112 112 113 ScopeUtil.Copy SolutionToScope(ExecutionContext.Scope, encoding, solution);113 ScopeUtil.CopyEncodedSolutionToScope(ExecutionContext.Scope, encoding, solution); 114 114 return base.Apply(); 115 115 }
Note: See TracChangeset
for help on using the changeset viewer.