Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HL-3.2-MonoMigration/HeuristicLab.Scheduling.JSSP/ScheduleInjector.cs @ 2396

Last change on this file since 2396 was 361, checked in by mkofler, 16 years ago

Set default timespan in the ScheduleInjector to Int32.MaxVal. Fixed issue with overwritten time slots (occurred when the processing time was zero).

File size: 3.2 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;
27using HeuristicLab.Data;
28
29namespace HeuristicLab.Scheduling.JSSP {
30  public class ScheduleInjector : OperatorBase {
31    public override string Description {
32      get { return @"TODO\r\nOperator description still missing ..."; }
33    }
34
35    private Schedule schedule;
36    public Schedule Schedule {
37      get { return schedule; }
38    }
39
40    public ScheduleInjector()
41      : base() {
42      AddVariableInfo(new VariableInfo("Machines", "Number of machines", typeof(IntData), VariableKind.In));
43      AddVariableInfo(new VariableInfo("Timespan", "Desired timespan for the schedule", typeof(IntData), VariableKind.In));
44      GetVariableInfo("Timespan").Local = true;
45      AddVariable(new Variable("Timespan", new IntData(Int32.MaxValue)));
46      AddVariableInfo(new VariableInfo("Schedule", "Schedule", typeof(Schedule), VariableKind.New));
47    }
48
49    public override IOperation Apply(IScope scope) {
50      IntData machines = GetVariableValue<IntData>("Machines", scope, true);
51      IntData timespan = GetVariableValue<IntData>("Timespan", scope, true);
52      schedule = new Schedule(machines.Data, timespan.Data);
53      scope.AddVariable(new Variable(scope.TranslateName("Schedule"), schedule));
54      return null;
55    }
56
57    public override object Clone(IDictionary<Guid, object> clonedObjects) {
58      ScheduleInjector clone = (ScheduleInjector)base.Clone(clonedObjects);
59      if(schedule != null) {
60        clone.schedule = (Schedule)Auxiliary.Clone(schedule, clonedObjects);
61      }
62      return clone;
63    }
64
65    #region IStorable Members
66    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
67      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
68      if(schedule != null) {
69        node.AppendChild(PersistenceManager.Persist("Schedule", schedule, document, persistedObjects));
70      }
71      return node;
72    }
73    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
74      base.Populate(node, restoredObjects);
75      XmlNode scheduleNode = node.SelectSingleNode("Schedule");
76      if(scheduleNode != null) {
77        schedule = (Schedule)PersistenceManager.Restore(scheduleNode, restoredObjects);
78      }
79    }
80    #endregion
81
82  }
83}
Note: See TracBrowser for help on using the repository browser.