Changeset 16751 for branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators
- Timestamp:
- 04/03/19 15:37:38 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiObjectiveAnalyzer.cs
r16723 r16751 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 28 29 using HeuristicLab.Operators; 29 30 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 31 32 32 namespace HeuristicLab.Optimization { 33 33 [Item("Multi-objective Analyzer", "Calls the Analyze method of the problem definition.")] 34 34 [StorableType("903FE3D1-3179-4EA5-A7E1-63DE26239F9B")] 35 public class MultiObjectiveAnalyzer<T Solution> : SingleSuccessorOperator, IMultiObjectiveAnalysisOperator<TSolution>, IStochasticOperator36 where T Solution : class, ISolution {35 public class MultiObjectiveAnalyzer<TEncodedSolution> : SingleSuccessorOperator, IMultiObjectiveAnalysisOperator<TEncodedSolution>, IStochasticOperator 36 where TEncodedSolution : class, IEncodedSolution { 37 37 public bool EnabledByDefault { get { return true; } } 38 38 39 public ILookupParameter<IEncoding<T Solution>> EncodingParameter {40 get { return (ILookupParameter<IEncoding<T Solution>>)Parameters["Encoding"]; }39 public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter { 40 get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; } 41 41 } 42 42 … … 53 53 } 54 54 55 public Action<T Solution[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; }55 public Action<TEncodedSolution[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; } 56 56 57 57 [StorableConstructor] 58 58 protected MultiObjectiveAnalyzer(StorableConstructorFlag _) : base(_) { } 59 protected MultiObjectiveAnalyzer(MultiObjectiveAnalyzer<T Solution> original, Cloner cloner) : base(original, cloner) { }59 protected MultiObjectiveAnalyzer(MultiObjectiveAnalyzer<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 60 60 public MultiObjectiveAnalyzer() { 61 61 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 62 Parameters.Add(new LookupParameter<IEncoding<T Solution>>("Encoding", "An item that holds the problem's encoding."));62 Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding.")); 63 63 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector.")); 64 64 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to.")); … … 66 66 67 67 public override IDeepCloneable Clone(Cloner cloner) { 68 return new MultiObjectiveAnalyzer<T Solution>(this, cloner);68 return new MultiObjectiveAnalyzer<TEncodedSolution>(this, cloner); 69 69 } 70 70 … … 78 78 scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b)); 79 79 80 var individuals = scopes.Select(s => ScopeUtil.Get Solution(s, encoding)).ToArray();80 var individuals = scopes.Select(s => ScopeUtil.GetEncodedSolution(s, encoding)).ToArray(); 81 81 AnalyzeAction(individuals, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results, random); 82 82 return base.Apply(); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiObjectiveEvaluator.cs
r16723 r16751 21 21 22 22 using System; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Operators; 27 28 using HeuristicLab.Parameters; 28 using HEAL.Attic;29 29 30 30 namespace HeuristicLab.Optimization { 31 31 [Item("Multi-objective Evaluator", "Calls the Evaluate method of the problem definition and writes the return value into the scope.")] 32 32 [StorableType("C5605ED8-0ED2-4C7B-97A1-E7EB68A4FDBF")] 33 public class MultiObjectiveEvaluator<T Solution> : InstrumentedOperator, IMultiObjectiveEvaluationOperator<TSolution>, IStochasticOperator34 where T Solution : class, ISolution {33 public class MultiObjectiveEvaluator<TEncodedSolution> : InstrumentedOperator, IMultiObjectiveEvaluationOperator<TEncodedSolution>, IStochasticOperator 34 where TEncodedSolution : class, IEncodedSolution { 35 35 36 36 public ILookupParameter<IRandom> RandomParameter { … … 38 38 } 39 39 40 public ILookupParameter<IEncoding<T Solution>> EncodingParameter {41 get { return (ILookupParameter<IEncoding<T Solution>>)Parameters["Encoding"]; }40 public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter { 41 get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; } 42 42 } 43 43 … … 46 46 } 47 47 48 public Func<T Solution, IRandom, double[]> EvaluateFunc { get; set; }48 public Func<TEncodedSolution, IRandom, double[]> EvaluateFunc { get; set; } 49 49 50 50 [StorableConstructor] 51 51 protected MultiObjectiveEvaluator(StorableConstructorFlag _) : base(_) { } 52 protected MultiObjectiveEvaluator(MultiObjectiveEvaluator<T Solution> original, Cloner cloner) : base(original, cloner) { }52 protected MultiObjectiveEvaluator(MultiObjectiveEvaluator<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 53 53 public MultiObjectiveEvaluator() { 54 54 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 55 Parameters.Add(new LookupParameter<IEncoding<T Solution>>("Encoding", "An item that holds the problem's encoding."));55 Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding.")); 56 56 Parameters.Add(new LookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector.")); 57 57 } 58 58 59 59 public override IDeepCloneable Clone(Cloner cloner) { 60 return new MultiObjectiveEvaluator<T Solution>(this, cloner);60 return new MultiObjectiveEvaluator<TEncodedSolution>(this, cloner); 61 61 } 62 62 … … 64 64 var random = RandomParameter.ActualValue; 65 65 var encoding = EncodingParameter.ActualValue; 66 var solution = ScopeUtil.Get Solution(ExecutionContext.Scope, encoding);66 var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding); 67 67 QualitiesParameter.ActualValue = new DoubleArray(EvaluateFunc(solution, random)); 68 68 return base.InstrumentedApply(); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/ScopeUtil.cs
r13359 r16751 29 29 public static class ScopeUtil { 30 30 31 public static T Solution CopySolutionToScope<TSolution>(IScope scope, IEncoding<TSolution> encoding, TSolution solution)32 where T Solution : class,ISolution {33 return Copy SolutionToScope(scope, encoding.Name, solution);31 public static TEncodedSolution CopyEncodedSolutionToScope<TEncodedSolution>(IScope scope, IEncoding<TEncodedSolution> encoding, TEncodedSolution solution) 32 where TEncodedSolution : class, IEncodedSolution { 33 return CopyEncodedSolutionToScope(scope, encoding.Name, solution); 34 34 } 35 35 36 public static T Solution CopySolutionToScope<TSolution>(IScope scope, string name, TSolution solution)37 where T Solution : class,ISolution {38 var copy = (T Solution)solution.Clone();36 public static TEncodedSolution CopyEncodedSolutionToScope<TEncodedSolution>(IScope scope, string name, TEncodedSolution solution) 37 where TEncodedSolution : class, IEncodedSolution { 38 var copy = (TEncodedSolution)solution.Clone(); 39 39 if (!scope.Variables.ContainsKey(name)) scope.Variables.Add(new Variable(name, copy)); 40 40 else scope.Variables[name].Value = copy; … … 42 42 } 43 43 44 public static T Solution GetSolution<TSolution>(IScope scope, IEncoding<TSolution> encoding)45 where T Solution : class,ISolution {44 public static TEncodedSolution GetEncodedSolution<TEncodedSolution>(IScope scope, IEncoding<TEncodedSolution> encoding) 45 where TEncodedSolution : class, IEncodedSolution { 46 46 var name = encoding.Name; 47 47 if (!scope.Variables.ContainsKey(name)) throw new ArgumentException(string.Format(" {0} cannot be found in the provided scope.", name)); 48 var value = scope.Variables[name].Value as T Solution;49 if (value == null) throw new InvalidOperationException(string.Format("Value of {0} is null or not of type {1}.", name, typeof(T Solution).GetPrettyName()));48 var value = scope.Variables[name].Value as TEncodedSolution; 49 if (value == null) throw new InvalidOperationException(string.Format("Value of {0} is null or not of type {1}.", name, typeof(TEncodedSolution).GetPrettyName())); 50 50 return value; 51 51 } 52 52 53 public static I Solution GetSolution(IScope scope, IEncoding encoding) {54 return Get Solution(scope, encoding.Name);53 public static IEncodedSolution GetEncodedSolution(IScope scope, IEncoding encoding) { 54 return GetEncodedSolution(scope, encoding.Name); 55 55 } 56 56 57 public static I Solution GetSolution(IScope scope, string name) {57 public static IEncodedSolution GetEncodedSolution(IScope scope, string name) { 58 58 IVariable variable; 59 59 if (!scope.Variables.TryGetValue(name, out variable)) throw new ArgumentException(string.Format("{0} cannot be found in the provided scope.", name)); 60 var solution = variable.Value as I Solution;60 var solution = variable.Value as IEncodedSolution; 61 61 if (solution == null) throw new InvalidOperationException(string.Format("{0} is null or not of type ISolution.", name)); 62 62 return solution; -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveAnalyzer.cs
r16723 r16751 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 28 29 using HeuristicLab.Operators; 29 30 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 31 32 32 namespace HeuristicLab.Optimization { 33 33 [Item("Single-objective Analyzer", "Calls the script's Analyze method to be able to write into the results collection.")] 34 34 [StorableType("3D20F8E2-CE11-4021-A05B-CFCB02C0FD6F")] 35 public sealed class SingleObjectiveAnalyzer<T Solution> : SingleSuccessorOperator, ISingleObjectiveAnalysisOperator<TSolution>, IAnalyzer, IStochasticOperator36 where T Solution : class, ISolution {35 public sealed class SingleObjectiveAnalyzer<TEncodedSolution> : SingleSuccessorOperator, ISingleObjectiveAnalysisOperator<TEncodedSolution>, IAnalyzer, IStochasticOperator 36 where TEncodedSolution : class, IEncodedSolution { 37 37 public bool EnabledByDefault { get { return true; } } 38 38 39 public ILookupParameter<IEncoding<T Solution>> EncodingParameter {40 get { return (ILookupParameter<IEncoding<T Solution>>)Parameters["Encoding"]; }39 public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter { 40 get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; } 41 41 } 42 42 … … 53 53 } 54 54 55 public Action<T Solution[], double[], ResultCollection, IRandom> AnalyzeAction { get; set; }55 public Action<TEncodedSolution[], double[], ResultCollection, IRandom> AnalyzeAction { get; set; } 56 56 57 57 [StorableConstructor] 58 58 private SingleObjectiveAnalyzer(StorableConstructorFlag _) : base(_) { } 59 private SingleObjectiveAnalyzer(SingleObjectiveAnalyzer<T Solution> original, Cloner cloner) : base(original, cloner) { }59 private SingleObjectiveAnalyzer(SingleObjectiveAnalyzer<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 60 60 public SingleObjectiveAnalyzer() { 61 Parameters.Add(new LookupParameter<IEncoding<T Solution>>("Encoding", "An item that holds the problem's encoding."));61 Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding.")); 62 62 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); 63 63 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to.")); … … 66 66 67 67 public override IDeepCloneable Clone(Cloner cloner) { 68 return new SingleObjectiveAnalyzer<T Solution>(this, cloner);68 return new SingleObjectiveAnalyzer<TEncodedSolution>(this, cloner); 69 69 } 70 70 … … 78 78 scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b)); 79 79 80 var individuals = scopes.Select(s => ScopeUtil.Get Solution(s, encoding)).ToArray();80 var individuals = scopes.Select(s => ScopeUtil.GetEncodedSolution(s, encoding)).ToArray(); 81 81 AnalyzeAction(individuals, QualityParameter.ActualValue.Select(x => x.Value).ToArray(), results, random); 82 82 return base.Apply(); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveEvaluator.cs
r16723 r16751 31 31 [Item("Single-objective Evaluator", "Calls the script's Evaluate method to get the quality value of the parameter vector.")] 32 32 [StorableType("E8914B68-D0D7-407F-8D58-002FDF2F45CF")] 33 public sealed class SingleObjectiveEvaluator<T Solution> : InstrumentedOperator, ISingleObjectiveEvaluationOperator<TSolution>, IStochasticOperator34 where T Solution : class, ISolution {33 public sealed class SingleObjectiveEvaluator<TEncodedSolution> : InstrumentedOperator, ISingleObjectiveEvaluationOperator<TEncodedSolution>, IStochasticOperator 34 where TEncodedSolution : class, IEncodedSolution { 35 35 36 36 public ILookupParameter<IRandom> RandomParameter { … … 38 38 } 39 39 40 public ILookupParameter<IEncoding<T Solution>> EncodingParameter {41 get { return (ILookupParameter<IEncoding<T Solution>>)Parameters["Encoding"]; }40 public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter { 41 get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; } 42 42 } 43 43 … … 46 46 } 47 47 48 public Func<T Solution, IRandom, double> EvaluateFunc { get; set; }48 public Func<TEncodedSolution, IRandom, double> EvaluateFunc { get; set; } 49 49 50 50 [StorableConstructor] 51 51 private SingleObjectiveEvaluator(StorableConstructorFlag _) : base(_) { } 52 private SingleObjectiveEvaluator(SingleObjectiveEvaluator<T Solution> original, Cloner cloner) : base(original, cloner) { }52 private SingleObjectiveEvaluator(SingleObjectiveEvaluator<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 53 53 public SingleObjectiveEvaluator() { 54 54 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 55 Parameters.Add(new LookupParameter<IEncoding<T Solution>>("Encoding", "An item that holds the problem's encoding."));55 Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding.")); 56 56 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); 57 57 } 58 58 59 public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveEvaluator<T Solution>(this, cloner); }59 public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveEvaluator<TEncodedSolution>(this, cloner); } 60 60 61 61 public override IOperation InstrumentedApply() { 62 62 var random = RandomParameter.ActualValue; 63 63 var encoding = EncodingParameter.ActualValue; 64 var solution = ScopeUtil.Get Solution(ExecutionContext.Scope, encoding);64 var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding); 65 65 QualityParameter.ActualValue = new DoubleValue(EvaluateFunc(solution, random)); 66 66 return base.InstrumentedApply(); -
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 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveMoveEvaluator.cs
r16723 r16751 21 21 22 22 using System; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Operators; 27 28 using HeuristicLab.Parameters; 28 using HEAL.Attic;29 29 30 30 namespace HeuristicLab.Optimization { 31 31 [Item("Single-objective MoveEvaluator", "Evaluates a parameter vector that results from a move.")] 32 32 [StorableType("EE4B1EBA-50BF-40C7-B338-F4A9D9CC554E")] 33 public class SingleObjectiveMoveEvaluator<T Solution> : SingleSuccessorOperator, ISingleObjectiveEvaluationOperator<TSolution>, ISingleObjectiveMoveEvaluator, IStochasticOperator, ISingleObjectiveMoveOperator34 where T Solution : class, ISolution {33 public class SingleObjectiveMoveEvaluator<TEncodedSolution> : SingleSuccessorOperator, ISingleObjectiveEvaluationOperator<TEncodedSolution>, ISingleObjectiveMoveEvaluator, IStochasticOperator, ISingleObjectiveMoveOperator 34 where TEncodedSolution : class, IEncodedSolution { 35 35 36 36 public ILookupParameter<IRandom> RandomParameter { … … 38 38 } 39 39 40 public ILookupParameter<IEncoding<T Solution>> EncodingParameter {41 get { return (ILookupParameter<IEncoding<T Solution>>)Parameters["Encoding"]; }40 public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter { 41 get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; } 42 42 } 43 43 … … 50 50 } 51 51 52 public Func<T Solution, IRandom, double> EvaluateFunc { get; set; }52 public Func<TEncodedSolution, IRandom, double> EvaluateFunc { get; set; } 53 53 54 54 [StorableConstructor] 55 55 protected SingleObjectiveMoveEvaluator(StorableConstructorFlag _) : base(_) { } 56 protected SingleObjectiveMoveEvaluator(SingleObjectiveMoveEvaluator<T Solution> original, Cloner cloner) : base(original, cloner) { }56 protected SingleObjectiveMoveEvaluator(SingleObjectiveMoveEvaluator<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 57 57 public SingleObjectiveMoveEvaluator() { 58 58 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 59 Parameters.Add(new LookupParameter<IEncoding<T Solution>>("Encoding", "An item that holds the problem's encoding."));59 Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding.")); 60 60 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); 61 61 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move.")); … … 63 63 64 64 public override IDeepCloneable Clone(Cloner cloner) { 65 return new SingleObjectiveMoveEvaluator<T Solution>(this, cloner);65 return new SingleObjectiveMoveEvaluator<TEncodedSolution>(this, cloner); 66 66 } 67 67 … … 69 69 var random = RandomParameter.ActualValue; 70 70 var encoding = EncodingParameter.ActualValue; 71 var individual = ScopeUtil.Get Solution(ExecutionContext.Scope, encoding);71 var individual = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding); 72 72 MoveQualityParameter.ActualValue = new DoubleValue(EvaluateFunc(individual, random)); 73 73 return base.Apply(); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveMoveGenerator.cs
r16723 r16751 34 34 [Item("Single-objective MoveGenerator", "Calls the GetNeighbors method of the problem definition to obtain the moves.")] 35 35 [StorableType("CB37E7D8-EAC3-4061-9D39-20538CD1064D")] 36 public class SingleObjectiveMoveGenerator<T Solution> : SingleSuccessorOperator, INeighborBasedOperator<TSolution>, IMultiMoveGenerator, IStochasticOperator, ISingleObjectiveMoveOperator37 where T Solution : class, ISolution {36 public class SingleObjectiveMoveGenerator<TEncodedSolution> : SingleSuccessorOperator, INeighborBasedOperator<TEncodedSolution>, IMultiMoveGenerator, IStochasticOperator, ISingleObjectiveMoveOperator 37 where TEncodedSolution : class, IEncodedSolution { 38 38 public ILookupParameter<IRandom> RandomParameter { 39 39 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } … … 44 44 } 45 45 46 public ILookupParameter<IEncoding<T Solution>> EncodingParameter {47 get { return (ILookupParameter<IEncoding<T Solution>>)Parameters["Encoding"]; }46 public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter { 47 get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; } 48 48 } 49 49 50 public Func<T Solution, IRandom, IEnumerable<TSolution>> GetNeighborsFunc { get; set; }50 public Func<TEncodedSolution, IRandom, IEnumerable<TEncodedSolution>> GetNeighborsFunc { get; set; } 51 51 52 52 [StorableConstructor] 53 53 protected SingleObjectiveMoveGenerator(StorableConstructorFlag _) : base(_) { } 54 protected SingleObjectiveMoveGenerator(SingleObjectiveMoveGenerator<T Solution> original, Cloner cloner)54 protected SingleObjectiveMoveGenerator(SingleObjectiveMoveGenerator<TEncodedSolution> original, Cloner cloner) 55 55 : base(original, cloner) { } 56 56 public SingleObjectiveMoveGenerator() { 57 57 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 58 58 Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to sample.")); 59 Parameters.Add(new LookupParameter<IEncoding<T Solution>>("Encoding", "An item that holds the problem's encoding."));59 Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding.")); 60 60 } 61 61 62 62 public override IDeepCloneable Clone(Cloner cloner) { 63 return new SingleObjectiveMoveGenerator<T Solution>(this, cloner);63 return new SingleObjectiveMoveGenerator<TEncodedSolution>(this, cloner); 64 64 } 65 65 … … 68 68 var sampleSize = SampleSizeParameter.ActualValue.Value; 69 69 var encoding = EncodingParameter.ActualValue; 70 var solution = ScopeUtil.Get Solution(ExecutionContext.Scope, encoding);70 var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding); 71 71 var nbhood = GetNeighborsFunc(solution, random).Take(sampleSize).ToList(); 72 72 … … 74 74 for (int i = 0; i < moveScopes.Length; i++) { 75 75 moveScopes[i] = new Scope(i.ToString(CultureInfo.InvariantCulture.NumberFormat)); 76 ScopeUtil.Copy SolutionToScope(moveScopes[i], encoding, nbhood[i]);76 ScopeUtil.CopyEncodedSolutionToScope(moveScopes[i], encoding, nbhood[i]); 77 77 } 78 78 ExecutionContext.Scope.SubScopes.AddRange(moveScopes); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveMoveMaker.cs
r16723 r16751 21 21 22 22 using System; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Operators; 27 28 using HeuristicLab.Parameters; 28 using HEAL.Attic;29 29 30 30 namespace HeuristicLab.Optimization { 31 31 [Item("Single-objective MoveMaker", "Applies a move.")] 32 32 [StorableType("C0ABF392-C825-4B98-8FB9-5749A9091FD6")] 33 public class SingleObjectiveMoveMaker<T Solution> : InstrumentedOperator, IMoveMaker, ISingleObjectiveMoveOperator34 where T Solution : class, ISolution {35 public ILookupParameter<IEncoding<T Solution>> EncodingParameter {36 get { return (ILookupParameter<IEncoding<T Solution>>)Parameters["Encoding"]; }33 public class SingleObjectiveMoveMaker<TEncodedSolution> : InstrumentedOperator, IMoveMaker, ISingleObjectiveMoveOperator 34 where TEncodedSolution : class, IEncodedSolution { 35 public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter { 36 get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; } 37 37 } 38 38 … … 47 47 [StorableConstructor] 48 48 protected SingleObjectiveMoveMaker(StorableConstructorFlag _) : base(_) { } 49 protected SingleObjectiveMoveMaker(SingleObjectiveMoveMaker<T Solution> original, Cloner cloner) : base(original, cloner) { }49 protected SingleObjectiveMoveMaker(SingleObjectiveMoveMaker<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 50 50 public SingleObjectiveMoveMaker() { 51 Parameters.Add(new LookupParameter<IEncoding<T Solution>>("Encoding", "An item that holds the problem's encoding."));51 Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding.")); 52 52 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); 53 53 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move.")); … … 55 55 56 56 public override IDeepCloneable Clone(Cloner cloner) { 57 return new SingleObjectiveMoveMaker<T Solution>(this, cloner);57 return new SingleObjectiveMoveMaker<TEncodedSolution>(this, cloner); 58 58 } 59 59 … … 62 62 63 63 var encoding = EncodingParameter.ActualValue; 64 var solution = ScopeUtil.Get Solution(ExecutionContext.Scope, encoding);65 ScopeUtil.Copy SolutionToScope(ExecutionContext.Scope.Parent.Parent, encoding, solution);64 var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding); 65 ScopeUtil.CopyEncodedSolutionToScope(ExecutionContext.Scope.Parent.Parent, encoding, solution); 66 66 67 67 if (QualityParameter.ActualValue == null) QualityParameter.ActualValue = new DoubleValue(MoveQualityParameter.ActualValue.Value);
Note: See TracChangeset
for help on using the changeset viewer.