Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Resource.cs @ 6414

Last change on this file since 6414 was 6412, checked in by jhelm, 13 years ago

#1329: Did some minor changes affecting datatypes.

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