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