Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/08/13 18:39:42 (11 years ago)
Author:
ascheibe
Message:

#1886 made RunCollectionModifierHiveTask distributable

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers/RunCollectionModifierHiveTask.cs

    r10114 r10117  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Clients.Hive;
    2326using HeuristicLab.Common;
     27using HeuristicLab.Optimization;
    2428
    2529namespace HeuristicLab.Analysis.SolutionCaching {
     
    3034      ItemTask = task;
    3135    }
     36
    3237    public RunCollectionModifierHiveTask(RunCollectionModifierExecutable executable)
    3338      : base() {
    3439      ItemTask = new RunCollectionModifierTask(executable);
    3540    }
     41
    3642    protected RunCollectionModifierHiveTask(RunCollectionModifierHiveTask original, Cloner cloner)
    37       : base(original, cloner) { }
     43      : base(original, cloner) {
     44    }
     45
    3846    public override IDeepCloneable Clone(Cloner cloner) {
    3947      return new RunCollectionModifierHiveTask(this, cloner);
    4048    }
    4149    #endregion
     50
     51    public override void IntegrateChild(ItemTask task, Guid childTaskId) {
     52      var optimizerTask = (RunCollectionModifierTask)task;
     53      syncTasksWithOptimizers = false; // don't sync with optimizers during this method
     54
     55      if (this.ItemTask != null && this.ItemTask.Item != null) {
     56        itemTaskLock.EnterWriteLock();
     57        try {
     58          this.ItemTask.Item.RunCollection.AddRange(((RunCollectionModifierExecutable)task.Item).RunCollection);
     59        }
     60        finally {
     61          itemTaskLock.ExitWriteLock();
     62        }
     63      }
     64
     65      IEnumerable<HiveTask> childs = this.ChildHiveTasks.Where(j => j.Task.Id == childTaskId);
     66      //TODO: in very rare cases childs is empty. This shouldn't be the case and should be further investigated.
     67      if (childs.Count() > 0) {
     68        RunCollectionModifierHiveTask child = childs.First() as RunCollectionModifierHiveTask;
     69        if (child != null && !optimizerTask.ComputeInParallel) {
     70          child.ItemTask = optimizerTask;
     71        }
     72      }
     73      syncTasksWithOptimizers = true;
     74    }
     75
     76    protected override void UpdateChildHiveTasks() {
     77      childHiveTasksLock.EnterWriteLock();
     78      try {
     79        if (Task != null && syncTasksWithOptimizers) {
     80          if (!ItemTask.ComputeInParallel) {
     81            if (childHiveTasks.Any()) {
     82              var exec = (RunCollectionModifierExecutable)ItemTask.Item;
     83              //compute in parallel was deactivated, copy runs back
     84              foreach (var childHiveTask in childHiveTasks) {
     85                exec.RunCollection.AddRange(((RunCollectionModifierExecutable)childHiveTask.ItemTask.Item).RunCollection);
     86              }
     87            }
     88            childHiveTasks.Clear();
     89          } else {
     90            var runs = ItemTask.Item.RunCollection;
     91            foreach (var run in runs) {
     92              var exec = (RunCollectionModifierExecutable)ItemTask.Item.Clone(new Cloner());
     93              //TODO: this could be more efficient, create new RCME instead of cloning
     94              exec.RunCollection.Clear();
     95              exec.RunCollection.Add(run);
     96
     97              var rcmHiveTask = new RunCollectionModifierHiveTask(exec);
     98              rcmHiveTask.Task.Priority = Task.Priority;
     99              childHiveTasks.Add(rcmHiveTask);
     100            }
     101            ItemTask.Item.RunCollection.Clear();
     102          }
     103        }
     104      }
     105      finally {
     106        childHiveTasksLock.ExitWriteLock();
     107      }
     108    }
    42109  }
    43110}
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers/RunCollectionModifierTask.cs

    r10114 r10117  
    3030  [StorableClass]
    3131  public class RunCollectionModifierTask : ItemTask {
    32     public override bool IsParallelizable {
     32    /*public override bool IsParallelizable {
    3333      get { return false; }
    34     }
     34    } */
    3535
    3636    public new RunCollectionModifierExecutable Item {
Note: See TracChangeset for help on using the changeset viewer.