Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Resource.cs @ 10479

Last change on this file since 10479 was 10476, checked in by gkronber, 11 years ago

#2127: removed Equals() and GetHashCode() overrides as well as related static methods.
Changed ctors of Task and Job to prevent calling virtual members.

File size: 2.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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
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    }
50    public Resource(int index)
51      : base() {
52      Index = index;
53      Tasks = new ItemList<ScheduledTask>();
54    }
55
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new Resource(this, cloner);
58    }
59
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
71    public override string ToString() {
72      StringBuilder sb = new StringBuilder();
73      sb.Append("Resource#" + Index + " [ ");
74      foreach (ScheduledTask t in Tasks) {
75        sb.Append(t+ " ");
76      }
77      sb.Append("]");
78      return sb.ToString();
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.