Free cookie consent management tool by TermsFeed Policy Generator

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, 4 years ago

#2971: Further minor refactorings and renaming of members.

File size: 4.2 KB
RevLine 
[16830]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;
[16756]24using System.Collections.Generic;
[17256]25using System.Drawing;
[16928]26using System.Linq;
[17146]27using HEAL.Attic;
[16756]28using HeuristicLab.Common;
29using HeuristicLab.Core;
30
31namespace HeuristicLab.Problems.DataAnalysis {
[16778]32  [StorableType("A56BFB05-8F11-4766-9FBF-20C7010F1CA3")]
[17146]33  [Item("ProblemDataConstraints", "Represents constraints associated with a problem data.")]
[16896]34  public class ProblemDataConstraint : Item {
[16884]35    private static readonly string exampleInput = "# Example for a target variable constraint:" + Environment.NewLine +
[16866]36                                                  "Target:'y' in [0 .. 100]" + Environment.NewLine + Environment.NewLine +
[17506]37                                                  "# Example for constraints on model parameters: " + Environment.NewLine +
[16866]38                                                  "d'y'/d'x' in [0 .. 10]" + Environment.NewLine +
[17370]39                                                  "∂²'y'/∂'x'² in [-1 .. inf.]";
[16928]40
[16937]41    [Storable]
[16928]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    }
[16756]51
[16937]52    [Storable]
[17256]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]
[16800]75    private IEnumerable<IntervalConstraint> constraints;
[16756]76    public IEnumerable<IntervalConstraint> Constraints {
[16937]77      get => constraints;
[16928]78      set {
79        if (constraints == value) return;
[16935]80        constraints = value.ToList();
[16928]81        OnChanged();
[16776]82      }
[16884]83    }
[17504]84    public IEnumerable<IntervalConstraint> EnabledConstraints {
85      get => Constraints.Where(c => c.Enabled);
86    }
87
88
[16884]89    [Storable]
90    public IRegressionProblemData ProblemData { get; private set; }
[16756]91
[16800]92    [StorableConstructor]
[16896]93    protected ProblemDataConstraint(StorableConstructorFlag _) : base(_) { }
[16773]94
[16896]95    protected ProblemDataConstraint(ProblemDataConstraint original, Cloner cloner)
[16756]96      : base(original, cloner) {
[16800]97      this.Input = original.Input;
[17256]98      this.InfoText = original.InfoText;
99      this.infoColor = original.InfoColor;
[16935]100      this.constraints = original.Constraints.Select(cloner.Clone).ToList();
[16928]101      this.ProblemData = cloner.Clone(original.ProblemData);
[16756]102    }
103
104    public override IDeepCloneable Clone(Cloner cloner) {
[16896]105      return new ProblemDataConstraint(this, cloner);
[16756]106    }
107
[17146]108    public ProblemDataConstraint() : base() {
[16800]109      this.Input = exampleInput;
[17256]110      this.InfoText = "";
111      this.InfoColor = Color.DarkOrange;
[16937]112      this.constraints = new List<IntervalConstraint>();
[16800]113      this.ProblemData = null;
[16756]114    }
115
[16896]116    public ProblemDataConstraint(IRegressionProblemData problemData) : base() {
[16800]117      this.Input = exampleInput;
[17256]118      this.InfoText = infoText;
119      this.InfoColor = InfoColor;
[16937]120      this.constraints = new List<IntervalConstraint>();
[16800]121      this.ProblemData = problemData;
122    }
123
[16776]124    public event EventHandler Changed;
[16928]125    protected virtual void OnChanged() {
[16776]126      EventHandler handlers = Changed;
127      if (handlers != null)
[16928]128        handlers(this, EventArgs.Empty);
[16776]129    }
[16756]130  }
131}
Note: See TracBrowser for help on using the repository browser.