Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/InputParameter.cs @ 14333

Last change on this file since 14333 was 14333, checked in by bburlacu, 8 years ago

#2679: Refactor problems and extract common functionality in static util class.

File size: 3.5 KB
Line 
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
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.GoalSeeking {
28  [Item("InputParameter", "An object describing a target for the goal seeking.")]
29  [StorableClass]
30  public class InputParameter : NamedItem {
31    [Storable]
32    private double min;
33    public double Min {
34      get { return min; }
35      set {
36        if (min.IsAlmost(value)) return;
37        min = value;
38        OnChanged(this, EventArgs.Empty);
39      }
40    }
41
42    [Storable]
43    private double max;
44    public double Max {
45      get { return max; }
46      set {
47        if (max.IsAlmost(value)) return;
48        max = value;
49        OnChanged(this, EventArgs.Empty);
50      }
51    }
52
53    [Storable]
54    private double step;
55    public double Step {
56      get { return step; }
57      set {
58        if (step.IsAlmost(value)) return;
59        step = value;
60        OnChanged(this, EventArgs.Empty);
61      }
62    }
63
64    [Storable]
65    private double value;
66    public double Value {
67      get { return value; }
68      set {
69        if (this.value.IsAlmost(value)) return;
70        this.value = value;
71        OnChanged(this, EventArgs.Empty);
72      }
73    }
74
75    [Storable]
76    private bool active;
77    public bool Active {
78      get { return active; }
79      set {
80        if (active == value) return;
81        active = value;
82        OnChanged(this, EventArgs.Empty);
83      }
84    }
85
86    public override string ToString() {
87      return string.Format("{0} [active: {1}; value: {2}; min: {3}; max: {4}; step: {5}]", Name, Active, Value, Min, Max, Step);
88    }
89
90    protected InputParameter(InputParameter original, Cloner cloner) : base(original, cloner) {
91      name = original.name;
92      min = original.min;
93      max = original.max;
94      step = original.step;
95      value = original.value;
96      active = original.active;
97    }
98
99    public override IDeepCloneable Clone(Cloner cloner) {
100      return new InputParameter(this, cloner);
101    }
102
103    [StorableConstructor]
104    protected InputParameter(bool deserializing) : base(deserializing) { }
105
106    public InputParameter(string name, double value, double min, double max, double step, bool active = true) {
107      this.name = name;
108      this.value = value;
109      this.min = min;
110      this.max = max;
111      this.step = step;
112      this.active = active;
113    }
114
115    public event EventHandler Changed;
116    private void OnChanged(object sender, EventArgs args) {
117      var changed = Changed;
118      if (changed == null) return;
119      changed(sender, args);
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.