Changeset 13365 for branches/ProblemRefactoring/HeuristicLab.Optimization
- Timestamp:
- 11/24/15 16:43:32 (9 years ago)
- Location:
- branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/MultiEncoding.cs
r13359 r13365 84 84 } 85 85 86 public void Clear() { 87 foreach (var enc in encodings.ToList()) Remove(enc); 88 } 89 86 90 public override void ConfigureOperators(IEnumerable<IOperator> operators) { 87 91 foreach (var encOp in operators.OfType<IMultiEncodingOperator>()) -
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs
r13339 r13365 41 41 } 42 42 43 //mkommend necessary for reuse of operators if the encoding changes 44 private TEncoding oldEncoding; 45 43 46 public TEncoding Encoding { 44 47 get { return EncodingParameter.Value; } … … 64 67 Parameters.Add(new ValueParameter<TEncoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any.")); 65 68 if (Encoding != null) { 69 oldEncoding = Encoding; 66 70 SolutionCreator = Encoding.SolutionCreator; 67 71 Parameterize(); … … 72 76 protected Problem(Problem<TEncoding, TSolution, TEvaluator> original, Cloner cloner) 73 77 : base(original, cloner) { 78 oldEncoding = cloner.Clone(original.oldEncoding); 74 79 RegisterEvents(); 75 80 } … … 79 84 [StorableHook(HookType.AfterDeserialization)] 80 85 private void AfterDeserialization() { 86 oldEncoding = Encoding; 81 87 RegisterEvents(); 82 88 } … … 96 102 97 103 private void Parameterize() { 104 if (oldEncoding != null) { 105 AdaptEncodingOperators(oldEncoding, Encoding); 106 //var oldMultiEncoding = oldEncoding as MultiEncoding; 107 //if (oldMultiEncoding != null) 108 // oldMultiEncoding.EncodingsChanged -= MultiEncodingOnEncodingsChanged; 109 } 110 oldEncoding = Encoding; 111 98 112 foreach (var op in Operators.OfType<IEncodingOperator<TSolution>>()) 99 113 op.EncodingParameter.ActualName = EncodingParameter.Name; 114 115 SolutionCreator = Encoding.SolutionCreator; 100 116 101 117 //var multiEncoding = Encoding as MultiEncoding; … … 108 124 } 109 125 110 protected virtual void MultiEncodingOnEncodingsChanged(object sender, EventArgs e) { 111 OnOperatorsChanged(); 126 private static void AdaptEncodingOperators(IEncoding oldEncoding, IEncoding newEncoding) { 127 if (oldEncoding.GetType() != newEncoding.GetType()) return; 128 129 if (oldEncoding.GetType() == typeof(MultiEncoding)) { 130 var oldMultiEncoding = (MultiEncoding)oldEncoding; 131 var newMultiEncoding = (MultiEncoding)newEncoding; 132 if (!oldMultiEncoding.Encodings.SequenceEqual(newMultiEncoding.Encodings, new TypeEqualityComparer<IEncoding>())) return; 133 134 var nestedEncodings = oldMultiEncoding.Encodings.Zip(newMultiEncoding.Encodings, (o, n) => new { oldEnc = o, newEnc = n }); 135 foreach (var multi in nestedEncodings) 136 AdaptEncodingOperators(multi.oldEnc, multi.newEnc); 137 } 138 139 var comparer = new TypeEqualityComparer<IOperator>(); 140 var cloner = new Cloner(); 141 var oldOperators = oldEncoding.Operators; 142 var newOperators = newEncoding.Operators; 143 144 cloner.RegisterClonedObject(oldEncoding, newEncoding); 145 var operators = oldOperators.Intersect(newOperators, comparer) 146 .Select(cloner.Clone) 147 .Union(newOperators, comparer).ToList(); 148 149 newEncoding.ConfigureOperators(operators); 150 newEncoding.Operators = operators; 112 151 } 113 152 }
Note: See TracChangeset
for help on using the changeset viewer.