Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.Scheduling.JSSP/ScheduleInjector.cs @ 9173

Last change on this file since 9173 was 77, checked in by swagner, 17 years ago

Fixed ticket #67

  • adapted accessing of variables in operators due to changes of variable lookup and the new name aliasing mechanism (actual/formal name translations should not be done directly anymore; instead the new method Scope.TranslateName should be used)
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(10000)));
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.