- Timestamp:
- 10/21/14 18:49:05 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Helper.cs
r11405 r11484 30 30 namespace HeuristicLab.Problems.Programmable { 31 31 internal static class Helper { 32 internal static ParameterVector Extract(IScope scope, Configuration config) { 33 var binDict = new Dictionary<string, BinaryVector>(); 34 var intDict = new Dictionary<string, IntegerVector>(); 35 var realDict = new Dictionary<string, RealVector>(); 36 var permDict = new Dictionary<string, Permutation>(); 37 foreach (var param in config.Parameters) { 38 var binConfig = param.Value as BinaryParameterConfiguration; 39 if (binConfig != null) { 40 binDict.Add(param.Key, (BinaryVector)scope.Variables[param.Key].Value); 41 continue; 32 internal static Individual Extract(IScope scope, Encoding encoding) { 33 Dictionary<string, BinaryVector> binDict = null; 34 Dictionary<string, IntegerVector> intDict = null; 35 Dictionary<string, RealVector> realDict = null; 36 Dictionary<string, Permutation> permDict = null; 37 var multiEncoding = encoding as MultiEncoding; 38 if (multiEncoding != null) { 39 foreach (var enc in multiEncoding.Encodings) { 40 var binConfig = enc as BinaryEncoding; 41 if (binConfig != null) { 42 if (binDict == null) binDict = new Dictionary<string, BinaryVector>(); 43 binDict.Add(enc.Name, (BinaryVector)scope.Variables[enc.Name].Value); 44 continue; 45 } 46 var intConfig = enc as IntegerEncoding; 47 if (intConfig != null) { 48 if (intDict == null) intDict = new Dictionary<string, IntegerVector>(); 49 intDict.Add(enc.Name, (IntegerVector)scope.Variables[enc.Name].Value); 50 continue; 51 } 52 var realConfig = enc as RealEncoding; 53 if (realConfig != null) { 54 if (realDict == null) realDict = new Dictionary<string, RealVector>(); 55 realDict.Add(enc.Name, (RealVector)scope.Variables[enc.Name].Value); 56 continue; 57 } 58 var permConfig = enc as PermutationEncoding; 59 if (permConfig != null) { 60 if (permDict == null) permDict = new Dictionary<string, Permutation>(); 61 permDict.Add(enc.Name, (Permutation)scope.Variables[enc.Name].Value); 62 continue; 63 } 64 throw new InvalidOperationException("Encoding for variable " + enc.Name + " not recognized."); 42 65 } 43 var intConfig = param.Value as IntegerParameterConfiguration; 44 if (intConfig != null) { 45 intDict.Add(param.Key, (IntegerVector)scope.Variables[param.Key].Value); 46 continue; 47 } 48 var realConfig = param.Value as RealParameterConfiguration; 49 if (realConfig != null) { 50 realDict.Add(param.Key, (RealVector)scope.Variables[param.Key].Value); 51 continue; 52 } 53 var permConfig = param.Value as PermutationParameterConfiguration; 54 if (permConfig != null) { 55 permDict.Add(param.Key, (Permutation)scope.Variables[param.Key].Value); 56 continue; 57 } 58 throw new InvalidOperationException("Parameter " + param.Key + " not found."); 66 } else { 67 var binaryEncoding = encoding as BinaryEncoding; 68 var handled = binaryEncoding != null; 69 if (binaryEncoding != null) binDict = new Dictionary<string, BinaryVector>(capacity: 1) { 70 {binaryEncoding.Name, (BinaryVector)scope.Variables[binaryEncoding.Name].Value} 71 }; 72 var integerEncoding = encoding as IntegerEncoding; 73 handled = handled || integerEncoding != null; 74 if (integerEncoding != null) intDict = new Dictionary<string, IntegerVector>(capacity: 1) { 75 {integerEncoding.Name, (IntegerVector)scope.Variables[integerEncoding.Name].Value} 76 }; 77 var realEncoding = encoding as RealEncoding; 78 handled = handled || realEncoding != null; 79 if (realEncoding != null) realDict = new Dictionary<string, RealVector>(capacity: 1) { 80 {realEncoding.Name, (RealVector)scope.Variables[realEncoding.Name].Value} 81 }; 82 var permEncoding = encoding as PermutationEncoding; 83 handled = handled || permEncoding != null; 84 if (permEncoding != null) permDict = new Dictionary<string, Permutation>(capacity: 1) { 85 {permEncoding.ItemName, (Permutation)scope.Variables[permEncoding.ItemName].Value} 86 }; 87 if (!handled) throw new InvalidOperationException("Encoding for variable " + encoding.Name + " not recognized."); 59 88 } 60 return new ParameterVector( 61 binaryVectors: binDict.Count > 0 ? binDict : null, 62 integerVectors: intDict.Count > 0 ? intDict : null, 63 realVectors: realDict.Count > 0 ? realDict : null, 64 permutations: permDict.Count > 0 ? permDict : null); 89 return new Individual(binDict, intDict, realDict, permDict); 65 90 } 66 91 67 internal static void Write(IScope scope, ParameterVectorvector) {92 internal static void Write(IScope scope, Individual vector) { 68 93 foreach (var param in vector.BinaryNames) { 69 94 if (scope.Variables.ContainsKey(param))
Note: See TracChangeset
for help on using the changeset viewer.