Changeset 15281 for branches/Async/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/MultiEncodingIndividual.cs
- Timestamp:
- 07/23/17 11:17:18 (7 years ago)
- Location:
- branches/Async
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Async
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/Async/HeuristicLab.Optimization
- Property svn:mergeinfo changed
-
branches/Async/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/MultiEncodingIndividual.cs
r12012 r15281 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 32 32 } 33 33 34 private readonly IEnumerable<Individual> individuals; 34 public MultiEncodingIndividual(MultiEncoding encoding, IScope scope) 35 : base(encoding, scope) { } 35 36 36 public MultiEncodingIndividual(MultiEncoding encoding, IScope scope) 37 : base(encoding, scope) { 38 individuals = encoding.Encodings.Select(e => e.GetIndividual(scope)).ToArray(); 37 private MultiEncodingIndividual(MultiEncodingIndividual copy) : base(copy.Encoding, new Scope()) { 38 copy.CopyToScope(Scope); 39 39 } 40 41 private MultiEncodingIndividual(MultiEncoding encoding, IScope scope, IEnumerable<Individual> individuals) 42 : base(encoding, scope) { 43 this.individuals = individuals; 44 } 45 46 47 public override IItem this[string name] { 48 get { 49 var individual = individuals.SingleOrDefault(i => i.Name == name); 50 if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name)); 51 return individual[name]; 52 } 53 set { 54 var individual = individuals.SingleOrDefault(i => i.Name == name); 55 if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name)); 56 individual[name] = value; 57 } 40 public override Individual Copy() { 41 return new MultiEncodingIndividual(this); 58 42 } 59 43 … … 62 46 try { 63 47 encoding = (TEncoding)Encoding.Encodings.SingleOrDefault(e => e is TEncoding); 64 } catch (InvalidOperationException) { 48 } 49 catch (InvalidOperationException) { 65 50 throw new InvalidOperationException(string.Format("The individual uses multiple {0} .", typeof(TEncoding).GetPrettyName())); 66 51 } … … 68 53 return encoding; 69 54 } 70 71 public override Individual CopyToScope(IScope scope) {72 var copies = individuals.Select(i => i.CopyToScope(scope)).ToArray();73 return new MultiEncodingIndividual(Encoding, scope, copies);74 }75 55 } 76 56 }
Note: See TracChangeset
for help on using the changeset viewer.