[14333] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 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 |
|
---|
[16901] | 22 | using HEAL.Attic;
|
---|
[14333] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[16901] | 25 | using System;
|
---|
[14333] | 26 |
|
---|
| 27 | namespace HeuristicLab.GoalSeeking {
|
---|
| 28 | [Item("GoalParameter", "An object describing a tunable parameter used in goal seeking.")]
|
---|
[16901] | 29 | [StorableType("493140D6-5DA2-40AD-97C9-86CDCA72CDA7")]
|
---|
[14333] | 30 | public class GoalParameter : NamedItem {
|
---|
| 31 | [Storable]
|
---|
| 32 | private double goal;
|
---|
| 33 | public double Goal {
|
---|
| 34 | get { return goal; }
|
---|
| 35 | set {
|
---|
[14338] | 36 | if (double.IsNaN(value) || double.IsInfinity(value)) return;
|
---|
[14333] | 37 | if (goal.IsAlmost(value)) return;
|
---|
| 38 | goal = value;
|
---|
| 39 | OnChanged(this, EventArgs.Empty);
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | [Storable]
|
---|
| 44 | private double weight;
|
---|
| 45 | public double Weight {
|
---|
| 46 | get { return weight; }
|
---|
| 47 | set {
|
---|
[14338] | 48 | if (double.IsNaN(value) || double.IsInfinity(value)) return;
|
---|
[14333] | 49 | if (weight.IsAlmost(value)) return;
|
---|
| 50 | weight = value;
|
---|
| 51 | OnChanged(this, EventArgs.Empty);
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | [Storable]
|
---|
| 56 | private double variance;
|
---|
| 57 |
|
---|
| 58 | public double Variance {
|
---|
| 59 | get { return variance; }
|
---|
| 60 | set {
|
---|
[14338] | 61 | if (double.IsNaN(value) || double.IsInfinity(value)) return;
|
---|
[14333] | 62 | if (variance.IsAlmost(value)) return;
|
---|
| 63 | variance = value;
|
---|
| 64 | OnChanged(this, EventArgs.Empty);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | [Storable]
|
---|
| 69 | private double step;
|
---|
| 70 | public double Step {
|
---|
| 71 | get { return step; }
|
---|
| 72 | set {
|
---|
[14338] | 73 | if (double.IsNaN(value) || double.IsInfinity(value)) return;
|
---|
[14333] | 74 | if (step.IsAlmost(value)) return;
|
---|
| 75 | step = value;
|
---|
| 76 | OnChanged(this, EventArgs.Empty);
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | [Storable]
|
---|
| 81 | private bool active;
|
---|
| 82 | public bool Active {
|
---|
| 83 | get { return active; }
|
---|
| 84 | set {
|
---|
| 85 | if (active == value) return;
|
---|
| 86 | active = value;
|
---|
| 87 | OnChanged(this, EventArgs.Empty);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public override string ToString() {
|
---|
| 92 | return string.Format("{0} [active: {1}; goal: {2}; weight: {3}; variance: {4}; step: {5}", Name, Active, Goal, Weight, Variance, Step);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | protected GoalParameter(GoalParameter original, Cloner cloner) : base(original, cloner) {
|
---|
| 96 | name = original.name;
|
---|
| 97 | goal = original.goal;
|
---|
| 98 | weight = original.weight;
|
---|
| 99 | variance = original.variance;
|
---|
| 100 | step = original.step;
|
---|
| 101 | active = original.active;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 105 | return new GoalParameter(this, cloner);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | [StorableConstructor]
|
---|
[16901] | 109 | protected GoalParameter(StorableConstructorFlag _) : base(_) { }
|
---|
[14333] | 110 |
|
---|
| 111 | public GoalParameter(string name, double goal, double weight, double variance, double step, bool active = true) {
|
---|
| 112 | this.name = name;
|
---|
| 113 | this.goal = goal;
|
---|
| 114 | this.weight = weight;
|
---|
| 115 | this.variance = variance;
|
---|
| 116 | this.step = step;
|
---|
| 117 | this.active = active;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | public event EventHandler Changed;
|
---|
| 121 | private void OnChanged(object sender, EventArgs args) {
|
---|
| 122 | var changed = Changed;
|
---|
| 123 | if (changed == null) return;
|
---|
| 124 | changed(sender, args);
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 | } |
---|