Changeset 16751 for branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/ScopeUtil.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/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;
Note: See TracChangeset
for help on using the changeset viewer.