Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1329: Applied suggestions from codereview. Added unit-tests. Renamed encoding-project.

File size: 2.4 KB
RevLine 
[6406]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.Data;
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 class Resource : Item {
32    public Resource(int index)
33      : base() {
34      Index = index;
35      Tasks = new ItemList<ScheduledTask>();
36    }
37    [Storable]
38    public int Index {
39      get;
40      set;
41    }
42    [Storable]
43    public ItemList<ScheduledTask> Tasks {
44      get;
45      set;
46    }
47    public DoubleValue TotalDuration {
48      get {
49        double result = 0;
50        foreach (ScheduledTask t in Tasks) {
51          if (t.EndTime.Value > result)
52            result = t.EndTime.Value;
53        }
54        return new DoubleValue(result);
55      }
56    }
57
58    [StorableConstructor]
59    protected Resource(bool deserializing) : base(deserializing) { }
60    protected Resource(Resource original, Cloner cloner)
61      : base(original, cloner) {
62      this.Index = original.Index;
63      this.Tasks = cloner.Clone(original.Tasks);
64    }
65    public override IDeepCloneable Clone(Cloner cloner) {
66      return new Resource(this, cloner);
67    }
68
69    public override string ToString() {
70      StringBuilder sb = new StringBuilder();
71      sb.Append("Resource#" + Index + " [ ");
72      foreach (ScheduledTask t in Tasks) {
73        sb.Append(t.ToString() + " ");
74      }
75      sb.Append("]");
76      return sb.ToString();
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.