[6406] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6406] | 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 |
|
---|
[13435] | 22 | using System.Linq;
|
---|
[6406] | 23 | using System.Text;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Encodings.ScheduleEncoding {
|
---|
| 29 | [Item("ResourceClass", "Represents a resource used in scheduling problems.")]
|
---|
| 30 | [StorableClass]
|
---|
[13435] | 31 | public sealed class Resource : Item {
|
---|
[8887] | 32 |
|
---|
[6406] | 33 | [Storable]
|
---|
[13435] | 34 | public int Index { get; private set; }
|
---|
[6406] | 35 | [Storable]
|
---|
[13435] | 36 | public ItemList<ScheduledTask> Tasks { get; private set; }
|
---|
| 37 |
|
---|
| 38 | public double TotalDuration {
|
---|
| 39 | get {
|
---|
| 40 | if (Tasks.Count == 0) return 0.0;
|
---|
| 41 | return Tasks.Max(t => t.EndTime);
|
---|
| 42 | }
|
---|
[6406] | 43 | }
|
---|
| 44 |
|
---|
| 45 | [StorableConstructor]
|
---|
[13435] | 46 | private Resource(bool deserializing) : base(deserializing) { }
|
---|
| 47 | private Resource(Resource original, Cloner cloner)
|
---|
[6406] | 48 | : base(original, cloner) {
|
---|
| 49 | this.Index = original.Index;
|
---|
| 50 | this.Tasks = cloner.Clone(original.Tasks);
|
---|
| 51 | }
|
---|
[8887] | 52 | public Resource(int index)
|
---|
| 53 | : base() {
|
---|
| 54 | Index = index;
|
---|
| 55 | Tasks = new ItemList<ScheduledTask>();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[6406] | 58 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 59 | return new Resource(this, cloner);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public override string ToString() {
|
---|
| 63 | StringBuilder sb = new StringBuilder();
|
---|
| 64 | sb.Append("Resource#" + Index + " [ ");
|
---|
| 65 | foreach (ScheduledTask t in Tasks) {
|
---|
[13435] | 66 | sb.Append(t + " ");
|
---|
[6406] | 67 | }
|
---|
| 68 | sb.Append("]");
|
---|
| 69 | return sb.ToString();
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | }
|
---|