Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.Scheduling.JSSP/JSSPInjector.cs @ 11700

Last change on this file since 11700 was 120, checked in by gkronber, 17 years ago

fixed a typo that caused an error in save/restore of operator JSSPInjector

File size: 4.0 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.Operators;
28using HeuristicLab.Data;
29
30namespace HeuristicLab.Scheduling.JSSP {
31  public class JSSPInjector : OperatorBase {
32    public override string Description {
33      get { return @"TODO\r\nOperator description still missing ..."; }
34    }
35
36    private ItemList operations;
37    public ItemList Operations {
38      get { return operations; }
39      set { operations = value; }
40    }
41
42    private IntData machines;
43    public int NrOfMachines {
44      get { return machines.Data; }
45      set { machines.Data = value; }
46    }
47    private IntData jobs;
48    public int NrOfJobs {
49      get { return jobs.Data; }
50      set { jobs.Data = value; }
51    }
52
53    public JSSPInjector()
54      : base() {
55      operations = new ItemList();
56      machines = new IntData();
57      jobs = new IntData();
58      AddVariableInfo(new VariableInfo("Machines", "Number of machines", typeof(IntData), VariableKind.New));
59      AddVariableInfo(new VariableInfo("Jobs", "Number of jobs", typeof(IntData), VariableKind.New));
60      AddVariableInfo(new VariableInfo("Operations", "List of JSSP operations", typeof(ItemList), VariableKind.New));
61    }
62
63    public override IView CreateView() {
64      return new JSSPInjectorView(this);
65    }
66
67    public override IOperation Apply(IScope scope) {
68      scope.AddVariable(new Variable(scope.TranslateName("Machines"), machines.Clone() as IntData));
69      scope.AddVariable(new Variable(scope.TranslateName("Jobs"), jobs.Clone() as IntData));
70      scope.AddVariable(new Variable(scope.TranslateName("Operations"), (ItemList)operations.Clone()));
71      return base.Apply(scope);
72    }
73
74    public override object Clone(IDictionary<Guid, object> clonedObjects) {
75      JSSPInjector clone = (JSSPInjector)base.Clone(clonedObjects);
76      clone.operations = (ItemList)Auxiliary.Clone(operations, clonedObjects);
77      clone.jobs = (IntData)Auxiliary.Clone(jobs, clonedObjects);
78      clone.machines = (IntData)Auxiliary.Clone(machines, clonedObjects);
79      return clone;
80    }
81
82    #region IStorable Members
83    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
84      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
85      node.AppendChild(PersistenceManager.Persist("Machines", machines, document, persistedObjects));
86      node.AppendChild(PersistenceManager.Persist("Jobs", jobs, document, persistedObjects));
87      node.AppendChild(PersistenceManager.Persist("Operations", operations, document, persistedObjects));
88      return node;
89    }
90    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
91      base.Populate(node, restoredObjects);
92      operations = (ItemList)PersistenceManager.Restore(node.SelectSingleNode("Operations"), restoredObjects);
93      jobs = (IntData)PersistenceManager.Restore(node.SelectSingleNode("Jobs"), restoredObjects);
94      machines = (IntData)PersistenceManager.Restore(node.SelectSingleNode("Machines"), restoredObjects);
95    }
96    #endregion
97  }
98}
Note: See TracBrowser for help on using the repository browser.