#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Linq; using HeuristicLab.Clients.Hive; using HeuristicLab.Common; namespace HeuristicLab.Analysis.SolutionCaching { public class RunCollectionModifierHiveTask : HiveTask { #region Constructors and Cloning public RunCollectionModifierHiveTask(RunCollectionModifierTask task) : base() { ItemTask = task; } public RunCollectionModifierHiveTask(RunCollectionModifierExecutable executable) : base() { ItemTask = new RunCollectionModifierTask(executable); } protected RunCollectionModifierHiveTask(RunCollectionModifierHiveTask original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new RunCollectionModifierHiveTask(this, cloner); } #endregion public override void IntegrateChild(ItemTask task, Guid childTaskId) { var rcmTask = (RunCollectionModifierTask)task; syncTasksWithOptimizers = false; if (ItemTask != null && ItemTask.Item != null) { itemTaskLock.EnterWriteLock(); try { ItemTask.Item.RunCollection.AddRange(rcmTask.Item.RunCollection); } finally { itemTaskLock.ExitWriteLock(); } } RunCollectionModifierHiveTask child = ChildHiveTasks.Single(j => j.Task.Id == childTaskId) as RunCollectionModifierHiveTask; if (!rcmTask.ComputeInParallel) { child.ItemTask = rcmTask; } syncTasksWithOptimizers = true; } protected override void UpdateChildHiveTasks() { childHiveTasksLock.EnterWriteLock(); try { if (Task != null && syncTasksWithOptimizers) { if (!ItemTask.ComputeInParallel) { if (childHiveTasks.Any()) { var exec = (RunCollectionModifierExecutable)ItemTask.Item; //compute in parallel was deactivated, copy runs back to parent foreach (var childHiveTask in childHiveTasks) { exec.RunCollection.AddRange(((RunCollectionModifierExecutable)childHiveTask.ItemTask.Item).RunCollection); } childHiveTasks.Clear(); } } else { var runs = ItemTask.Item.RunCollection; foreach (var run in runs) { var exec = ItemTask.Item.CloneWithoutRuns(); exec.RunCollection.Add(run); exec.Prepare(); var rcmHiveTask = new RunCollectionModifierHiveTask(exec); rcmHiveTask.Task.Priority = Task.Priority; rcmHiveTask.ItemTask.IsParallelizable = false; childHiveTasks.Add(rcmHiveTask); } ItemTask.Item.RunCollection.Clear(); } } } finally { childHiveTasksLock.ExitWriteLock(); } } } }