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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using System.Xml;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 |
|
---|
28 | namespace 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 | public override void Populate(XmlReader reader, IDictionary<Guid, IStorable> restoredObjects) {
|
---|
88 | int machines = int.Parse(reader["Machines"]);
|
---|
89 | base.Populate(reader, restoredObjects);
|
---|
90 | schedule = new ScheduleTree[machines];
|
---|
91 | for(int i = 0; i < machines; i++) {
|
---|
92 | schedule[i] = (ScheduleTree)PersistenceManager.Restore(reader, "Machine" + i.ToString(), restoredObjects);
|
---|
93 | reader.Skip();
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
98 | int timespan = 0;
|
---|
99 | if ((schedule != null) && (schedule.Length > 0)) {
|
---|
100 | timespan = schedule[0].Timespan;
|
---|
101 | }
|
---|
102 | Schedule clone = new Schedule(this.Machines, timespan);
|
---|
103 | clonedObjects.Add(Guid, clone);
|
---|
104 | clone.schedule = new ScheduleTree[this.Machines];
|
---|
105 | for(int i = 0; i < this.Machines; i++) {
|
---|
106 | clone.schedule[i] = (ScheduleTree)Auxiliary.Clone(schedule[i], clonedObjects);
|
---|
107 | }
|
---|
108 | return clone;
|
---|
109 | }
|
---|
110 |
|
---|
111 | #endregion
|
---|
112 | }
|
---|
113 | }
|
---|