Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.Scheduling.JSSP/Operation.cs @ 988

Last change on this file since 988 was 2, checked in by swagner, 16 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 5.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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;
23using System.Collections.Generic;
24using System.Text;
25using System.Xml;
26using System.Collections;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29
30namespace HeuristicLab.Scheduling.JSSP {
31  public class Operation : ItemBase, IComparable {
32
33    #region Data
34    private IntData start;
35    public int Start {
36      get { return start.Data; }
37      set {
38        start.Data = value;
39        OnChanged();
40      }
41    }
42
43    private IntData duration;
44    public int Duration {
45      get { return duration.Data; }
46      set {
47        duration.Data = value;
48        OnChanged();
49      }
50    }
51
52    private IntData job;
53    public int Job {
54      get { return job.Data; }
55      set {
56        job.Data = value;
57        OnChanged();
58      }
59    }
60
61    private IntData operationIndex;
62    public int OperationIndex {
63      get { return operationIndex.Data; }
64      set { operationIndex.Data = value; }
65    }
66
67    private IntArrayData machines;
68    public int[] Machines {
69      get { return machines.Data; }
70      set {
71        machines.Data = value;
72        OnChanged();
73      }
74    }
75
76    private ItemList predecessors;
77    public ItemList Predecessors {
78      get { return predecessors; }
79      set { predecessors = value; }
80    }
81    #endregion
82
83    public Operation()
84      : this(-1, 0, 0, -1, new int[0], null) {
85    }
86
87    public Operation(int job, int earliestStart, int duration, int operationIndex, int[] machines, int[] predecessors) {
88      this.start = new IntData(earliestStart);
89      this.duration = new IntData(duration);
90      this.job = new IntData(job);
91      this.machines = new IntArrayData(machines);
92      this.predecessors = new ItemList();
93      if(predecessors != null) {
94        for(int i = 0; i < predecessors.Length; i++) {
95          this.predecessors.Add(new IntData(predecessors[i]));
96        }
97      }
98      this.operationIndex = new IntData(operationIndex);
99    }
100
101    public override string ToString() {
102      if(this.Job == -1) {
103        return "";
104      }
105      return (String.Format("|{2},{3}:[m:{0} d:{1}]", machines.Data[0], duration, job, operationIndex));
106    }
107
108    #region IComparable Members
109
110    public int CompareTo(object obj) {
111      if(obj is Operation) {
112        Operation bin = (Operation)obj;
113        return (start.CompareTo(bin.start));
114      } else { throw new ArgumentException("Object is not an Operation"); }
115    }
116
117    #endregion
118
119    #region IViewable Members
120
121    public override IView CreateView() {
122      return new OperationView(this);
123    }
124
125    #endregion
126
127    #region IStorable Members
128
129    public override object Clone(IDictionary<Guid, object> clonedObjects) {
130      Operation clone = new Operation();
131      clonedObjects.Add(Guid, clone);
132      clone.duration = (IntData)Auxiliary.Clone(duration, clonedObjects);
133      clone.start = (IntData)Auxiliary.Clone(start, clonedObjects);
134      clone.operationIndex = (IntData)Auxiliary.Clone(operationIndex, clonedObjects);
135      clone.job = (IntData)Auxiliary.Clone(job, clonedObjects);
136      clone.machines = (IntArrayData)Auxiliary.Clone(machines, clonedObjects);
137      clone.predecessors = (ItemList)Auxiliary.Clone(predecessors, clonedObjects);
138      return clone;
139    }
140
141    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
142      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
143      node.AppendChild(PersistenceManager.Persist("Job", job, document, persistedObjects));
144      node.AppendChild(PersistenceManager.Persist("OperationIndex", operationIndex, document, persistedObjects));
145      node.AppendChild(PersistenceManager.Persist("Start", start, document, persistedObjects));
146      node.AppendChild(PersistenceManager.Persist("Duration", duration, document, persistedObjects));
147      node.AppendChild(PersistenceManager.Persist("Predecessors", predecessors, document, persistedObjects));
148      node.AppendChild(PersistenceManager.Persist("Machines", machines, document, persistedObjects));
149      return node;
150    }
151
152    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
153      base.Populate(node, restoredObjects);
154      job = (IntData)PersistenceManager.Restore(node.SelectSingleNode("Job"), restoredObjects);
155      operationIndex = (IntData)PersistenceManager.Restore(node.SelectSingleNode("OperationIndex"), restoredObjects);
156      start = (IntData)PersistenceManager.Restore(node.SelectSingleNode("Start"), restoredObjects);
157      duration = (IntData)PersistenceManager.Restore(node.SelectSingleNode("Duration"), restoredObjects);
158      predecessors = (ItemList)PersistenceManager.Restore(node.SelectSingleNode("Predecessors"), restoredObjects);
159      machines = (IntArrayData)PersistenceManager.Restore(node.SelectSingleNode("Machines"), restoredObjects);
160    }
161
162    #endregion
163  }
164}
Note: See TracBrowser for help on using the repository browser.