Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Job.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.6 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.Data;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.Scheduling {
29  [Item("Job Class", "Represents a composition of tasks that require processing in a scheduling problem.")]
30  [StorableClass]
31  public class Job : Item {
32    [Storable]
33    public DoubleValue DueDate { get; set; }
34    [Storable]
35    public IntValue Index { get; set; }
36    [Storable]
37    public ItemList<Task> Tasks { get; set; }
38
39    [StorableConstructor]
40    protected Job(bool deserializing) : base(deserializing) { }
41    protected Job(Job original, Cloner cloner)
42      : base(original, cloner) {
43      this.DueDate = cloner.Clone(original.DueDate);
44      this.Index = cloner.Clone(original.Index);
45      this.Tasks = cloner.Clone(original.Tasks);
46    }
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new Job(this, cloner);
49    }
50    public Job(IntValue index, DoubleValue dueDate)
51      : base() {
52      Index = index;
53      Tasks = new ItemList<Task>();
54
55      if (dueDate != null)
56        DueDate = (DoubleValue)dueDate.Clone();
57      else
58        DueDate = null;
59    }
60
61    public override string ToString() {
62      StringBuilder sb = new StringBuilder();
63      sb.Append("Job#" + Index + " [ ");
64      foreach (Task t in Tasks) {
65        sb.Append(t.ToString() + " ");
66      }
67      if (DueDate != null)
68        sb.Append("{" + DueDate.Value + "} ");
69      sb.Append("]");
70      return sb.ToString();
71    }
72
73    internal Task GetPreviousTask(Task t) {
74      if (t.TaskNr.Value == 0)
75        return null;
76      else
77        return Tasks[t.TaskNr.Value - 1];
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.