Changeset 3280
- Timestamp:
- 04/07/10 05:22:33 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs
r3275 r3280 168 168 geneticAlgorithmMainLoop.ResultsParameter.ActualName = "Results"; 169 169 170 Initial ze();170 Initialize(); 171 171 } 172 172 [StorableConstructor] 173 private GeneticAlgorithm(bool deserializing) : base( ) { }173 private GeneticAlgorithm(bool deserializing) : base(deserializing) { } 174 174 175 175 public override IDeepCloneable Clone(Cloner cloner) { 176 176 GeneticAlgorithm clone = (GeneticAlgorithm)base.Clone(cloner); 177 clone.Initial ze();177 clone.Initialize(); 178 178 return clone; 179 179 } … … 249 249 #region Helpers 250 250 [StorableHook(HookType.AfterDeserialization)] 251 private void Initial ze() {251 private void Initialize() { 252 252 InitializeSelectors(); 253 253 UpdateSelectors(); -
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs
r3275 r3280 33 33 34 34 namespace HeuristicLab.Algorithms.LocalSearch { 35 [Item("Local Search", "A local search algorithm.")]35 [Item("Local Search", "A local search algorithm.")] 36 36 [Creatable("Algorithms")] 37 37 [StorableClass] … … 111 111 #endregion 112 112 113 [StorableConstructor]114 private LocalSearch(bool deserializing) : base() { }115 113 public LocalSearch() 116 114 : base() { … … 147 145 Initialize(); 148 146 } 147 [StorableConstructor] 148 private LocalSearch(bool deserializing) : base(deserializing) { } 149 149 150 150 public override IDeepCloneable Clone(Cloner cloner) { -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs
r3275 r3280 133 133 #endregion 134 134 135 [StorableConstructor]136 private SimulatedAnnealing(bool deserializing) : base() { }137 135 public SimulatedAnnealing() 138 136 : base() { … … 175 173 Initialize(); 176 174 } 175 [StorableConstructor] 176 private SimulatedAnnealing(bool deserializing) : base(deserializing) { } 177 177 178 178 public override IDeepCloneable Clone(Cloner cloner) { -
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs
r3275 r3280 33 33 34 34 namespace HeuristicLab.Algorithms.TabuSearch { 35 [Item("Tabu Search", "A tabu search algorithm.")]35 [Item("Tabu Search", "A tabu search algorithm.")] 36 36 [Creatable("Algorithms")] 37 37 [StorableClass] … … 128 128 #endregion 129 129 130 [StorableConstructor]131 private TabuSearch(bool deserializing) : base() { }132 130 public TabuSearch() 133 131 : base() { … … 169 167 Initialize(); 170 168 } 169 [StorableConstructor] 170 private TabuSearch(bool deserializing) : base(deserializing) { } 171 171 172 172 public override IDeepCloneable Clone(Cloner cloner) { -
trunk/sources/HeuristicLab.Core/3.3/DeepCloneable.cs
r3017 r3280 29 29 [StorableClass] 30 30 public abstract class DeepCloneable : IDeepCloneable { 31 protected DeepCloneable() { } 32 [StorableConstructor] 33 protected DeepCloneable(bool deserializing) { } 34 31 35 /// <summary> 32 36 /// Creates a deep clone of this instance. -
trunk/sources/HeuristicLab.Core/3.3/Engine.cs
r3265 r3280 49 49 50 50 public override IDeepCloneable Clone(Cloner cloner) { 51 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 51 52 Engine clone = (Engine)base.Clone(cloner); 52 53 IOperation[] contexts = executionStack.ToArray(); -
trunk/sources/HeuristicLab.Core/3.3/Item.cs
r3017 r3280 42 42 } 43 43 44 protected Item() : base() { } 45 [StorableConstructor] 46 protected Item(bool deserializing) : base(deserializing) { } 47 48 44 49 /// <summary> 45 50 /// Gets the string representation of the current instance. -
trunk/sources/HeuristicLab.Core/3.3/NamedItem.cs
r3017 r3280 91 91 else this.description = description; 92 92 } 93 [StorableConstructor] 94 protected NamedItem(bool deserializing) : base(deserializing) { } 93 95 94 96 /// <summary> -
trunk/sources/HeuristicLab.Core/3.3/ParameterizedNamedItem.cs
r3260 r3280 32 32 [StorableClass] 33 33 public abstract class ParameterizedNamedItem : NamedItem, IParameterizedNamedItem { 34 [Storable] 34 35 private ParameterCollection parameters; 35 [Storable]36 36 protected ParameterCollection Parameters { 37 37 get { return parameters; } 38 private set {39 parameters = value;40 readOnlyParameters = null;41 }42 38 } 43 39 private ReadOnlyObservableKeyedCollection<string, IParameter> readOnlyParameters; … … 53 49 name = ItemName; 54 50 description = ItemDescription; 55 Parameters = new ParameterCollection();51 parameters = new ParameterCollection(); 56 52 readOnlyParameters = null; 57 53 } … … 59 55 : base(name) { 60 56 description = ItemDescription; 61 Parameters = new ParameterCollection();57 parameters = new ParameterCollection(); 62 58 readOnlyParameters = null; 63 59 } … … 65 61 : base(name) { 66 62 description = ItemDescription; 67 Parameters = parameters;63 this.parameters = parameters; 68 64 readOnlyParameters = null; 69 65 } 70 66 protected ParameterizedNamedItem(string name, string description) 71 67 : base(name, description) { 72 Parameters = new ParameterCollection();68 parameters = new ParameterCollection(); 73 69 readOnlyParameters = null; 74 70 } 75 71 protected ParameterizedNamedItem(string name, string description, ParameterCollection parameters) 76 72 : base(name, description) { 77 Parameters = parameters;73 this.parameters = parameters; 78 74 readOnlyParameters = null; 79 75 } 76 [StorableConstructor] 77 protected ParameterizedNamedItem(bool deserializing) : base(deserializing) { } 80 78 81 79 public override IDeepCloneable Clone(Cloner cloner) { 82 80 ParameterizedNamedItem clone = (ParameterizedNamedItem)base.Clone(cloner); 83 clone.Parameters = (ParameterCollection)cloner.Clone(parameters); 81 clone.parameters = (ParameterCollection)cloner.Clone(parameters); 82 clone.readOnlyParameters = null; 84 83 return clone; 85 84 } … … 87 86 public virtual void CollectParameterValues(IDictionary<string, IItem> values) { 88 87 foreach (IValueParameter param in parameters.OfType<IValueParameter>()) { 89 values.Add(param.Name, param.Value != null ? (IItem)param.Value.Clone() : null);88 values.Add(param.Name, param.Value); 90 89 if (param.Value is IParameterizedItem) { 91 90 Dictionary<string, IItem> children = new Dictionary<string, IItem>(); -
trunk/sources/HeuristicLab.Core/3.3/Scope.cs
r3160 r3280 35 35 get { return parent; } 36 36 set { 37 if (parent != null) parent.SubScopes.Remove(this); 38 parent = value; 39 if ((parent != null) && !parent.SubScopes.Contains(this)) parent.SubScopes.Add(this); 37 if (parent != value) { 38 IScope oldParent = parent; 39 parent = null; 40 if (oldParent != null) oldParent.SubScopes.Remove(this); 41 parent = value; 42 if ((parent != null) && !parent.SubScopes.Contains(this)) parent.SubScopes.Add(this); 43 } 40 44 } 41 45 } … … 97 101 clone.Description = Description; 98 102 if (variables.Count > 0) clone.variables = (VariableCollection)cloner.Clone(variables); 99 if (subScopes.Count > 0) clone.SubScopes = (ScopeList)cloner.Clone(subScopes); 103 if (subScopes.Count > 0) { 104 clone.SubScopes = (ScopeList)cloner.Clone(subScopes); 105 foreach (IScope child in clone.SubScopes) 106 child.Parent = clone; 107 } 100 108 return clone; 101 109 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.Designer.cs
r3277 r3280 38 38 if (disposing) { 39 39 foreach (ListViewItem item in itemsListView.Items) 40 (( Run)item.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);40 ((IRun)item.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged); 41 41 if (components != null) components.Dispose(); 42 42 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs
r3277 r3280 31 31 [View("RunCollection View")] 32 32 [Content(typeof(RunCollection), true)] 33 [Content(typeof(IObservableCollection< Run>), false)]33 [Content(typeof(IObservableCollection<IRun>), false)] 34 34 public partial class RunCollectionView : AsynchronousContentView { 35 public new IObservableCollection< Run> Content {36 get { return (IObservableCollection< Run>)base.Content; }35 public new IObservableCollection<IRun> Content { 36 get { return (IObservableCollection<IRun>)base.Content; } 37 37 set { base.Content = value; } 38 38 } … … 47 47 } 48 48 49 public RunCollectionView(IObservableCollection< Run> content)49 public RunCollectionView(IObservableCollection<IRun> content) 50 50 : this() { 51 51 Content = content; … … 53 53 54 54 protected override void DeregisterContentEvents() { 55 Content.ItemsAdded -= new CollectionItemsChangedEventHandler< Run>(Content_ItemsAdded);56 Content.ItemsRemoved -= new CollectionItemsChangedEventHandler< Run>(Content_ItemsRemoved);57 Content.CollectionReset -= new CollectionItemsChangedEventHandler< Run>(Content_CollectionReset);55 Content.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded); 56 Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved); 57 Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset); 58 58 base.DeregisterContentEvents(); 59 59 } 60 60 protected override void RegisterContentEvents() { 61 61 base.RegisterContentEvents(); 62 Content.ItemsAdded += new CollectionItemsChangedEventHandler< Run>(Content_ItemsAdded);63 Content.ItemsRemoved += new CollectionItemsChangedEventHandler< Run>(Content_ItemsRemoved);64 Content.CollectionReset += new CollectionItemsChangedEventHandler< Run>(Content_CollectionReset);62 Content.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded); 63 Content.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved); 64 Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset); 65 65 } 66 66 … … 77 77 Caption += " (" + Content.GetType().Name + ")"; 78 78 itemsListView.Enabled = true; 79 foreach ( Run item in Content)79 foreach (IRun item in Content) 80 80 AddListViewItem(CreateListViewItem(item)); 81 81 } 82 82 } 83 83 84 protected virtual ListViewItem CreateListViewItem( Run item) {84 protected virtual ListViewItem CreateListViewItem(IRun item) { 85 85 if (!itemsListView.SmallImageList.Images.ContainsKey(item.GetType().FullName)) 86 86 itemsListView.SmallImageList.Images.Add(item.GetType().FullName, item.ItemImage); … … 95 95 protected virtual void AddListViewItem(ListViewItem listViewItem) { 96 96 itemsListView.Items.Add(listViewItem); 97 (( Run)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);97 ((IRun)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged); 98 98 } 99 99 protected virtual void RemoveListViewItem(ListViewItem listViewItem) { 100 (( Run)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);100 ((IRun)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged); 101 101 listViewItem.Remove(); 102 102 } … … 106 106 } 107 107 } 108 protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem( Run item) {108 protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem(IRun item) { 109 109 foreach (ListViewItem listViewItem in itemsListView.Items) { 110 if ((( Run)listViewItem.Tag) == item)110 if (((IRun)listViewItem.Tag) == item) 111 111 yield return listViewItem; 112 112 } … … 117 117 removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && !Content.IsReadOnly; 118 118 if (itemsListView.SelectedItems.Count == 1) { 119 Run item = (Run)itemsListView.SelectedItems[0].Tag;119 IRun item = (IRun)itemsListView.SelectedItems[0].Tag; 120 120 detailsGroupBox.Enabled = true; 121 121 viewHost.ViewType = null; … … 134 134 if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly) { 135 135 foreach (ListViewItem item in itemsListView.SelectedItems) 136 Content.Remove(( Run)item.Tag);136 Content.Remove((IRun)item.Tag); 137 137 } 138 138 } … … 140 140 protected virtual void itemsListView_DoubleClick(object sender, EventArgs e) { 141 141 if (itemsListView.SelectedItems.Count == 1) { 142 Run item = (Run)itemsListView.SelectedItems[0].Tag;142 IRun item = (IRun)itemsListView.SelectedItems[0].Tag; 143 143 IView view = MainFormManager.CreateDefaultView(item); 144 144 if (view != null) view.Show(); … … 147 147 protected virtual void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) { 148 148 ListViewItem listViewItem = (ListViewItem)e.Item; 149 Run item = (Run)listViewItem.Tag;149 IRun item = (IRun)listViewItem.Tag; 150 150 DataObject data = new DataObject(); 151 151 data.SetData("Type", item.GetType()); … … 162 162 e.Effect = DragDropEffects.None; 163 163 Type type = e.Data.GetData("Type") as Type; 164 if ((!Content.IsReadOnly) && (type != null) && (typeof( Run).IsAssignableFrom(type))) {164 if ((!Content.IsReadOnly) && (type != null) && (typeof(IRun).IsAssignableFrom(type))) { 165 165 if ((e.KeyState & 8) == 8) e.Effect = DragDropEffects.Copy; // CTRL key 166 166 else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key … … 172 172 protected virtual void itemsListView_DragDrop(object sender, DragEventArgs e) { 173 173 if (e.Effect != DragDropEffects.None) { 174 Run item = e.Data.GetData("Value") asRun;175 if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = ( Run)item.Clone();174 IRun item = e.Data.GetData("Value") as IRun; 175 if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (IRun)item.Clone(); 176 176 Content.Add(item); 177 177 } … … 183 183 if (itemsListView.SelectedItems.Count > 0) { 184 184 foreach (ListViewItem item in itemsListView.SelectedItems) 185 Content.Remove(( Run)item.Tag);185 Content.Remove((IRun)item.Tag); 186 186 itemsListView.SelectedItems.Clear(); 187 187 } … … 190 190 191 191 #region Content Events 192 protected virtual void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs< Run> e) {193 if (InvokeRequired) 194 Invoke(new CollectionItemsChangedEventHandler< Run>(Content_ItemsAdded), sender, e);192 protected virtual void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 193 if (InvokeRequired) 194 Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e); 195 195 else 196 foreach ( Run item in e.Items)196 foreach (IRun item in e.Items) 197 197 AddListViewItem(CreateListViewItem(item)); 198 198 } 199 protected virtual void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs< Run> e) {200 if (InvokeRequired) 201 Invoke(new CollectionItemsChangedEventHandler< Run>(Content_ItemsRemoved), sender, e);199 protected virtual void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 200 if (InvokeRequired) 201 Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e); 202 202 else { 203 foreach ( Run item in e.Items) {203 foreach (IRun item in e.Items) { 204 204 foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) { 205 205 RemoveListViewItem(listViewItem); … … 209 209 } 210 210 } 211 protected virtual void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs< Run> e) {212 if (InvokeRequired) 213 Invoke(new CollectionItemsChangedEventHandler< Run>(Content_CollectionReset), sender, e);211 protected virtual void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 212 if (InvokeRequired) 213 Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e); 214 214 else { 215 foreach ( Run item in e.OldItems) {215 foreach (IRun item in e.OldItems) { 216 216 foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) { 217 217 RemoveListViewItem(listViewItem); … … 219 219 } 220 220 } 221 foreach ( Run item in e.Items)221 foreach (IRun item in e.Items) 222 222 AddListViewItem(CreateListViewItem(item)); 223 223 } … … 230 230 Invoke(new EventHandler(Item_ToStringChanged), sender, e); 231 231 else { 232 Run item = (Run)sender;232 IRun item = (IRun)sender; 233 233 foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) 234 234 UpdateListViewItem(listViewItem); -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.Designer.cs
r3277 r3280 46 46 private void InitializeComponent() { 47 47 this.components = new System.ComponentModel.Container(); 48 System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup(" Parameters", System.Windows.Forms.HorizontalAlignment.Left);49 System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup(" Results", System.Windows.Forms.HorizontalAlignment.Left);48 System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("Results", System.Windows.Forms.HorizontalAlignment.Left); 49 System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("Parameters", System.Windows.Forms.HorizontalAlignment.Left); 50 50 this.parametersResultsGroupBox = new System.Windows.Forms.GroupBox(); 51 51 this.splitContainer = new System.Windows.Forms.SplitContainer(); … … 113 113 this.valueColumnHeader}); 114 114 this.listView.FullRowSelect = true; 115 listViewGroup1.Header = " Parameters";116 listViewGroup1.Name = " parametersGroup";117 listViewGroup2.Header = " Results";118 listViewGroup2.Name = " resultsGroup";115 listViewGroup1.Header = "Results"; 116 listViewGroup1.Name = "resultsGroup"; 117 listViewGroup2.Header = "Parameters"; 118 listViewGroup2.Name = "parametersGroup"; 119 119 this.listView.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { 120 120 listViewGroup1, -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.cs
r3277 r3280 31 31 /// </summary> 32 32 [View("Run View")] 33 [Content(typeof( Run), true)]33 [Content(typeof(IRun), true)] 34 34 public sealed partial class RunView : NamedItemView { 35 35 /// <summary> … … 38 38 /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>. 39 39 /// No own data storage present.</remarks> 40 public new Run Content {41 get { return ( Run)base.Content; }40 public new IRun Content { 41 get { return (IRun)base.Content; } 42 42 set { base.Content = value; } 43 43 } … … 55 55 /// <remarks>Calls <see cref="VariableView()"/>.</remarks> 56 56 /// <param name="variable">The variable to represent visually.</param> 57 public RunView( Run content)57 public RunView(IRun content) 58 58 : this() { 59 59 Content = content; … … 76 76 private void FillListView() { 77 77 if (!listView.SmallImageList.Images.ContainsKey("Default")) 78 listView.SmallImageList.Images.Add("Default", HeuristicLab.Common.Resources.VS2008ImageLibrary. Class);78 listView.SmallImageList.Images.Add("Default", HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing); 79 79 80 80 listView.Items.Clear(); -
trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs
r3275 r3280 64 64 } 65 65 66 [Storable] 66 67 private IProblem problem; 67 [Storable]68 private IProblem ProblemPersistence {69 get { return problem; }70 set {71 if (problem != null) DeregisterProblemEvents();72 problem = value;73 if (problem != null) RegisterProblemEvents();74 }75 }76 68 public IProblem Problem { 77 69 get { return problem; } … … 91 83 92 84 [Storable] 85 protected int runsCounter; 86 87 [Storable] 93 88 private RunCollection runs; 94 89 public RunCollection Runs { … … 100 95 executionState = ExecutionState.Stopped; 101 96 executionTime = TimeSpan.Zero; 97 runsCounter = 0; 102 98 runs = new RunCollection(); 103 99 } … … 106 102 executionState = ExecutionState.Stopped; 107 103 executionTime = TimeSpan.Zero; 104 runsCounter = 0; 108 105 runs = new RunCollection(); 109 106 } … … 112 109 executionState = ExecutionState.Stopped; 113 110 executionTime = TimeSpan.Zero; 111 runsCounter = 0; 114 112 runs = new RunCollection(); 115 113 } … … 118 116 executionState = ExecutionState.Stopped; 119 117 executionTime = TimeSpan.Zero; 118 runsCounter = 0; 120 119 runs = new RunCollection(); 121 120 } … … 124 123 executionState = ExecutionState.Stopped; 125 124 executionTime = TimeSpan.Zero; 126 runs = new RunCollection(); 125 runsCounter = 0; 126 runs = new RunCollection(); 127 } 128 internal Algorithm(Algorithm algorithm, Cloner cloner) 129 : base(algorithm.Name, algorithm.Description, (ParameterCollection)cloner.Clone(algorithm.Parameters)) { 130 executionState = algorithm.executionState; 131 executionTime = algorithm.executionTime; 132 problem = (IProblem)cloner.Clone(algorithm.problem); 133 runsCounter = algorithm.runsCounter; 134 runs = (RunCollection)cloner.Clone(algorithm.runs); 135 Initialize(); 136 } 137 [StorableConstructor] 138 protected Algorithm(bool deserializing) : base(deserializing) { } 139 140 [StorableHook(HookType.AfterDeserialization)] 141 private void Initialize() { 142 if (problem != null) RegisterProblemEvents(); 127 143 } 128 144 129 145 public override IDeepCloneable Clone(Cloner cloner) { 146 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 130 147 Algorithm clone = (Algorithm)base.Clone(cloner); 131 148 clone.executionState = executionState; 132 149 clone.executionTime = executionTime; 133 clone.Problem = (IProblem)cloner.Clone(problem); 150 clone.problem = (IProblem)cloner.Clone(problem); 151 clone.runsCounter = runsCounter; 134 152 clone.runs = (RunCollection)cloner.Clone(runs); 153 clone.Initialize(); 135 154 return clone; 136 155 } … … 143 162 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) 144 163 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 145 if (clearRuns) runs.Clear(); 164 if (clearRuns) { 165 runsCounter = 0; 166 runs.Clear(); 167 } 146 168 Prepare(); 147 169 } … … 165 187 public virtual void CollectResultValues(IDictionary<string, IItem> values) { 166 188 foreach (IResult result in Results) 167 values.Add(result.Name, result.Value != null ? (IItem)result.Value.Clone() : null);189 values.Add(result.Name, result.Value); 168 190 } 169 191 … … 205 227 public event EventHandler Stopped; 206 228 protected virtual void OnStopped() { 207 Run run = new Run("Run (" + ExecutionTime.ToString() + ")");208 CollectParameterValues(run.Parameters);209 CollectResultValues(run.Results);210 runs.Add(run);211 229 ExecutionState = ExecutionState.Stopped; 230 runsCounter++; 231 runs.Add(new Run(string.Format("{0} Run {1} ({2})", Name, runsCounter, ExecutionTime), this)); 212 232 EventHandler handler = Stopped; 213 233 if (handler != null) handler(this, EventArgs.Empty); -
trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs
r3276 r3280 66 66 } 67 67 68 [Storable] 68 69 private IAlgorithm algorithm; 69 [Storable]70 private IAlgorithm AlgorithmPersistence {71 get { return algorithm; }72 set {73 if (algorithm != null) DeregisterAlgorithmEvents();74 algorithm = value;75 if (algorithm != null) RegisterAlgorithmEvents();76 }77 }78 70 public IAlgorithm Algorithm { 79 71 get { return algorithm; } … … 113 105 public BatchRun() 114 106 : base() { 107 name = ItemName; 108 description = ItemDescription; 115 109 executionState = ExecutionState.Stopped; 116 110 executionTime = TimeSpan.Zero; … … 119 113 stopPending = false; 120 114 } 121 public BatchRun(string name) : base(name) { 115 public BatchRun(string name) 116 : base(name) { 117 description = ItemDescription; 122 118 executionState = ExecutionState.Stopped; 123 119 executionTime = TimeSpan.Zero; … … 126 122 stopPending = false; 127 123 } 128 public BatchRun(string name, string description) : base(name, description) { 124 public BatchRun(string name, string description) 125 : base(name, description) { 129 126 executionState = ExecutionState.Stopped; 130 127 executionTime = TimeSpan.Zero; … … 133 130 stopPending = false; 134 131 } 132 [StorableConstructor] 133 private BatchRun(bool deserializing) 134 : base(deserializing) { 135 stopPending = false; 136 } 137 138 [StorableHook(HookType.AfterDeserialization)] 139 private void Initialize() { 140 if (algorithm != null) RegisterAlgorithmEvents(); 141 } 135 142 136 143 public override IDeepCloneable Clone(Cloner cloner) { 144 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 137 145 BatchRun clone = (BatchRun)base.Clone(cloner); 138 146 clone.executionState = executionState; 139 147 clone.executionTime = executionTime; 140 clone. Algorithm = (IAlgorithm)cloner.Clone(algorithm);148 clone.algorithm = (IAlgorithm)cloner.Clone(algorithm); 141 149 clone.repetitions = repetitions; 142 150 clone.runs = (RunCollection)cloner.Clone(runs); 143 151 clone.stopPending = stopPending; 152 clone.Initialize(); 144 153 return clone; 145 154 } … … 234 243 algorithm.Started += new EventHandler(Algorithm_Started); 235 244 algorithm.Stopped += new EventHandler(Algorithm_Stopped); 236 algorithm.Runs.CollectionReset += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_CollectionReset);237 algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsAdded);238 algorithm.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsRemoved);245 algorithm.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_CollectionReset); 246 algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded); 247 algorithm.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsRemoved); 239 248 } 240 249 private void DeregisterAlgorithmEvents() { … … 245 254 algorithm.Started -= new EventHandler(Algorithm_Started); 246 255 algorithm.Stopped -= new EventHandler(Algorithm_Stopped); 247 algorithm.Runs.CollectionReset -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_CollectionReset);248 algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsAdded);249 algorithm.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsRemoved);256 algorithm.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_CollectionReset); 257 algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded); 258 algorithm.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsRemoved); 250 259 } 251 260 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { … … 277 286 } 278 287 } 279 private void Algorithm_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs< Run> e) {288 private void Algorithm_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 280 289 Runs.RemoveRange(e.OldItems); 281 290 Runs.AddRange(e.Items); 282 291 } 283 private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs< Run> e) {292 private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 284 293 Runs.AddRange(e.Items); 285 294 } 286 private void Algorithm_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs< Run> e) {295 private void Algorithm_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 287 296 Runs.RemoveRange(e.Items); 288 297 } -
trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs
r3275 r3280 34 34 [StorableClass] 35 35 public abstract class EngineAlgorithm : Algorithm { 36 [Storable] 36 37 private OperatorGraph operatorGraph; 37 [Storable]38 private OperatorGraph OperatorGraphPersistence {39 get { return operatorGraph; }40 set {41 if (operatorGraph != null) operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged);42 operatorGraph = value;43 if (operatorGraph != null) operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);44 }45 }46 38 protected OperatorGraph OperatorGraph { 47 39 get { return operatorGraph; } … … 49 41 if (value == null) throw new ArgumentNullException(); 50 42 if (value != operatorGraph) { 51 if (operatorGraph != null)operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged);43 operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged); 52 44 operatorGraph = value; 53 if (operatorGraph != null)operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);45 operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged); 54 46 OnOperatorGraphChanged(); 55 47 Prepare(); … … 64 56 } 65 57 58 [Storable] 66 59 private IEngine engine; 67 [Storable]68 private IEngine EnginePersistence {69 get { return engine; }70 set {71 if (engine != null) DeregisterEngineEvents();72 engine = value;73 if (engine != null) RegisterEngineEvents();74 }75 }76 60 public IEngine Engine { 77 61 get { return engine; } … … 97 81 globalScope = new Scope("Global Scope"); 98 82 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 99 OperatorGraph = new OperatorGraph();100 Initialize Engine();83 operatorGraph = new OperatorGraph(); 84 Initialize(); 101 85 } 102 86 protected EngineAlgorithm(string name) … … 104 88 globalScope = new Scope("Global Scope"); 105 89 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 106 OperatorGraph = new OperatorGraph();107 Initialize Engine();90 operatorGraph = new OperatorGraph(); 91 Initialize(); 108 92 } 109 93 protected EngineAlgorithm(string name, ParameterCollection parameters) … … 111 95 globalScope = new Scope("Global Scope"); 112 96 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 113 OperatorGraph = new OperatorGraph();114 Initialize Engine();97 operatorGraph = new OperatorGraph(); 98 Initialize(); 115 99 } 116 100 protected EngineAlgorithm(string name, string description) … … 118 102 globalScope = new Scope("Global Scope"); 119 103 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 120 OperatorGraph = new OperatorGraph();121 Initialize Engine();104 operatorGraph = new OperatorGraph(); 105 Initialize(); 122 106 } 123 107 protected EngineAlgorithm(string name, string description, ParameterCollection parameters) … … 125 109 globalScope = new Scope("Global Scope"); 126 110 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 127 OperatorGraph = new OperatorGraph(); 128 InitializeEngine(); 129 } 130 131 private void InitializeEngine() { 132 if (ApplicationManager.Manager != null) { 111 operatorGraph = new OperatorGraph(); 112 Initialize(); 113 } 114 internal EngineAlgorithm(EngineAlgorithm algorithm, Cloner cloner) 115 : base(algorithm, cloner) { 116 globalScope = (IScope)cloner.Clone(algorithm.globalScope); 117 operatorGraph = (OperatorGraph)cloner.Clone(algorithm.operatorGraph); 118 engine = (IEngine)cloner.Clone(algorithm.engine); 119 Initialize(); 120 } 121 [StorableConstructor] 122 protected EngineAlgorithm(bool deserializing) : base(deserializing) { } 123 124 [StorableHook(HookType.AfterDeserialization)] 125 private void Initialize() { 126 operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged); 127 if ((engine == null) && (ApplicationManager.Manager != null)) { 133 128 var types = ApplicationManager.Manager.GetTypes(typeof(IEngine)); 134 129 Type t = types.FirstOrDefault(x => x.Name.Equals("SequentialEngine")); 135 130 if (t == null) t = types.FirstOrDefault(); 136 if (t != null) Engine = (IEngine)Activator.CreateInstance(t); 137 } 131 if (t != null) engine = (IEngine)Activator.CreateInstance(t); 132 } 133 if (engine != null) RegisterEngineEvents(); 138 134 } 139 135 … … 141 137 EngineAlgorithm clone = (EngineAlgorithm)base.Clone(cloner); 142 138 clone.globalScope = (IScope)cloner.Clone(globalScope); 143 clone.Engine = (IEngine)cloner.Clone(engine); 144 clone.OperatorGraph = (OperatorGraph)cloner.Clone(operatorGraph); 139 clone.engine = (IEngine)cloner.Clone(engine); 140 clone.operatorGraph = (OperatorGraph)cloner.Clone(operatorGraph); 141 clone.Initialize(); 145 142 return clone; 146 143 } 147 144 148 145 public UserDefinedAlgorithm CreateUserDefinedAlgorithm() { 149 UserDefinedAlgorithm algorithm = new UserDefinedAlgorithm(Name, Description); 150 Cloner cloner = new Cloner(); 151 foreach (IParameter param in Parameters) 152 algorithm.Parameters.Add((IParameter)cloner.Clone(param)); 153 algorithm.Problem = (IProblem)cloner.Clone(Problem); 154 algorithm.Engine = (IEngine)cloner.Clone(engine); 155 algorithm.OperatorGraph = (OperatorGraph)cloner.Clone(operatorGraph); 156 return algorithm; 146 return new UserDefinedAlgorithm(this, new Cloner()); 157 147 } 158 148 -
trunk/sources/HeuristicLab.Optimization/3.3/Experiment.cs
r3276 r3280 62 62 } 63 63 64 [Storable] 64 65 private OptimizerList optimizers; 65 [Storable]66 66 public OptimizerList Optimizers { 67 67 get { return optimizers; } 68 private set {69 if (optimizers != value) {70 if (optimizers != null) DeregisterOptimizersEvents();71 optimizers = value;72 if (optimizers != null) RegisterOptimizersEvents();73 foreach (IOptimizer optimizer in optimizers)74 RegisterOptimizerEvents(optimizer);75 }76 }77 68 } 78 69 … … 87 78 public Experiment() 88 79 : base() { 80 name = ItemName; 81 description = ItemDescription; 89 82 executionState = ExecutionState.Stopped; 90 83 executionTime = TimeSpan.Zero; 91 Optimizers = new OptimizerList();84 optimizers = new OptimizerList(); 92 85 runs = new RunCollection(); 93 86 stopPending = false; 94 } 95 public Experiment(string name) : base(name) { 87 Initialize(); 88 } 89 public Experiment(string name) 90 : base(name) { 91 description = ItemDescription; 96 92 executionState = ExecutionState.Stopped; 97 93 executionTime = TimeSpan.Zero; 98 Optimizers = new OptimizerList();94 optimizers = new OptimizerList(); 99 95 runs = new RunCollection(); 100 96 stopPending = false; 101 } 102 public Experiment(string name, string description) : base(name, description) { 97 Initialize(); 98 } 99 public Experiment(string name, string description) 100 : base(name, description) { 103 101 executionState = ExecutionState.Stopped; 104 102 executionTime = TimeSpan.Zero; 105 Optimizers = new OptimizerList();103 optimizers = new OptimizerList(); 106 104 runs = new RunCollection(); 107 105 stopPending = false; 106 Initialize(); 107 } 108 [StorableConstructor] 109 private Experiment(bool deserializing) 110 : base(deserializing) { 111 stopPending = false; 112 } 113 114 [StorableHook(HookType.AfterDeserialization)] 115 private void Initialize() { 116 RegisterOptimizersEvents(); 117 foreach (IOptimizer optimizer in optimizers) 118 RegisterOptimizerEvents(optimizer); 108 119 } 109 120 110 121 public override IDeepCloneable Clone(Cloner cloner) { 122 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 111 123 Experiment clone = (Experiment)base.Clone(cloner); 112 124 clone.executionState = executionState; 113 125 clone.executionTime = executionTime; 114 clone. Optimizers = (OptimizerList)cloner.Clone(optimizers);126 clone.optimizers = (OptimizerList)cloner.Clone(optimizers); 115 127 clone.runs = (RunCollection)cloner.Clone(runs); 116 128 clone.stopPending = stopPending; 129 clone.Initialize(); 117 130 return clone; 118 131 } … … 244 257 optimizer.Started += new EventHandler(optimizer_Started); 245 258 optimizer.Stopped += new EventHandler(optimizer_Stopped); 246 optimizer.Runs.CollectionReset += new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_CollectionReset);247 optimizer.Runs.ItemsAdded += new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_ItemsAdded);248 optimizer.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_ItemsRemoved);259 optimizer.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_CollectionReset); 260 optimizer.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsAdded); 261 optimizer.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved); 249 262 } 250 263 private void DeregisterOptimizerEvents(IOptimizer optimizer) { … … 255 268 optimizer.Started -= new EventHandler(optimizer_Started); 256 269 optimizer.Stopped -= new EventHandler(optimizer_Stopped); 257 optimizer.Runs.CollectionReset -= new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_CollectionReset);258 optimizer.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_ItemsAdded);259 optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_ItemsRemoved);270 optimizer.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_CollectionReset); 271 optimizer.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsAdded); 272 optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved); 260 273 } 261 274 private void optimizer_ExceptionOccurred(object sender, EventArgs<Exception> e) { … … 287 300 } 288 301 } 289 private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs< Run> e) {302 private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 290 303 Runs.RemoveRange(e.OldItems); 291 304 Runs.AddRange(e.Items); 292 305 } 293 private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs< Run> e) {306 private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 294 307 Runs.AddRange(e.Items); 295 308 } 296 private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs< Run> e) {309 private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 297 310 Runs.RemoveRange(e.Items); 298 311 } -
trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r3274 r3280 87 87 <Compile Include="Algorithm.cs" /> 88 88 <Compile Include="BatchRun.cs" /> 89 <Compile Include="Interfaces\IRun.cs" /> 89 90 <Compile Include="OptimizerList.cs" /> 90 91 <Compile Include="Experiment.cs" /> -
trunk/sources/HeuristicLab.Optimization/3.3/Run.cs
r3275 r3280 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Core; … … 30 31 [Item("Run", "The parameters and results of an algorithm run.")] 31 32 [StorableClass] 32 public sealed class Run : NamedItem { 33 public override bool CanChangeName { 34 get { return false; } 33 public sealed class Run : NamedItem, IRun { 34 [Storable] 35 private IAlgorithm algorithm; 36 public IAlgorithm Algorithm { 37 get { return algorithm; } 35 38 } 36 public override bool CanChangeDescription {37 get { return false; }38 }39 40 39 [Storable] 41 40 private Dictionary<string, IItem> parameters; … … 50 49 51 50 public Run() 52 : base("Anonymous") { 51 : base() { 52 name = ItemName; 53 description = ItemDescription; 54 algorithm = null; 53 55 parameters = new Dictionary<string, IItem>(); 54 56 results = new Dictionary<string, IItem>(); 55 57 } 56 public Run(string name) 58 public Run(IAlgorithm algorithm) 59 : base() { 60 if (algorithm == null) throw new ArgumentNullException(); 61 name = algorithm.Name + " Run (" + algorithm.ExecutionTime.ToString() + ")"; 62 description = ItemDescription; 63 Initialize((IAlgorithm)algorithm.Clone()); 64 } 65 public Run(string name, IAlgorithm algorithm) 57 66 : base(name) { 67 if (algorithm == null) throw new ArgumentNullException(); 68 description = ItemDescription; 69 Initialize((IAlgorithm)algorithm.Clone()); 70 } 71 public Run(string name, string description, IAlgorithm algorithm) 72 : base(name, description) { 73 if (algorithm == null) throw new ArgumentNullException(); 74 Initialize((IAlgorithm)algorithm.Clone()); 75 } 76 77 private void Initialize(IAlgorithm algorithm) { 78 this.algorithm = algorithm; 58 79 parameters = new Dictionary<string, IItem>(); 59 80 results = new Dictionary<string, IItem>(); 60 } 61 public Run(string name, string description) 62 : base(name, description) { 63 parameters = new Dictionary<string, IItem>(); 64 results = new Dictionary<string, IItem>(); 81 this.algorithm.CollectParameterValues(parameters); 82 this.algorithm.CollectResultValues(results); 65 83 } 66 84 67 85 public override IDeepCloneable Clone(Cloner cloner) { 68 Run clone = new Run(Name, Description);69 clone r.RegisterClonedObject(this, clone);86 Run clone = (Run)base.Clone(cloner); 87 clone.algorithm = (IAlgorithm)cloner.Clone(algorithm); 70 88 foreach (string key in parameters.Keys) 71 89 clone.parameters.Add(key, (IItem)cloner.Clone(parameters[key])); -
trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs
r3274 r3280 28 28 [StorableClass] 29 29 [Item("RunCollection", "Represents a collection of runs.")] 30 public class RunCollection : ItemCollection< Run> {30 public class RunCollection : ItemCollection<IRun> { 31 31 public RunCollection() : base() { } 32 32 public RunCollection(int capacity) : base(capacity) { } 33 public RunCollection(IEnumerable< Run> collection) : base(collection) { }33 public RunCollection(IEnumerable<IRun> collection) : base(collection) { } 34 34 35 35 public override IDeepCloneable Clone(Cloner cloner) { 36 RunCollection clone = new RunCollection(this.Select(x => ( Run)cloner.Clone(x)));36 RunCollection clone = new RunCollection(this.Select(x => (IRun)cloner.Clone(x))); 37 37 cloner.RegisterClonedObject(this, clone); 38 38 return clone; -
trunk/sources/HeuristicLab.Optimization/3.3/UserDefinedAlgorithm.cs
r3262 r3280 52 52 public UserDefinedAlgorithm(string name) : base(name) { } 53 53 public UserDefinedAlgorithm(string name, string description) : base(name, description) { } 54 internal UserDefinedAlgorithm(EngineAlgorithm algorithm, Cloner cloner) : base(algorithm, cloner) { } 55 [StorableConstructor] 56 private UserDefinedAlgorithm(bool deserializing) : base(deserializing) { } 54 57 55 58 public event EventHandler OperatorGraphChanged;
Note: See TracChangeset
for help on using the changeset viewer.