source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/ProblemDataConstraint.cs @ 17506

Last change on this file since 17506 was 17506, checked in by mkommend, 6 months ago

#2971: Further minor refactorings and renaming of members.

File size: 4.2 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23using System;
24using System.Collections.Generic;
25using System.Drawing;
26using System.Linq;
27using HEAL.Attic;
28using HeuristicLab.Common;
29using HeuristicLab.Core;
30
31namespace HeuristicLab.Problems.DataAnalysis {
32  [StorableType("A56BFB05-8F11-4766-9FBF-20C7010F1CA3")]
33  [Item("ProblemDataConstraints", "Represents constraints associated with a problem data.")]
34  public class ProblemDataConstraint : Item {
35    private static readonly string exampleInput = "# Example for a target variable constraint:" + Environment.NewLine +
36                                                  "Target:'y' in [0 .. 100]" + Environment.NewLine + Environment.NewLine +
37                                                  "# Example for constraints on model parameters: " + Environment.NewLine +
38                                                  "d'y'/d'x' in [0 .. 10]" + Environment.NewLine +
39                                                  "∂²'y'/∂'x'² in [-1 .. inf.]";
40
41    [Storable]
42    private string input;
43    public string Input {
44      get => input;
45      set {
46        if (input == value) return;
47        input = value;
48        OnChanged();
49      }
50    }
51
52    [Storable]
53    private string infoText;
54    public string InfoText {
55      get => infoText;
56      set {
57        if (infoText == value) return;
58        infoText = value;
59        OnChanged();
60      }
61    }
62
63    [Storable]
64    private Color infoColor;
65    public Color InfoColor {
66      get => infoColor;
67      set {
68        if (infoColor == value) return;
69        infoColor = value;
70        OnChanged();
71      }
72    }
73
74    [Storable]
75    private IEnumerable<IntervalConstraint> constraints;
76    public IEnumerable<IntervalConstraint> Constraints {
77      get => constraints;
78      set {
79        if (constraints == value) return;
80        constraints = value.ToList();
81        OnChanged();
82      }
83    }
84    public IEnumerable<IntervalConstraint> EnabledConstraints {
85      get => Constraints.Where(c => c.Enabled);
86    }
87
88
89    [Storable]
90    public IRegressionProblemData ProblemData { get; private set; }
91
92    [StorableConstructor]
93    protected ProblemDataConstraint(StorableConstructorFlag _) : base(_) { }
94
95    protected ProblemDataConstraint(ProblemDataConstraint original, Cloner cloner)
96      : base(original, cloner) {
97      this.Input = original.Input;
98      this.InfoText = original.InfoText;
99      this.infoColor = original.InfoColor;
100      this.constraints = original.Constraints.Select(cloner.Clone).ToList();
101      this.ProblemData = cloner.Clone(original.ProblemData);
102    }
103
104    public override IDeepCloneable Clone(Cloner cloner) {
105      return new ProblemDataConstraint(this, cloner);
106    }
107
108    public ProblemDataConstraint() : base() {
109      this.Input = exampleInput;
110      this.InfoText = "";
111      this.InfoColor = Color.DarkOrange;
112      this.constraints = new List<IntervalConstraint>();
113      this.ProblemData = null;
114    }
115
116    public ProblemDataConstraint(IRegressionProblemData problemData) : base() {
117      this.Input = exampleInput;
118      this.InfoText = infoText;
119      this.InfoColor = InfoColor;
120      this.constraints = new List<IntervalConstraint>();
121      this.ProblemData = problemData;
122    }
123
124    public event EventHandler Changed;
125    protected virtual void OnChanged() {
126      EventHandler handlers = Changed;
127      if (handlers != null)
128        handlers(this, EventArgs.Empty);
129    }
130  }
131}
Note: See TracBrowser for help on using the repository browser.