#region License Information /* HeuristicLab * Copyright (C) 2002-2015 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; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Random; namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction { [StorableClass] public class PredictedGlucoseVariableTreeNode : SymbolicExpressionTreeTerminalNode { public new PredictedGlucoseVariableSymbol Symbol { get { return (PredictedGlucoseVariableSymbol)base.Symbol; } } [Storable] private int rowOffset; public int RowOffset { get { return rowOffset; } set { rowOffset = value; } } [Storable] private double weight; public double Weight { get { return weight; } set { weight = value; } } [StorableConstructor] protected PredictedGlucoseVariableTreeNode(bool deserializing) : base(deserializing) { } protected PredictedGlucoseVariableTreeNode(PredictedGlucoseVariableTreeNode original, Cloner cloner) : base(original, cloner) { rowOffset = original.rowOffset; weight = original.weight; } protected PredictedGlucoseVariableTreeNode() { } public PredictedGlucoseVariableTreeNode(PredictedGlucoseVariableSymbol variableSymbol) : base(variableSymbol) { } public override bool HasLocalParameters { get { return true; } } public override void ResetLocalParameters(IRandom random) { base.ResetLocalParameters(random); rowOffset = random.Next(Symbol.MinRowOffset, Symbol.MaxRowOffset + 1); weight = NormalDistributedRandom.NextDouble(random, 0, 10); } public override void ShakeLocalParameters(IRandom random, double shakingFactor) { base.ShakeLocalParameters(random, shakingFactor); // increase or decrease offset by one rowOffset += random.NextDouble() > 0.5 ? +1 : -1; rowOffset = Math.Max(rowOffset, Symbol.MinRowOffset); rowOffset = Math.Min(rowOffset, Symbol.MaxRowOffset); weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor); } public override IDeepCloneable Clone(Cloner cloner) { return new PredictedGlucoseVariableTreeNode(this, cloner); } public override string ToString() { return string.Format("{0:N2}*predGluc(k{1})", weight, rowOffset); } } }