Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.Scheduling.JSSP/Schedule.cs @ 7102

Last change on this file since 7102 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 3.5 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 HeuristicLab.Core;
27
28namespace HeuristicLab.Scheduling.JSSP {
29  public class Schedule : ItemBase {
30
31    private ScheduleTree[] schedule;
32
33    public Schedule(int nrOfMachines, int timeSpan)
34      : base() {
35      schedule = new ScheduleTree[nrOfMachines];
36      for(int i = 0; i < nrOfMachines; i++) {
37        schedule[i] = new ScheduleTree(timeSpan);
38      }
39    }
40
41    public Schedule() : this(0, 100) { }
42
43    public int Machines {
44      get { return schedule.Length; }
45    }
46
47    public ScheduleTree GetMachineSchedule(int machineIndex) {
48      return schedule[machineIndex];
49    }
50
51    // return value: operation completion time
52    public int ScheduleOperation(Operation op) {
53      int machine = op.Machines[0];
54      return schedule[machine].Insert(op);
55    }
56
57    public override string ToString() {
58      string s = "";
59      for(int i = 0; i < this.Machines; i++) {
60        s += schedule[i].ToString();
61        s += "\n";
62      }
63      return s;
64    }
65
66    #region IStorable Members
67
68    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
69      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
70      XmlAttribute machineAttribute = document.CreateAttribute("Machines");
71      machineAttribute.Value = Machines.ToString();
72      node.Attributes.Append(machineAttribute);
73      for(int i = 0; i < Machines; i++) {
74        node.AppendChild(PersistenceManager.Persist("Machine" + i.ToString(), schedule[i], document, persistedObjects));
75      }
76      return node;
77    }
78
79    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
80      base.Populate(node, restoredObjects);
81      int machines = int.Parse(node.Attributes["Machines"].Value);
82      schedule = new ScheduleTree[machines];
83      for(int i = 0; i < machines; i++) {
84        schedule[i] = (ScheduleTree)PersistenceManager.Restore(node.SelectSingleNode("Machine" + i.ToString()), restoredObjects);
85      }
86    }
87
88    public override object Clone(IDictionary<Guid, object> clonedObjects) {
89      int timespan = 0;
90      if ((schedule != null) && (schedule.Length > 0)) {
91        timespan = schedule[0].Timespan;
92      }
93      Schedule clone = new Schedule(this.Machines, timespan);
94      clonedObjects.Add(Guid, clone);
95      clone.schedule = new ScheduleTree[this.Machines];
96      for(int i = 0; i < this.Machines; i++) {
97        clone.schedule[i] = (ScheduleTree)Auxiliary.Clone(schedule[i], clonedObjects);
98      }
99      return clone;
100    }
101
102    #endregion
103  }
104}
Note: See TracBrowser for help on using the repository browser.