Changeset 13359 for branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Individuals
- Timestamp:
- 11/24/15 15:24:12 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/MultiSolution.cs
r13356 r13359 35 35 protected IScope Scope { get; private set; } 36 36 37 private readonly Dictionary<string, ISolution> solutions;38 39 37 [StorableConstructor] 40 38 private CombinedSolution(bool deserializing) : base(deserializing) { } … … 44 42 Encoding = cloner.Clone(original.Encoding); 45 43 Scope = cloner.Clone(original.Scope); 46 solutions = original.solutions.ToDictionary(x => x.Key, x => cloner.Clone(x.Value));47 44 } 48 45 public CombinedSolution(IScope scope, MultiEncoding encoding) { 49 46 Encoding = encoding; 50 47 Scope = scope; 51 solutions = encoding.Encodings.Select(e => new { Name = e.Name, Solution = ScopeUtil.GetSolution(scope, e) })52 .ToDictionary(x => x.Name, x => x.Solution);53 48 } 54 49 … … 58 53 59 54 public ISolution this[string name] { 60 get { 61 ISolution result; 62 if (!solutions.TryGetValue(name, out result)) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name)); 63 return result; 64 } 65 set { 66 if (!solutions.ContainsKey(name)) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name)); 67 solutions[name] = value; 68 } 55 get { return ScopeUtil.GetSolution(Scope, name); } 56 set { ScopeUtil.CopySolutionToScope(Scope, name, value); } 69 57 } 70 58 … … 80 68 } 81 69 82 public TSolution GetSolution<TSolution>() where TSolution : class, ISolution { 83 TSolution solution; 84 try { 85 solution = (TSolution)solutions.SingleOrDefault(s => s.Value is TSolution).Value; 86 } catch (InvalidOperationException) { 87 throw new InvalidOperationException(string.Format("The solution uses multiple {0} .", typeof(TSolution).GetPrettyName())); 88 } 89 if (solution == null) throw new InvalidOperationException(string.Format("The solution does not use a {0}.", typeof(TSolution).GetPrettyName())); 90 return solution; 70 public TSolution GetSolution<TSolution>(string name) where TSolution : class, ISolution { 71 return (TSolution)ScopeUtil.GetSolution(Scope, name); 91 72 } 92 73 }
Note: See TracChangeset
for help on using the changeset viewer.