- Timestamp:
- 06/21/12 18:02:33 (13 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators
- Property svn:ignore
-
old new 20 20 bin 21 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/GP-MoveOperators/HeuristicLab.Optimization/3.3/Problems/Problem.cs
r7706 r8085 34 34 [StorableClass] 35 35 public abstract class Problem : ParameterizedNamedItem, IProblem { 36 private static readonly string OperatorsParameterName = "Operators"; 37 38 public IFixedValueParameter<OperatorCollection> OperatorsParameter { 39 get { return (IFixedValueParameter<OperatorCollection>)Parameters[OperatorsParameterName]; } 36 private const string OperatorsParameterName = "Operators"; 37 public IFixedValueParameter<ItemCollection<IItem>> OperatorsParameter { 38 get { return (IFixedValueParameter<ItemCollection<IItem>>)Parameters[OperatorsParameterName]; } 40 39 } 41 40 … … 53 52 protected Problem() 54 53 : base() { 55 Parameters.Add(new FixedValueParameter< OperatorCollection>(OperatorsParameterName, "The operators that the problem provides to the algorithms.", new OperatorCollection(), false));54 Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false)); 56 55 OperatorsParameter.Hidden = true; 57 56 RegisterEventHandlers(); … … 60 59 [StorableHook(HookType.AfterDeserialization)] 61 60 private void AfterDeserialization() { 61 // BackwardsCompatibility3.3 62 #region Backwards compatible code, remove with 3.4 63 IParameter operatorsParam; 64 if (Parameters.TryGetValue(OperatorsParameterName, out operatorsParam)) { 65 var operators = operatorsParam.ActualValue as OperatorCollection; 66 if (operators != null) { 67 Parameters.Remove(OperatorsParameterName); 68 Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(operators), false)); 69 OperatorsParameter.Hidden = true; 70 } 71 } 72 #endregion 73 62 74 RegisterEventHandlers(); 63 75 } 64 76 65 77 private void RegisterEventHandlers() { 66 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<I Operator>(Operators_Changed);67 Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<I Operator>(Operators_Changed);68 Operators.CollectionReset += new CollectionItemsChangedEventHandler<I Operator>(Operators_Changed);78 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IItem>(Operators_Changed); 79 Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IItem>(Operators_Changed); 80 Operators.CollectionReset += new CollectionItemsChangedEventHandler<IItem>(Operators_Changed); 69 81 } 70 82 … … 72 84 // BackwardsCompatibility3.3 73 85 #region Backwards compatible code, remove with 3.4 74 [Storable(Name = "Operators" )]86 [Storable(Name = "Operators", AllowOneWay = true)] 75 87 private IEnumerable<IOperator> StorableOperators { 76 get { return null; }77 88 set { 89 IParameter operatorsParam; 90 if (Parameters.TryGetValue(OperatorsParameterName, out operatorsParam)) { 91 var items = operatorsParam.ActualValue as ItemCollection<IItem>; 92 if (items == null) Parameters.Remove(operatorsParam); 93 } 94 95 //necessary to convert old experiments files where no parameter was used for saving the operators 78 96 if (!Parameters.ContainsKey(OperatorsParameterName)) { 79 Parameters.Add(new FixedValueParameter< OperatorCollection>(OperatorsParameterName, "The operators that the problem provides to the algorithms.", new OperatorCollection(value), false));97 Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false)); 80 98 OperatorsParameter.Hidden = true; 81 99 } 100 if (value != null) Operators.AddRange(value); 82 101 } 83 102 } 84 103 #endregion 85 protected OperatorCollectionOperators {104 protected ItemCollection<IItem> Operators { 86 105 get { 87 106 // BackwardsCompatibility3.3 88 107 #region Backwards compatible code, remove with 3.4 89 108 if (!Parameters.ContainsKey(OperatorsParameterName)) { 90 Parameters.Add(new FixedValueParameter< OperatorCollection>(OperatorsParameterName, "The operators that the problem provides to the algorithms.", new OperatorCollection(), false));109 Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false)); 91 110 OperatorsParameter.Hidden = true; 92 111 } … … 95 114 } 96 115 } 97 IEnumerable<I Operator> IProblem.Operators { get { return Operators; } }116 IEnumerable<IItem> IProblem.Operators { get { return Operators; } } 98 117 #endregion 99 118 -
branches/GP-MoveOperators/HeuristicLab.Optimization/3.3/Problems/UserDefinedProblem.cs
r7351 r8085 81 81 get { return (OptionalValueParameter<IScope>)Parameters["BestKnownSolution"]; } 82 82 } 83 public ValueParameter<ItemList<I Operator>> OperatorsParameter {84 get { return (ValueParameter<ItemList<I Operator>>)Parameters["Operators"]; }83 public ValueParameter<ItemList<IItem>> OperatorsParameter { 84 get { return (ValueParameter<ItemList<IItem>>)Parameters["Operators"]; } 85 85 } 86 86 #endregion … … 112 112 set { BestKnownQualityParameter.Value = value; } 113 113 } 114 public IEnumerable<I Operator> Operators {114 public IEnumerable<IItem> Operators { 115 115 get { return OperatorsParameter.Value; } 116 116 } … … 121 121 [StorableHook(HookType.AfterDeserialization)] 122 122 private void AfterDeserialization() { 123 // BackwardsCompatibility3.3 124 #region Backwards compatible code, remove with 3.4 125 if (Parameters.ContainsKey("Operators") && Parameters["Operators"] is ValueParameter<ItemList<IOperator>>) { 126 ItemList<IOperator> tmp = ((ValueParameter<ItemList<IOperator>>)Parameters["Operators"]).Value; 127 Parameters.Remove("Operators"); 128 Parameters.Add(new ValueParameter<ItemList<IItem>>("Operators", "The operators and items that the problem provides to the algorithms.", new ItemList<IItem>(tmp), false)); 129 } 130 #endregion 131 123 132 RegisterEventHandlers(); 124 133 } … … 130 139 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.")); 131 140 Parameters.Add(new OptionalValueParameter<IScope>("BestKnownSolution", "The best known solution for this external evaluation problem.")); 132 Parameters.Add(new ValueParameter<ItemList<I Operator>>("Operators", "The operators that are passed to the algorithm.", new ItemList<IOperator>()));141 Parameters.Add(new ValueParameter<ItemList<IItem>>("Operators", "The operators and items that the problem provides to the algorithms.", new ItemList<IItem>())); 133 142 134 143 RegisterEventHandlers(); … … 200 209 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 201 210 OperatorsParameter.ValueChanged += new EventHandler(OperatorsParameter_ValueChanged); 202 OperatorsParameter.Value.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<I Operator>>(OperatorsParameter_Value_ItemsAdded);203 OperatorsParameter.Value.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<I Operator>>(OperatorsParameter_Value_ItemsRemoved);204 OperatorsParameter.Value.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<I Operator>>(OperatorsParameter_Value_CollectionReset);211 OperatorsParameter.Value.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IItem>>(OperatorsParameter_Value_ItemsAdded); 212 OperatorsParameter.Value.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IItem>>(OperatorsParameter_Value_ItemsRemoved); 213 OperatorsParameter.Value.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<IItem>>(OperatorsParameter_Value_CollectionReset); 205 214 } 206 215 … … 209 218 if (Evaluator != null) { 210 219 string qualityName = Evaluator.QualityParameter.ActualName; 211 foreach (IOperator op in OperatorsParameter.Value ) {220 foreach (IOperator op in OperatorsParameter.Value.OfType<IOperator>()) { 212 221 foreach (ILookupParameter<DoubleValue> param in op.Parameters.OfType<ILookupParameter<DoubleValue>>()) { 213 222 if (param.Name.Equals("Quality")) param.ActualName = qualityName;
Note: See TracChangeset
for help on using the changeset viewer.