Changeset 11587 for branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiEncodingCreator.cs
- Timestamp:
- 11/26/14 13:24:20 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiEncodingCreator.cs
r11484 r11587 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 using HeuristicLab.Operators;26 26 using HeuristicLab.Optimization; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.Programmable.Operators; 28 29 29 30 namespace HeuristicLab.Problems.Programmable { 30 [Item("MultiEncodingCreator", "Contains solution creators that together create a multi encoding.")]31 [Item("MultiEncodingCreator", "Contains solution creators that together create a multi-encoding.")] 31 32 [StorableClass] 32 public class MultiEncodingCreator : MultiOperator<ISolutionCreator>, ISolutionCreator { 33 public sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator { 34 [StorableConstructor] 35 private MultiEncodingCreator(bool deserializing) : base(deserializing) { } 33 36 34 [StorableConstructor] 35 protected MultiEncodingCreator(bool deserializing) : base(deserializing) { } 36 protected MultiEncodingCreator(MultiEncodingCreator original, Cloner cloner) : base(original, cloner) { } 37 private MultiEncodingCreator(MultiEncodingCreator original, Cloner cloner) : base(original, cloner) { } 37 38 public MultiEncodingCreator() { } 38 39 … … 41 42 } 42 43 43 public override IOperation InstrumentedApply() { 44 var baseOperations = base.InstrumentedApply(); 45 return new OperationCollection(new[] { baseOperations }.Concat(Operators.Select(x => ExecutionContext.CreateOperation(x)))); 44 public override void AddEncoding(IEncoding encoding) { 45 base.AddEncoding(encoding); 46 var parameter = GetParameter(encoding); 47 parameter.Value = encoding.SolutionCreator; 48 encoding.SolutionCreatorChanged += Encoding_SolutionCreatorChanged; 49 } 50 51 public override bool RemoveEncoding(IEncoding encoding) { 52 var success = base.RemoveEncoding(encoding); 53 encoding.SolutionCreatorChanged -= Encoding_SolutionCreatorChanged; 54 return success; 55 } 56 57 private void Encoding_SolutionCreatorChanged(object sender, EventArgs e) { 58 var encoding = (IEncoding)sender; 59 var parameter = GetParameter(encoding); 60 61 var oldCreator = parameter.ValidValues.Single(creator => creator.GetType() == encoding.SolutionCreator.GetType()); 62 parameter.ValidValues.Remove(oldCreator); 63 parameter.ValidValues.Add(encoding.SolutionCreator); 64 parameter.Value = encoding.SolutionCreator; 46 65 } 47 66 }
Note: See TracChangeset
for help on using the changeset viewer.