#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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 HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Core; using System; namespace HeuristicLab.GoalSeeking { [Item("GoalParameter", "An object describing a tunable parameter used in goal seeking.")] [StorableType("493140D6-5DA2-40AD-97C9-86CDCA72CDA7")] public class GoalParameter : NamedItem { [Storable] private double goal; public double Goal { get { return goal; } set { if (double.IsNaN(value) || double.IsInfinity(value)) return; if (goal.IsAlmost(value)) return; goal = value; OnChanged(this, EventArgs.Empty); } } [Storable] private double weight; public double Weight { get { return weight; } set { if (double.IsNaN(value) || double.IsInfinity(value)) return; if (weight.IsAlmost(value)) return; weight = value; OnChanged(this, EventArgs.Empty); } } [Storable] private double variance; public double Variance { get { return variance; } set { if (double.IsNaN(value) || double.IsInfinity(value)) return; if (variance.IsAlmost(value)) return; variance = value; OnChanged(this, EventArgs.Empty); } } [Storable] private double step; public double Step { get { return step; } set { if (double.IsNaN(value) || double.IsInfinity(value)) return; if (step.IsAlmost(value)) return; step = value; OnChanged(this, EventArgs.Empty); } } [Storable] private bool active; public bool Active { get { return active; } set { if (active == value) return; active = value; OnChanged(this, EventArgs.Empty); } } public override string ToString() { return string.Format("{0} [active: {1}; goal: {2}; weight: {3}; variance: {4}; step: {5}", Name, Active, Goal, Weight, Variance, Step); } protected GoalParameter(GoalParameter original, Cloner cloner) : base(original, cloner) { name = original.name; goal = original.goal; weight = original.weight; variance = original.variance; step = original.step; active = original.active; } public override IDeepCloneable Clone(Cloner cloner) { return new GoalParameter(this, cloner); } [StorableConstructor] protected GoalParameter(StorableConstructorFlag _) : base(_) { } public GoalParameter(string name, double goal, double weight, double variance, double step, bool active = true) { this.name = name; this.goal = goal; this.weight = weight; this.variance = variance; this.step = step; this.active = active; } public event EventHandler Changed; private void OnChanged(object sender, EventArgs args) { var changed = Changed; if (changed == null) return; changed(sender, args); } } }