Changeset 6178 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/OptimizerHiveJob.cs
- Timestamp:
- 05/10/11 17:58:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/OptimizerHiveJob.cs
r6111 r6178 37 37 public OptimizerHiveJob(IOptimizer optimizer) 38 38 : this() { 39 this. JobItem= new OptimizerJob(optimizer);39 this.ItemJob = new OptimizerJob(optimizer); 40 40 } 41 41 public OptimizerHiveJob(OptimizerJob optimizerJob) 42 42 : this() { 43 this. JobItem= optimizerJob;43 this.ItemJob = optimizerJob; 44 44 } 45 45 protected OptimizerHiveJob(OptimizerHiveJob original, Cloner cloner) … … 60 60 base.UpdateChildHiveJobs(); 61 61 if (Job != null && syncJobsWithOptimizers) { 62 if (! JobItem.ComputeInParallel) {62 if (!ItemJob.ComputeInParallel) { 63 63 this.childHiveJobs.Clear(); 64 64 } else { 65 if ( JobItem.Item is Optimization.Experiment) {66 Optimization.Experiment experiment = (Optimization.Experiment) JobItem.Item;65 if (ItemJob.Item is Optimization.Experiment) { 66 Optimization.Experiment experiment = (Optimization.Experiment)ItemJob.Item; 67 67 foreach (IOptimizer childOpt in experiment.Optimizers) { 68 68 this.childHiveJobs.Add(new OptimizerHiveJob(childOpt)); 69 69 } 70 } else if ( JobItem.Item is Optimization.BatchRun) {71 Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;70 } else if (ItemJob.Item is Optimization.BatchRun) { 71 Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun; 72 72 if (batchRun.Optimizer != null) { 73 73 while (this.childHiveJobs.Count < batchRun.Repetitions) { … … 83 83 } 84 84 85 protected override void Register JobItemEvents() {86 base.Register JobItemEvents();87 if ( JobItem!= null) {88 if ( JobItem.Item is Optimization.Experiment) {89 Optimization.Experiment experiment = JobItem.OptimizerAsExperiment;85 protected override void RegisterItemJobEvents() { 86 base.RegisterItemJobEvents(); 87 if (ItemJob != null) { 88 if (ItemJob.Item is Optimization.Experiment) { 89 Optimization.Experiment experiment = ItemJob.OptimizerAsExperiment; 90 90 experiment.Optimizers.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded); 91 91 experiment.Optimizers.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced); 92 92 experiment.Optimizers.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved); 93 93 experiment.Optimizers.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset); 94 } else if ( JobItem.Item is Optimization.BatchRun) {95 Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;94 } else if (ItemJob.Item is Optimization.BatchRun) { 95 Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun; 96 96 batchRun.RepetitionsChanged += new EventHandler(batchRun_RepetitionsChanged); 97 97 batchRun.OptimizerChanged += new EventHandler(batchRun_OptimizerChanged); … … 99 99 } 100 100 } 101 protected override void Dergister JobItemsEvents() {102 base.Dergister JobItemsEvents();103 if ( JobItem!= null) {104 if ( JobItem.Item is Optimization.Experiment) {105 Optimization.Experiment experiment = JobItem.OptimizerAsExperiment;101 protected override void DergisterItemJobEvents() { 102 base.DergisterItemJobEvents(); 103 if (ItemJob != null) { 104 if (ItemJob.Item is Optimization.Experiment) { 105 Optimization.Experiment experiment = ItemJob.OptimizerAsExperiment; 106 106 experiment.Optimizers.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded); 107 107 experiment.Optimizers.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced); 108 108 experiment.Optimizers.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved); 109 109 experiment.Optimizers.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset); 110 } else if ( JobItem.Item is Optimization.BatchRun) {111 Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;110 } else if (ItemJob.Item is Optimization.BatchRun) { 111 Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun; 112 112 batchRun.RepetitionsChanged -= new EventHandler(batchRun_RepetitionsChanged); 113 113 batchRun.OptimizerChanged -= new EventHandler(batchRun_OptimizerChanged); … … 129 129 130 130 private void Optimizers_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) { 131 if (syncJobsWithOptimizers && this. JobItem.ComputeInParallel) {131 if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) { 132 132 foreach (var item in e.Items) { 133 133 if (GetChildByOptimizer(item.Value) == null && item.Value.Name != "Placeholder") { … … 138 138 } 139 139 private void Optimizers_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) { 140 if (syncJobsWithOptimizers && this. JobItem.ComputeInParallel) {140 if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) { 141 141 foreach (var item in e.OldItems) { 142 142 this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value)); … … 150 150 } 151 151 private void Optimizers_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) { 152 if (syncJobsWithOptimizers && this. JobItem.ComputeInParallel) {152 if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) { 153 153 foreach (var item in e.Items) { 154 154 this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value)); … … 157 157 } 158 158 private void Optimizers_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) { 159 if (syncJobsWithOptimizers && this. JobItem.ComputeInParallel) {159 if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) { 160 160 foreach (var item in e.Items) { 161 161 this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value)); … … 174 174 syncJobsWithOptimizers = false; // don't sync with optimizers during this method 175 175 176 if (this. JobItem != null && this.JobItem.Item != null) {177 if (this. JobItem.Item is Optimization.Experiment) {178 UpdateOptimizerInExperiment(this. JobItem.OptimizerAsExperiment, optimizerJob);179 } else if (this. JobItem.Item is Optimization.BatchRun) {180 UpdateOptimizerInBatchRun(this. JobItem.OptimizerAsBatchRun, optimizerJob);176 if (this.ItemJob != null && this.ItemJob.Item != null) { 177 if (this.ItemJob.Item is Optimization.Experiment) { 178 UpdateOptimizerInExperiment(this.ItemJob.OptimizerAsExperiment, optimizerJob); 179 } else if (this.ItemJob.Item is Optimization.BatchRun) { 180 UpdateOptimizerInBatchRun(this.ItemJob.OptimizerAsBatchRun, optimizerJob); 181 181 } 182 182 } … … 185 185 if (!optimizerJob.ComputeInParallel) { 186 186 child.syncJobsWithOptimizers = false; 187 child. JobItem= optimizerJob;187 child.ItemJob = optimizerJob; 188 188 child.syncJobsWithOptimizers = true; 189 189 } … … 236 236 internal void SetIndexInParentOptimizerList(OptimizerHiveJob parentHiveJob) { 237 237 if (parentHiveJob != null) { 238 if (parentHiveJob. JobItem.Item is Optimization.Experiment) {239 this. JobItem.IndexInParentOptimizerList = parentHiveJob.JobItem.OptimizerAsExperiment.Optimizers.IndexOf(this.JobItem.Item);240 } else if (parentHiveJob. JobItem.Item is Optimization.BatchRun) {241 this. JobItem.IndexInParentOptimizerList = 0;238 if (parentHiveJob.ItemJob.Item is Optimization.Experiment) { 239 this.ItemJob.IndexInParentOptimizerList = parentHiveJob.ItemJob.OptimizerAsExperiment.Optimizers.IndexOf(this.ItemJob.Item); 240 } else if (parentHiveJob.ItemJob.Item is Optimization.BatchRun) { 241 this.ItemJob.IndexInParentOptimizerList = 0; 242 242 } else { 243 243 throw new NotSupportedException("Only Experiment and BatchRuns are supported"); … … 253 253 var optimizerHiveJob = (OptimizerHiveJob)hiveJob; 254 254 syncJobsWithOptimizers = false; 255 if (this. JobItem != null && optimizerHiveJob.JobItem!= null) {255 if (this.ItemJob != null && optimizerHiveJob.ItemJob != null) { 256 256 // if job is in state Paused, it has to preserve its ResultCollection, which is cleared when a optimizer is added to an experiment 257 257 OptimizerJob optimizerJobClone = null; 258 258 if (optimizerHiveJob.Job.State == JobState.Paused) { 259 optimizerJobClone = (OptimizerJob)optimizerHiveJob. JobItem.Clone();260 } 261 262 if (this. JobItem.Item is Optimization.Experiment) {263 if (!this. JobItem.OptimizerAsExperiment.Optimizers.Contains(optimizerHiveJob.JobItem.Item)) {264 UpdateOptimizerInExperiment(this. JobItem.OptimizerAsExperiment, optimizerHiveJob.JobItem);259 optimizerJobClone = (OptimizerJob)optimizerHiveJob.ItemJob.Clone(); 260 } 261 262 if (this.ItemJob.Item is Optimization.Experiment) { 263 if (!this.ItemJob.OptimizerAsExperiment.Optimizers.Contains(optimizerHiveJob.ItemJob.Item)) { 264 UpdateOptimizerInExperiment(this.ItemJob.OptimizerAsExperiment, optimizerHiveJob.ItemJob); 265 265 } 266 } else if (this. JobItem.Item is Optimization.BatchRun) {267 UpdateOptimizerInBatchRun(this. JobItem.OptimizerAsBatchRun, optimizerHiveJob.JobItem);266 } else if (this.ItemJob.Item is Optimization.BatchRun) { 267 UpdateOptimizerInBatchRun(this.ItemJob.OptimizerAsBatchRun, optimizerHiveJob.ItemJob); 268 268 } 269 269 270 270 if (optimizerHiveJob.Job.State == JobState.Paused) { 271 optimizerHiveJob. JobItem= optimizerJobClone;271 optimizerHiveJob.ItemJob = optimizerJobClone; 272 272 } 273 273 } … … 283 283 public override JobData GetAsJobData(bool withoutChildOptimizers, out List<IPluginDescription> plugins) { 284 284 plugins = new List<IPluginDescription>(); 285 if (this. jobItem== null) // || this.jobItem.Optimizer == null285 if (this.itemJob == null) // || this.jobItem.Optimizer == null 286 286 return null; 287 287 288 288 IEnumerable<Type> usedTypes; 289 289 byte[] jobByteArray; 290 if (withoutChildOptimizers && this. JobItem.Item is Optimization.Experiment) {291 OptimizerJob clonedJob = (OptimizerJob)this. JobItem.Clone(); // use a cloned job, so that the childHiveJob don't get confused290 if (withoutChildOptimizers && this.ItemJob.Item is Optimization.Experiment) { 291 OptimizerJob clonedJob = (OptimizerJob)this.ItemJob.Clone(); // use a cloned job, so that the childHiveJob don't get confused 292 292 clonedJob.OptimizerAsExperiment.Optimizers.Clear(); 293 293 jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes); 294 } else if (withoutChildOptimizers && this. JobItem.Item is Optimization.BatchRun) {295 OptimizerJob clonedJob = (OptimizerJob)this. JobItem.Clone();294 } else if (withoutChildOptimizers && this.ItemJob.Item is Optimization.BatchRun) { 295 OptimizerJob clonedJob = (OptimizerJob)this.ItemJob.Clone(); 296 296 clonedJob.OptimizerAsBatchRun.Optimizer = null; 297 297 jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes); 298 } else if (this. JobItem.Item is IAlgorithm) {299 ((IAlgorithm)this. JobItem.Item).StoreAlgorithmInEachRun = false; // avoid storing the algorithm in runs to reduce size300 jobByteArray = PersistenceUtil.Serialize(this. JobItem, out usedTypes);298 } else if (this.ItemJob.Item is IAlgorithm) { 299 ((IAlgorithm)this.ItemJob.Item).StoreAlgorithmInEachRun = false; // avoid storing the algorithm in runs to reduce size 300 jobByteArray = PersistenceUtil.Serialize(this.ItemJob, out usedTypes); 301 301 } else { 302 jobByteArray = PersistenceUtil.Serialize(this. JobItem, out usedTypes);302 jobByteArray = PersistenceUtil.Serialize(this.ItemJob, out usedTypes); 303 303 } 304 304 … … 315 315 public OptimizerHiveJob GetChildByOptimizerJob(OptimizerJob optimizerJob) { 316 316 foreach (OptimizerHiveJob child in ChildHiveJobs) { 317 if (child. JobItem== optimizerJob)317 if (child.ItemJob == optimizerJob) 318 318 return child; 319 319 } … … 323 323 public HiveJob<OptimizerJob> GetChildByOptimizer(IOptimizer optimizer) { 324 324 foreach (OptimizerHiveJob child in ChildHiveJobs) { 325 if (child. JobItem.Item == optimizer)325 if (child.ItemJob.Item == optimizer) 326 326 return child; 327 327 }
Note: See TracChangeset
for help on using the changeset viewer.