[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("InputParameter", "An object describing a target for the goal seeking.")]
|
---|
[16901] | 29 | [StorableType("3F8B2C70-7EF4-439C-8E5A-A770F5431E65")]
|
---|
[14333] | 30 | public class InputParameter : NamedItem {
|
---|
| 31 | [Storable]
|
---|
| 32 | private double min;
|
---|
| 33 | public double Min {
|
---|
| 34 | get { return min; }
|
---|
| 35 | set {
|
---|
[14338] | 36 | if (double.IsNaN(value) || double.IsInfinity(value)) return;
|
---|
[14333] | 37 | if (min.IsAlmost(value)) return;
|
---|
| 38 | min = value;
|
---|
| 39 | OnChanged(this, EventArgs.Empty);
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | [Storable]
|
---|
| 44 | private double max;
|
---|
| 45 | public double Max {
|
---|
| 46 | get { return max; }
|
---|
| 47 | set {
|
---|
[14338] | 48 | if (double.IsNaN(value) || double.IsInfinity(value)) return;
|
---|
[14333] | 49 | if (max.IsAlmost(value)) return;
|
---|
| 50 | max = value;
|
---|
| 51 | OnChanged(this, EventArgs.Empty);
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | [Storable]
|
---|
| 56 | private double step;
|
---|
| 57 | public double Step {
|
---|
| 58 | get { return step; }
|
---|
| 59 | set {
|
---|
[14338] | 60 | if (double.IsNaN(value) || double.IsInfinity(value)) return;
|
---|
[14333] | 61 | if (step.IsAlmost(value)) return;
|
---|
| 62 | step = value;
|
---|
| 63 | OnChanged(this, EventArgs.Empty);
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | [Storable]
|
---|
| 68 | private double value;
|
---|
| 69 | public double Value {
|
---|
| 70 | get { return value; }
|
---|
| 71 | set {
|
---|
[14338] | 72 | if (double.IsNaN(value) || double.IsInfinity(value)) return;
|
---|
[14333] | 73 | if (this.value.IsAlmost(value)) return;
|
---|
| 74 | this.value = value;
|
---|
| 75 | OnChanged(this, EventArgs.Empty);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | [Storable]
|
---|
| 80 | private bool active;
|
---|
| 81 | public bool Active {
|
---|
| 82 | get { return active; }
|
---|
| 83 | set {
|
---|
| 84 | if (active == value) return;
|
---|
| 85 | active = value;
|
---|
| 86 | OnChanged(this, EventArgs.Empty);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | public override string ToString() {
|
---|
| 91 | return string.Format("{0} [active: {1}; value: {2}; min: {3}; max: {4}; step: {5}]", Name, Active, Value, Min, Max, Step);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | protected InputParameter(InputParameter original, Cloner cloner) : base(original, cloner) {
|
---|
| 95 | name = original.name;
|
---|
| 96 | min = original.min;
|
---|
| 97 | max = original.max;
|
---|
| 98 | step = original.step;
|
---|
| 99 | value = original.value;
|
---|
| 100 | active = original.active;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 104 | return new InputParameter(this, cloner);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | [StorableConstructor]
|
---|
[16901] | 108 | protected InputParameter(StorableConstructorFlag _) : base(_) { }
|
---|
[14333] | 109 |
|
---|
| 110 | public InputParameter(string name, double value, double min, double max, double step, bool active = true) {
|
---|
| 111 | this.name = name;
|
---|
| 112 | this.value = value;
|
---|
| 113 | this.min = min;
|
---|
| 114 | this.max = max;
|
---|
| 115 | this.step = step;
|
---|
| 116 | this.active = active;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | public event EventHandler Changed;
|
---|
| 120 | private void OnChanged(object sender, EventArgs args) {
|
---|
| 121 | var changed = Changed;
|
---|
| 122 | if (changed == null) return;
|
---|
| 123 | changed(sender, args);
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | }
|
---|