#region License Information /* HeuristicLab * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Collections.Generic; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.GP.Interfaces; using System.Xml; namespace HeuristicLab.GP.StructureIdentification.Networks { public class OpenParameterFunctionTree : TerminalTreeNode { public string VariableName { get; set; } public int SampleOffset { get; set; } public OpenParameterFunctionTree(OpenParameter openParameter) : base(openParameter) { } protected OpenParameterFunctionTree(OpenParameterFunctionTree original) : base(original) { VariableName = original.VariableName; SampleOffset = original.SampleOffset; } public override bool HasLocalParameters { get { return true; } } public override IOperation CreateShakingOperation(IScope scope) { Scope myVariableScope = new Scope(); scope.AddSubScope(myVariableScope); myVariableScope.AddVariable(CreateSampleOffsetVariable()); return new AtomicOperation(Function.Manipulator, myVariableScope); } public override IOperation CreateInitOperation(IScope scope) { Scope myVariableScope = new Scope(); scope.AddSubScope(myVariableScope); myVariableScope.AddVariable(CreateSampleOffsetVariable()); return new AtomicOperation(Function.Initializer, myVariableScope); } public override string ToString() { return SymbolicExpressionExporter.GetName(this); } #region serialization public override object Clone() { return new OpenParameterFunctionTree(this); } public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary persistedObjects) { XmlNode node = document.CreateElement(name); XmlAttribute variableAttr = document.CreateAttribute("Variable"); variableAttr.Value = VariableName; XmlAttribute sampleOffsetAttr = document.CreateAttribute("SampleOffset"); sampleOffsetAttr.Value = XmlConvert.ToString(SampleOffset); node.Attributes.Append(sampleOffsetAttr); node.Attributes.Append(variableAttr); return node; } public override void Populate(XmlNode node, IDictionary restoredObjects) { base.Populate(node, restoredObjects); SampleOffset = XmlConvert.ToInt32(node.Attributes["SampleOffset"].Value); VariableName = node.Attributes["Variable"].Value; } #endregion private IVariable CreateSampleOffsetVariable() { IntData data = new IntData(SampleOffset); data.Changed += (sender, args) => SampleOffset = data.Data; var variable = new HeuristicLab.Core.Variable(Variable.OFFSET, data); variable.ValueChanged += (sender, args) => SampleOffset = ((IntData)variable.Value).Data; return variable; } private IVariable CreateVariableNameVariable() { StringData data = new StringData(VariableName); data.Changed += (sender, args) => VariableName = data.Data; var variable = new HeuristicLab.Core.Variable(Variable.VARIABLENAME, data); variable.ValueChanged += (sender, args) => VariableName = ((StringData)variable.Value).Data; return variable; } } }