Changeset 3591 for trunk/sources
- Timestamp:
- 05/03/10 14:30:55 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators.Views/3.3/CheckedMultiOperatorView.Designer.cs
r3588 r3591 21 21 22 22 namespace HeuristicLab.Operators.Views { 23 partial class MultiOperatorView<T> {23 partial class CheckedMultiOperatorView<T> { 24 24 /// <summary> 25 25 /// Required designer variable. -
trunk/sources/HeuristicLab.Operators.Views/3.3/CheckedMultiOperatorView.cs
r3588 r3591 27 27 28 28 namespace HeuristicLab.Operators.Views { 29 /// <summary> 30 /// The base class for visual representations of items. 31 /// </summary> 32 [View("MultiOperator View")] 33 [Content(typeof(MultiOperator<>), true)] 34 public partial class MultiOperatorView<T> : NamedItemView where T : class, IOperator { 35 public new MultiOperator<T> Content { 36 get { return (MultiOperator<T>)base.Content; } 29 [View("CheckedMultiOperator View")] 30 [Content(typeof(CheckedMultiOperator<>), true)] 31 public partial class CheckedMultiOperatorView<T> : NamedItemView where T : class, IOperator { 32 public new CheckedMultiOperator<T> Content { 33 get { return (CheckedMultiOperator<T>)base.Content; } 37 34 set { base.Content = value; } 38 35 } 39 36 40 37 /// <summary> 41 /// Initializes a new instance of <see cref=" ItemBaseView"/>.38 /// Initializes a new instance of <see cref="CheckedMultiOperatorView"/>. 42 39 /// </summary> 43 public MultiOperatorView() {40 public CheckedMultiOperatorView() { 44 41 InitializeComponent(); 45 42 } 46 43 47 44 /// <summary> 48 /// Removes the eventhandlers from the underlying <see cref=" IOperatorGraph"/>.45 /// Removes the eventhandlers from the underlying <see cref="CheckedMultiOperator"/>. 49 46 /// </summary> 50 /// <remarks>Calls <see cref=" ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>47 /// <remarks>Calls <see cref="NamedItemView.DeregisterContentEvents"/> of base class <see cref="NamedItemView"/>.</remarks> 51 48 protected override void DeregisterContentEvents() { 52 49 Content.BreakpointChanged -= new EventHandler(Content_BreakpointChanged); … … 55 52 56 53 /// <summary> 57 /// Adds eventhandlers to the underlying <see cref=" IOperatorGraph"/>.54 /// Adds eventhandlers to the underlying <see cref="CheckedMultiOperator"/>. 58 55 /// </summary> 59 /// <remarks>Calls <see cref=" ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>56 /// <remarks>Calls <see cref="NamedItemView.RegisterContentEvents"/> of base class <see cref="NamedItemView"/>.</remarks> 60 57 protected override void RegisterContentEvents() { 61 58 base.RegisterContentEvents(); -
trunk/sources/HeuristicLab.Operators.Views/3.3/HeuristicLab.Operators.Views-3.3.csproj
r3437 r3591 92 92 </Compile> 93 93 <None Include="HeuristicLabOperatorsViewsPlugin.cs.frame" /> 94 <Compile Include="CheckedMultiOperatorView.cs"> 95 <SubType>UserControl</SubType> 96 </Compile> 97 <Compile Include="CheckedMultiOperatorView.Designer.cs"> 98 <DependentUpon>CheckedMultiOperatorView.cs</DependentUpon> 99 </Compile> 94 100 <Compile Include="MultiOperatorView.cs"> 95 101 <SubType>UserControl</SubType> -
trunk/sources/HeuristicLab.Operators.Views/3.3/MultiOperatorView.Designer.cs
r3568 r3591 47 47 this.tabControl = new System.Windows.Forms.TabControl(); 48 48 this.operatorsTabPage = new System.Windows.Forms.TabPage(); 49 this.operatorListView = new HeuristicLab.Core.Views. CheckedItemListView<T>();49 this.operatorListView = new HeuristicLab.Core.Views.ItemListView<T>(); 50 50 this.parametersTabPage = new System.Windows.Forms.TabPage(); 51 51 this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView(); … … 178 178 protected System.Windows.Forms.TabPage parametersTabPage; 179 179 protected HeuristicLab.Core.Views.ParameterCollectionView parameterCollectionView; 180 protected HeuristicLab.Core.Views. CheckedItemListView<T> operatorListView;180 protected HeuristicLab.Core.Views.ItemListView<T> operatorListView; 181 181 protected System.Windows.Forms.CheckBox breakpointCheckBox; 182 182 protected System.Windows.Forms.Label breakpointLabel; -
trunk/sources/HeuristicLab.Operators/3.3/CheckedMultiOperator.cs
r3588 r3591 31 31 namespace HeuristicLab.Operators { 32 32 /// <summary> 33 /// A base class for operators which apply arbitrary many other operators of a specific type .33 /// A base class for operators which apply arbitrary many other operators of a specific type, operators can be checked/unchecked. 34 34 /// </summary> 35 [Item(" MultiOperator<T>", "A base class for operators which apply arbitrary many other operators of a specific type.")]35 [Item("CheckedMultiOperator<T>", "A base class for operators which apply arbitrary many other operators of a specific type.")] 36 36 [StorableClass] 37 public abstract class MultiOperator<T> : SingleSuccessorOperatorwhere T : class, IOperator {38 private List<IValueParameter<T>> operatorParameters;39 40 [Storable]41 p rivate CheckedItemList<T> operators;42 public CheckedItemList<T> Operators {43 get { return operators; }37 public abstract class CheckedMultiOperator<T> : MultiOperator<T> where T : class, IOperator { 38 /// <summary> 39 /// Gets the operators of the checked multi operator 40 /// </summary> 41 public new ICheckedItemList<T> Operators { 42 get { return (ICheckedItemList<T>)base.Operators; } 43 protected set { base.Operators = value; } 44 44 } 45 46 public MultiOperator() 45 /// <summary> 46 /// Creates a new instance of CheckedMultiOperator 47 /// </summary> 48 public CheckedMultiOperator() 47 49 : base() { 48 operators = new CheckedItemList<T>(); 49 Initialize(); 50 Operators = new CheckedItemList<T>(); 50 51 } 51 52 [StorableConstructor] 52 protected MultiOperator(bool deserializing) : base(deserializing) { } 53 54 [StorableHook(HookType.AfterDeserialization)] 55 private void Initialize() { 56 if (operators != null) RegisterOperatorsEvents(); 57 operatorParameters = new List<IValueParameter<T>>(); 58 for (int i = 0; i < Operators.Count; i++) { 59 IValueParameter<T> opParam = (IValueParameter<T>)Parameters[i.ToString()]; 60 operatorParameters.Add(opParam); 61 opParam.ValueChanged += new EventHandler(opParam_ValueChanged); 62 } 63 } 64 65 public override IDeepCloneable Clone(Cloner cloner) { 66 MultiOperator<T> clone = (MultiOperator<T>)base.Clone(cloner); 67 clone.operators = (CheckedItemList<T>)cloner.Clone(operators); 68 clone.Initialize(); 69 return clone; 70 } 71 72 private void UpdateOperatorParameters() { 73 foreach (IValueParameter<T> opParam in operatorParameters) { 74 opParam.ValueChanged -= new EventHandler(opParam_ValueChanged); 75 Parameters.Remove(opParam.Name); 76 } 77 operatorParameters.Clear(); 78 for (int i = 0; i < Operators.Count; i++) { 79 IValueParameter<T> opParam = new ValueParameter<T>(i.ToString(), string.Empty, Operators[i]); 80 opParam.ValueChanged += new EventHandler(opParam_ValueChanged); 81 Parameters.Add(opParam); 82 operatorParameters.Add(opParam); 83 } 84 } 85 86 #region Events 87 private void RegisterOperatorsEvents() { 88 operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsAdded); 89 operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsRemoved); 90 operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsReplaced); 91 operators.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsMoved); 92 operators.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_CollectionReset); 93 } 94 private void DeregisterOperatorsEvents() { 95 operators.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsAdded); 96 operators.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsRemoved); 97 operators.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsReplaced); 98 operators.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsMoved); 99 operators.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_CollectionReset); 100 } 101 protected virtual void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 102 UpdateOperatorParameters(); 103 } 104 protected virtual void Operators_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 105 UpdateOperatorParameters(); 106 } 107 protected virtual void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 108 foreach (IndexedItem<T> item in e.Items) 109 operatorParameters[item.Index].Value = item.Value; 110 } 111 protected virtual void Operators_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 112 foreach (IndexedItem<T> item in e.Items) 113 operatorParameters[item.Index].Value = item.Value; 114 } 115 protected virtual void Operators_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 116 UpdateOperatorParameters(); 117 } 118 private void opParam_ValueChanged(object sender, EventArgs e) { 119 IValueParameter<T> opParam = (IValueParameter<T>)sender; 120 operators[operatorParameters.IndexOf(opParam)] = opParam.Value; 121 } 122 #endregion 53 protected CheckedMultiOperator(bool deserializing) : base(deserializing) { } 123 54 } 124 55 } -
trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj
r3425 r3591 85 85 </ItemGroup> 86 86 <ItemGroup> 87 <Compile Include="CheckedMultiOperator.cs" /> 87 88 <Compile Include="CombinedOperator.cs" /> 88 89 <None Include="HeuristicLabOperatorsPlugin.cs.frame" /> -
trunk/sources/HeuristicLab.Operators/3.3/MultiOperator.cs
r3568 r3591 39 39 40 40 [Storable] 41 private CheckedItemList<T> operators;42 public CheckedItemList<T> Operators {41 private IItemList<T> operators; 42 public IItemList<T> Operators { 43 43 get { return operators; } 44 protected set { 45 if (operators != value) { 46 if (value == null) throw new ArgumentException(); 47 DeregisterOperatorsEvents(); 48 operators = value; 49 RegisterOperatorsEvents(); 50 } 51 } 44 52 } 45 53 46 54 public MultiOperator() 47 55 : base() { 48 operators = new CheckedItemList<T>();56 this.operators = new ItemList<T>(); 49 57 Initialize(); 50 58 } 59 51 60 [StorableConstructor] 52 61 protected MultiOperator(bool deserializing) : base(deserializing) { } … … 65 74 public override IDeepCloneable Clone(Cloner cloner) { 66 75 MultiOperator<T> clone = (MultiOperator<T>)base.Clone(cloner); 67 clone.operators = ( CheckedItemList<T>)cloner.Clone(operators);76 clone.operators = (IItemList<T>)cloner.Clone(operators); 68 77 clone.Initialize(); 69 78 return clone; -
trunk/sources/HeuristicLab.Operators/3.3/StochasticMultiOperator.cs
r3568 r3591 36 36 [Item("StochasticMultiOperator<T>", "Base class for stochastic multi operators.")] 37 37 [StorableClass] 38 public abstract class StochasticMultiOperator<T> : MultiOperator<T> where T : class, IOperator {38 public abstract class StochasticMultiOperator<T> : CheckedMultiOperator<T> where T : class, IOperator { 39 39 /// <summary> 40 40 /// Should return true if the StochasticMultiOperator should create a new child operation with the selected successor … … 122 122 throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators"); 123 123 } 124 IOperator successor = null; 124 125 var checkedOperators = Operators.CheckedItems; 125 if (checkedOperators.Count() == 0) { 126 throw new InvalidOperationException(Name + ": At least one operator must be checked."); 127 } 128 double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum(); 129 if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability."); 130 double r = random.NextDouble() * sum; 131 sum = 0; 132 IOperator successor = null; 133 foreach (var indexedItem in checkedOperators) { 134 sum += probabilities[indexedItem.Index]; 135 if (sum > r) { 136 successor = indexedItem.Value; 137 break; 126 if (checkedOperators.Count() > 0) { 127 // select a random operator from the checked operators 128 double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum(); 129 if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability."); 130 double r = random.NextDouble() * sum; 131 sum = 0; 132 foreach (var indexedItem in checkedOperators) { 133 sum += probabilities[indexedItem.Index]; 134 if (sum > r) { 135 successor = indexedItem.Value; 136 break; 137 } 138 138 } 139 139 }
Note: See TracChangeset
for help on using the changeset viewer.