Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13435 was 13435, checked in by mkommend, 8 years ago

#2521: Intermediate version of schedule encoding refactoring.

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    //TODO why does a Ressource has a duration?
39    public double TotalDuration {
40      get {
41        if (Tasks.Count == 0) return 0.0;
42        return Tasks.Max(t => t.EndTime);
43      }
44    }
45
46    [StorableConstructor]
47    private Resource(bool deserializing) : base(deserializing) { }
48    private Resource(Resource original, Cloner cloner)
49      : base(original, cloner) {
50      this.Index = original.Index;
51      this.Tasks = cloner.Clone(original.Tasks);
52    }
53    public Resource(int index)
54      : base() {
55      Index = index;
56      Tasks = new ItemList<ScheduledTask>();
57    }
58
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new Resource(this, cloner);
61    }
62
63    public override string ToString() {
64      StringBuilder sb = new StringBuilder();
65      sb.Append("Resource#" + Index + " [ ");
66      foreach (ScheduledTask t in Tasks) {
67        sb.Append(t + " ");
68      }
69      sb.Append("]");
70      return sb.ToString();
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.