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 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
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 | }
|
---|
34 |
|
---|
35 | public RunCollectionModifierHiveTask(RunCollectionModifierExecutable executable)
|
---|
36 | : base() {
|
---|
37 | ItemTask = new RunCollectionModifierTask(executable);
|
---|
38 | }
|
---|
39 |
|
---|
40 | protected RunCollectionModifierHiveTask(RunCollectionModifierHiveTask original, Cloner cloner)
|
---|
41 | : base(original, cloner) {
|
---|
42 | }
|
---|
43 |
|
---|
44 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
45 | return new RunCollectionModifierHiveTask(this, cloner);
|
---|
46 | }
|
---|
47 | #endregion
|
---|
48 |
|
---|
49 | public override void IntegrateChild(ItemTask task, Guid childTaskId) {
|
---|
50 | var rcmTask = (RunCollectionModifierTask)task;
|
---|
51 | syncTasksWithOptimizers = false;
|
---|
52 |
|
---|
53 | if (ItemTask != null && ItemTask.Item != null) {
|
---|
54 | itemTaskLock.EnterWriteLock();
|
---|
55 | try {
|
---|
56 | ItemTask.Item.RunCollection.AddRange(rcmTask.Item.RunCollection);
|
---|
57 | }
|
---|
58 | finally {
|
---|
59 | itemTaskLock.ExitWriteLock();
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | RunCollectionModifierHiveTask child = ChildHiveTasks.Single(j => j.Task.Id == childTaskId) as RunCollectionModifierHiveTask;
|
---|
64 | if (!rcmTask.ComputeInParallel) {
|
---|
65 | child.ItemTask = rcmTask;
|
---|
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;
|
---|
77 | //compute in parallel was deactivated, copy runs back to parent
|
---|
78 | foreach (var childHiveTask in childHiveTasks) {
|
---|
79 | exec.RunCollection.AddRange(((RunCollectionModifierExecutable)childHiveTask.ItemTask.Item).RunCollection);
|
---|
80 | }
|
---|
81 | childHiveTasks.Clear();
|
---|
82 | }
|
---|
83 | } else {
|
---|
84 | var runs = ItemTask.Item.RunCollection;
|
---|
85 | foreach (var run in runs) {
|
---|
86 | var exec = ItemTask.Item.CloneWithoutRuns();
|
---|
87 | exec.RunCollection.Add(run);
|
---|
88 | exec.Prepare();
|
---|
89 |
|
---|
90 | var rcmHiveTask = new RunCollectionModifierHiveTask(exec);
|
---|
91 | rcmHiveTask.Task.Priority = Task.Priority;
|
---|
92 | rcmHiveTask.ItemTask.IsParallelizable = false;
|
---|
93 | childHiveTasks.Add(rcmHiveTask);
|
---|
94 | }
|
---|
95 | ItemTask.Item.RunCollection.Clear();
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | finally {
|
---|
100 | childHiveTasksLock.ExitWriteLock();
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 | } |
---|