source: trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Job.cs @ 8886

Last change on this file since 8886 was 8886, checked in by abeham, 10 years ago

#1329:

  • Removed unnecessary DueDates parameter
  • Changed ValueParameter to FixedValueParameter for Jobs and Resources
  • Made Job and Task INotifyPropertyChanged
  • Added a JobView and TaskView
File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.ComponentModel;
23using System.Text;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Encodings.ScheduleEncoding {
29  [Item("Job", "Represents a composition of tasks that require processing in a scheduling problem.")]
30  [StorableClass]
31  public class Job : Item, INotifyPropertyChanged {
32    [Storable(Name = "DueDate")] private double dueDate;
33    public double DueDate {
34      get { return dueDate; }
35      set {
36        bool changed = dueDate != value;
37        dueDate = value;
38        if (changed) OnPropertyChanged("DueDate");
39      }
40    }
41
42    [Storable(Name = "Index")]
43    private int index;
44    public int Index {
45      get { return index; }
46      set {
47        bool changed = index != value;
48        index = value;
49        if (changed) OnPropertyChanged("Index");
50      }
51    }
52
53    [Storable(Name = "Tasks")]
54    private ItemList<Task> tasks;
55    public ItemList<Task> Tasks {
56      get { return tasks; }
57      set {
58        bool changed = tasks != value;
59        tasks = value;
60        if (changed) OnPropertyChanged("Tasks");
61      }
62    }
63
64    [StorableConstructor]
65    protected Job(bool deserializing) : base(deserializing) { }
66    protected Job(Job original, Cloner cloner)
67      : base(original, cloner) {
68      this.DueDate = original.DueDate;
69      this.Index = original.Index;
70      this.Tasks = cloner.Clone(original.Tasks);
71    }
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new Job(this, cloner);
74    }
75    public Job(int index, double dueDate)
76      : base() {
77      DueDate = dueDate;
78      Index = index;
79      Tasks = new ItemList<Task>();
80    }
81
82    public override string ToString() {
83      var sb = new StringBuilder();
84      sb.Append("Job#" + Index + " [ ");
85      foreach (Task t in Tasks) {
86        sb.Append(t.ToString() + " ");
87      }
88      sb.Append("{" + DueDate + "} ");
89      sb.Append("]");
90      return sb.ToString();
91    }
92
93    internal Task GetPreviousTask(Task t) {
94      if (t.TaskNr == 0) return null;
95      return Tasks[t.TaskNr - 1];
96    }
97
98    public event PropertyChangedEventHandler PropertyChanged;
99    protected virtual void OnPropertyChanged(string propertyName) {
100      var handler = PropertyChanged;
101      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.