Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/ProblemDataConstraint.cs @ 17717

Last change on this file since 17717 was 17651, checked in by chaider, 4 years ago

#3073 Persistence fixes

File size: 4.6 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:"     +
36                                                  Environment.NewLine                               +
37                                                  "Target:'y' in [0 .. 100]"                        +
38                                                  Environment.NewLine                               +
39                                                  Environment.NewLine                               +
40                                                  "# Example for constraints on model parameters: " +
41                                                  Environment.NewLine                               +
42                                                  "d'y'/d'x' in [0 .. 10]"                          +
43                                                  Environment.NewLine                               +
44                                                  "∂²'y'/∂'x'² in [-1 .. inf.]";
45
46    [Storable] private string input;
47
48    public string Input {
49      get => input;
50      set {
51        if (input == value) return;
52        input = value;
53        OnChanged();
54      }
55    }
56
57    [Storable] private string infoText;
58
59    public string InfoText {
60      get => infoText;
61      set {
62        if (infoText == value) return;
63        infoText = value;
64        OnChanged();
65      }
66    }
67
68    [Storable] private Color infoColor;
69
70    public Color InfoColor {
71      get => infoColor;
72      set {
73        if (infoColor == value) return;
74        infoColor = value;
75        OnChanged();
76      }
77    }
78
79    [Storable] private IEnumerable<IntervalConstraint> constraints;
80
81    public IEnumerable<IntervalConstraint> Constraints {
82      get => constraints;
83      set {
84        if (constraints == value) return;
85        constraints = value.ToList();
86        OnChanged();
87      }
88    }
89
90    public IEnumerable<IntervalConstraint> EnabledConstraints => Constraints.Where(c => c.Enabled);
91
92
93    [Storable] public IRegressionProblemData ProblemData { get; private set; }
94
95    [StorableConstructor]
96    protected ProblemDataConstraint(StorableConstructorFlag _) : base(_) { }
97
98    protected ProblemDataConstraint(ProblemDataConstraint original, Cloner cloner)
99      : base(original, cloner) {
100      Input       = original.Input;
101      InfoText    = original.InfoText;
102      infoColor   = original.InfoColor;
103      constraints = original.Constraints.Select(cloner.Clone).ToList();
104      ProblemData = cloner.Clone(original.ProblemData);
105    }
106
107    public override IDeepCloneable Clone(Cloner cloner) {
108      return new ProblemDataConstraint(this, cloner);
109    }
110
111    public ProblemDataConstraint() {
112      Input       = exampleInput;
113      InfoText    = "";
114      InfoColor   = Color.DarkOrange;
115      constraints = new List<IntervalConstraint>();
116      ProblemData = null;
117    }
118
119    public ProblemDataConstraint(IRegressionProblemData problemData) {
120      Input       = exampleInput;
121      InfoText    = infoText;
122      InfoColor   = InfoColor;
123      constraints = new List<IntervalConstraint>();
124      ProblemData = problemData;
125    }
126
127    public event EventHandler Changed;
128
129    protected virtual void OnChanged() {
130      var handlers = Changed;
131      if (handlers != null)
132        handlers(this, EventArgs.Empty);
133    }
134  }
135}
Note: See TracBrowser for help on using the repository browser.