Changeset 13365 for branches/ProblemRefactoring
- Timestamp:
- 11/24/15 16:43:32 (9 years ago)
- Location:
- branches/ProblemRefactoring
- Files:
-
- 4 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 } -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs
r13350 r13365 71 71 : base() { 72 72 Parameters.Add(new FixedValueParameter<MultiObjectiveProblemDefinitionScript<TEncoding, TSolution>>("ProblemScript", "Defines the problem.", 73 new MultiObjectiveProblemDefinitionScript<TEncoding, TSolution>() { Name = Name, Encoding = Encoding })); 73 new MultiObjectiveProblemDefinitionScript<TEncoding, TSolution>() { Name = Name })); 74 ProblemScript.Encoding = Encoding = (TEncoding)Encoding.Clone(); 74 75 RegisterEvents(); 75 76 } … … 87 88 Parameters.Remove("Maximization"); 88 89 Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()) { Hidden = true }); 90 var multiEnc = ProblemScript.Encoding as MultiEncoding; 91 if (multiEnc != null) multiEnc.Clear(); 92 ProblemScript.Initialize(); 93 Encoding = (TEncoding)ProblemScript.Encoding.Clone(); 89 94 90 ProblemScript.Initialize();91 95 OnOperatorsChanged(); 92 96 OnReset(); -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r13350 r13365 73 73 : base() { 74 74 Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>>("ProblemScript", "Defines the problem.", 75 new SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>() { Name = Name, Encoding = Encoding })); 75 new SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>() { Name = Name })); 76 ProblemScript.Encoding = Encoding = (TEncoding)Encoding.Clone(); 76 77 Operators.Add(new BestScopeSolutionAnalyzer()); 77 78 RegisterEvents(); … … 90 91 Parameters.Remove("Maximization"); 91 92 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true }); 93 var multiEnc = ProblemScript.Encoding as MultiEncoding; 94 if (multiEnc != null) multiEnc.Clear(); 92 95 ProblemScript.Initialize(); 96 Encoding = (TEncoding)ProblemScript.Encoding.Clone(); 93 97 94 98 OnOperatorsChanged();
Note: See TracChangeset
for help on using the changeset viewer.