[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Xml;
|
---|
[1823] | 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[2] | 27 |
|
---|
| 28 | namespace HeuristicLab.Core {
|
---|
[776] | 29 | /// <summary>
|
---|
| 30 | /// Represents a class for operations consisting themselves of several operations.
|
---|
| 31 | /// Can also be executed in parallel.
|
---|
| 32 | /// </summary>
|
---|
[2] | 33 | public class CompositeOperation : ItemBase, IOperation {
|
---|
[1667] | 34 |
|
---|
| 35 | [Storable]
|
---|
[2] | 36 | private bool myExecuteInParallel;
|
---|
[776] | 37 | /// <summary>
|
---|
| 38 | /// Gets or sets the bool value, whether the operation should be executed in parallel or not.
|
---|
| 39 | /// </summary>
|
---|
[2] | 40 | public bool ExecuteInParallel {
|
---|
| 41 | get { return myExecuteInParallel; }
|
---|
| 42 | set { myExecuteInParallel = value; }
|
---|
| 43 | }
|
---|
[1667] | 44 |
|
---|
| 45 | [Storable]
|
---|
[2] | 46 | private List<IOperation> myOperations;
|
---|
[776] | 47 | /// <summary>
|
---|
| 48 | /// Gets all current operations.
|
---|
| 49 | /// <note type="caution"> Operations are read-only!</note>
|
---|
| 50 | /// </summary>
|
---|
[2] | 51 | public IList<IOperation> Operations {
|
---|
| 52 | get { return myOperations.AsReadOnly(); }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[776] | 55 | /// <summary>
|
---|
| 56 | /// Initializes a new instance of <see cref="CompositeOperation"/>, the <see cref="ExecuteInParallel"/>
|
---|
| 57 | /// property set to <c>false</c>.
|
---|
| 58 | /// </summary>
|
---|
[2] | 59 | public CompositeOperation() {
|
---|
| 60 | myOperations = new List<IOperation>();
|
---|
| 61 | myExecuteInParallel = false;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[776] | 64 | /// <summary>
|
---|
| 65 | /// Adds an operation to the current list of operations.
|
---|
| 66 | /// </summary>
|
---|
| 67 | /// <param name="operation">The operation to add.</param>
|
---|
[2] | 68 | public void AddOperation(IOperation operation) {
|
---|
| 69 | myOperations.Add(operation);
|
---|
| 70 | }
|
---|
[776] | 71 | /// <summary>
|
---|
| 72 | /// Removes an operation from the current list.
|
---|
| 73 | /// </summary>
|
---|
| 74 | /// <param name="operation">The operation to remove.</param>
|
---|
[2] | 75 | public void RemoveOperation(IOperation operation) {
|
---|
| 76 | myOperations.Remove(operation);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[776] | 79 | /// <summary>
|
---|
| 80 | /// Clones the current instance of <see cref="CompositeOperation"/> (deep clone).
|
---|
| 81 | /// </summary>
|
---|
| 82 | /// <remarks>All operations of the current instance are cloned, too (deep clone), with the
|
---|
| 83 | /// <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of the class <see cref="Auxiliary"/>.</remarks>
|
---|
| 84 | /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
|
---|
| 85 | /// <returns>The cloned operation as <see cref="CompositeOperation"/>.</returns>
|
---|
[2] | 86 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
| 87 | CompositeOperation clone = new CompositeOperation();
|
---|
| 88 | clonedObjects.Add(Guid, clone);
|
---|
| 89 | clone.myExecuteInParallel = ExecuteInParallel;
|
---|
| 90 | for (int i = 0; i < Operations.Count; i++)
|
---|
| 91 | clone.AddOperation((IOperation)Auxiliary.Clone(Operations[i], clonedObjects));
|
---|
| 92 | return clone;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|