source: branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Resource.cs @ 13436

Last change on this file since 13436 was 13436, checked in by mkommend, 5 years ago

#2521: Minor improvements in SchedulingEncoding.

File size: 2.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using System.Linq;
23using System.Text;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Encodings.ScheduleEncoding {
29  [Item("ResourceClass", "Represents a resource used in scheduling problems.")]
30  [StorableClass]
31  public sealed class Resource : Item {
32
33    [Storable]
34    public int Index { get; private set; }
35    [Storable]
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      }
43    }
44
45    [StorableConstructor]
46    private Resource(bool deserializing) : base(deserializing) { }
47    private Resource(Resource original, Cloner cloner)
48      : base(original, cloner) {
49      this.Index = original.Index;
50      this.Tasks = cloner.Clone(original.Tasks);
51    }
52    public Resource(int index)
53      : base() {
54      Index = index;
55      Tasks = new ItemList<ScheduledTask>();
56    }
57
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) {
66        sb.Append(t + " ");
67      }
68      sb.Append("]");
69      return sb.ToString();
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.