[6475] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[8603] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6475] | 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 |
|
---|
[8886] | 22 | using System.ComponentModel;
|
---|
[6475] | 23 | using System.Text;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Encodings.ScheduleEncoding {
|
---|
| 29 | [Item("Job", "Represents a composition of tasks that require processing in a scheduling problem.")]
|
---|
| 30 | [StorableClass]
|
---|
[8886] | 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 | }
|
---|
[6475] | 41 |
|
---|
[8886] | 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 |
|
---|
[6475] | 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() {
|
---|
[8886] | 77 | DueDate = dueDate;
|
---|
[6475] | 78 | Index = index;
|
---|
| 79 | Tasks = new ItemList<Task>();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | public override string ToString() {
|
---|
[8886] | 83 | var sb = new StringBuilder();
|
---|
[6475] | 84 | sb.Append("Job#" + Index + " [ ");
|
---|
| 85 | foreach (Task t in Tasks) {
|
---|
| 86 | sb.Append(t.ToString() + " ");
|
---|
| 87 | }
|
---|
[7116] | 88 | sb.Append("{" + DueDate + "} ");
|
---|
[6475] | 89 | sb.Append("]");
|
---|
| 90 | return sb.ToString();
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | internal Task GetPreviousTask(Task t) {
|
---|
[8886] | 94 | if (t.TaskNr == 0) return null;
|
---|
| 95 | return Tasks[t.TaskNr - 1];
|
---|
[6475] | 96 | }
|
---|
| 97 |
|
---|
[8886] | 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 | }
|
---|
[6475] | 103 | }
|
---|
| 104 | }
|
---|