Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.SimOpt/SimOptProblemInjector.cs @ 3508

Last change on this file since 3508 was 592, checked in by abeham, 16 years ago

Put the GPL license in the files from the communication framework and simulation optimization project (branch 3.1)

File size: 4.4 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.Linq;
25using System.Text;
26using System.Xml;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29
30namespace HeuristicLab.SimOpt {
31  public class SimOptProblemInjector : OperatorBase {
32
33    public override string Description {
34      get { return @"Injects the parameters used for simulation parameter optimization"; }
35    }
36
37    private BoolData myMaximization;
38    public BoolData Maximization {
39      get { return myMaximization; }
40      set { myMaximization = value; }
41    }
42
43    private StringData myGeneName;
44    public StringData GeneName {
45      get { return myGeneName; }
46      set { myGeneName = value; }
47    }
48
49    private ConstrainedItemList myParameters;
50    public ConstrainedItemList Parameters {
51      get { return myParameters; }
52      set { myParameters = value; }
53    }
54
55    public SimOptProblemInjector()
56      : base() {
57      myParameters = new ConstrainedItemList();
58      myGeneName = new StringData("Items");
59      myMaximization = new BoolData(false);
60    }
61
62    public override IOperation Apply(IScope scope) {
63      scope.AddVariable(new Variable("Maximization", (BoolData)Maximization.Clone()));
64      scope.AddVariable(new Variable(myGeneName.Data, (ConstrainedItemList)Parameters.Clone()));
65      return null;
66    }
67
68    public override IView CreateView() {
69      return new SimOptProblemInjectorView(this);
70    }
71
72    #region Clone & Persistence Methods
73    public override object Clone(IDictionary<Guid, object> clonedObjects) {
74      SimOptProblemInjector clone = new SimOptProblemInjector();
75      clonedObjects.Add(Guid, clone);
76      clone.Maximization = (BoolData)myMaximization.Clone(clonedObjects);
77      clone.GeneName = (StringData)myGeneName.Clone(clonedObjects);
78      clone.myParameters = (ConstrainedItemList)myParameters.Clone(clonedObjects);
79      return clone;
80    }
81
82    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
83      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
84      // variable infos should not be persisted
85      XmlNode infosNode = node.SelectSingleNode("VariableInfos");
86      infosNode.RemoveAll();
87      XmlNode maxNode = PersistenceManager.Persist("Maximization", Maximization, document, persistedObjects);
88      node.AppendChild(maxNode);
89      XmlNode nameNode = PersistenceManager.Persist("GeneName", GeneName, document, persistedObjects);
90      node.AppendChild(nameNode);
91      XmlNode parametersNode = PersistenceManager.Persist("Items", Parameters, document, persistedObjects);
92      node.AppendChild(parametersNode);
93      return node;
94    }
95
96    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
97      base.Populate(node, restoredObjects);
98      if (node.SelectSingleNode("Maximization") != null) {
99        myMaximization = (BoolData)PersistenceManager.Restore(node.SelectSingleNode("Maximization"), restoredObjects);
100      }
101      if (node.SelectSingleNode("GeneName") != null) {
102        myGeneName = (StringData)PersistenceManager.Restore(node.SelectSingleNode("GeneName"), restoredObjects);
103      }
104      IStorable items = (ConstrainedItemList)PersistenceManager.Restore(node.SelectSingleNode("Items"), restoredObjects);
105      try {
106        myParameters = (ConstrainedItemList)items;
107      } catch (InvalidCastException ice) {
108        IVariable var = (Variable)items;
109        myParameters = (ConstrainedItemList)var.Value;
110      }
111    }
112    #endregion
113  }
114}
Note: See TracBrowser for help on using the repository browser.