[10114] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[10117] | 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
[10114] | 24 | using HeuristicLab.Clients.Hive;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Analysis.SolutionCaching {
|
---|
| 28 | public class RunCollectionModifierHiveTask : HiveTask<RunCollectionModifierTask> {
|
---|
| 29 | #region Constructors and Cloning
|
---|
| 30 | public RunCollectionModifierHiveTask(RunCollectionModifierTask task)
|
---|
| 31 | : base() {
|
---|
| 32 | ItemTask = task;
|
---|
| 33 | }
|
---|
[10117] | 34 |
|
---|
[10114] | 35 | public RunCollectionModifierHiveTask(RunCollectionModifierExecutable executable)
|
---|
| 36 | : base() {
|
---|
| 37 | ItemTask = new RunCollectionModifierTask(executable);
|
---|
| 38 | }
|
---|
[10117] | 39 |
|
---|
[10114] | 40 | protected RunCollectionModifierHiveTask(RunCollectionModifierHiveTask original, Cloner cloner)
|
---|
[10117] | 41 | : base(original, cloner) {
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[10114] | 44 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 45 | return new RunCollectionModifierHiveTask(this, cloner);
|
---|
| 46 | }
|
---|
| 47 | #endregion
|
---|
[10117] | 48 |
|
---|
| 49 | public override void IntegrateChild(ItemTask task, Guid childTaskId) {
|
---|
[10128] | 50 | var rcmTask = (RunCollectionModifierTask)task;
|
---|
| 51 | syncTasksWithOptimizers = false;
|
---|
[10117] | 52 |
|
---|
[10128] | 53 | if (ItemTask != null && ItemTask.Item != null) {
|
---|
[10117] | 54 | itemTaskLock.EnterWriteLock();
|
---|
| 55 | try {
|
---|
[10128] | 56 | ItemTask.Item.RunCollection.AddRange(rcmTask.Item.RunCollection);
|
---|
[10117] | 57 | }
|
---|
| 58 | finally {
|
---|
| 59 | itemTaskLock.ExitWriteLock();
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[10128] | 63 | RunCollectionModifierHiveTask child = ChildHiveTasks.Single(j => j.Task.Id == childTaskId) as RunCollectionModifierHiveTask;
|
---|
| 64 | if (!rcmTask.ComputeInParallel) {
|
---|
| 65 | child.ItemTask = rcmTask;
|
---|
[10117] | 66 | }
|
---|
| 67 | syncTasksWithOptimizers = true;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | protected override void UpdateChildHiveTasks() {
|
---|
| 71 | childHiveTasksLock.EnterWriteLock();
|
---|
| 72 | try {
|
---|
| 73 | if (Task != null && syncTasksWithOptimizers) {
|
---|
| 74 | if (!ItemTask.ComputeInParallel) {
|
---|
| 75 | if (childHiveTasks.Any()) {
|
---|
| 76 | var exec = (RunCollectionModifierExecutable)ItemTask.Item;
|
---|
[10128] | 77 | //compute in parallel was deactivated, copy runs back to parent
|
---|
[10117] | 78 | foreach (var childHiveTask in childHiveTasks) {
|
---|
| 79 | exec.RunCollection.AddRange(((RunCollectionModifierExecutable)childHiveTask.ItemTask.Item).RunCollection);
|
---|
| 80 | }
|
---|
[10128] | 81 | childHiveTasks.Clear();
|
---|
[10117] | 82 | }
|
---|
| 83 | } else {
|
---|
| 84 | var runs = ItemTask.Item.RunCollection;
|
---|
| 85 | foreach (var run in runs) {
|
---|
[10128] | 86 | var exec = ItemTask.Item.CloneWithoutRuns();
|
---|
[10117] | 87 | exec.RunCollection.Add(run);
|
---|
[10128] | 88 | exec.Prepare();
|
---|
[10117] | 89 |
|
---|
| 90 | var rcmHiveTask = new RunCollectionModifierHiveTask(exec);
|
---|
| 91 | rcmHiveTask.Task.Priority = Task.Priority;
|
---|
[10121] | 92 | rcmHiveTask.ItemTask.IsParallelizable = false;
|
---|
[10117] | 93 | childHiveTasks.Add(rcmHiveTask);
|
---|
| 94 | }
|
---|
| 95 | ItemTask.Item.RunCollection.Clear();
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | finally {
|
---|
| 100 | childHiveTasksLock.ExitWriteLock();
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
[10114] | 103 | }
|
---|
| 104 | } |
---|