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
|
---|
23 | using System;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Linq;
|
---|
26 | using HEAL.Attic;
|
---|
27 | using HeuristicLab.Common;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
31 | [StorableType("A56BFB05-8F11-4766-9FBF-20C7010F1CA3")]
|
---|
32 | [Item("ProblemDataConstraints", "Represents constraints associated with a problem data.")]
|
---|
33 | public class ProblemDataConstraint : Item {
|
---|
34 | private static readonly string exampleInput = "# Example for a target variable constraint:" + Environment.NewLine +
|
---|
35 | "Target:'y' in [0 .. 100]" + Environment.NewLine + Environment.NewLine +
|
---|
36 | "# Example for constraint on model parameter: " + Environment.NewLine +
|
---|
37 | "d'y'/d'x' in [0 .. 10]" + Environment.NewLine +
|
---|
38 | "∂²'y'/∂'x'² in ]-1 .. inf.[";
|
---|
39 |
|
---|
40 | [Storable]
|
---|
41 | private string input;
|
---|
42 | public string Input {
|
---|
43 | get => input;
|
---|
44 | set {
|
---|
45 | if (input == value) return;
|
---|
46 | input = value;
|
---|
47 | OnChanged();
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | [Storable]
|
---|
52 | private IEnumerable<IntervalConstraint> constraints;
|
---|
53 | public IEnumerable<IntervalConstraint> Constraints {
|
---|
54 | get => constraints;
|
---|
55 | set {
|
---|
56 | if (constraints == value) return;
|
---|
57 | constraints = value.ToList();
|
---|
58 | OnChanged();
|
---|
59 | }
|
---|
60 | }
|
---|
61 | [Storable]
|
---|
62 | public IRegressionProblemData ProblemData { get; private set; }
|
---|
63 |
|
---|
64 | [StorableConstructor]
|
---|
65 | protected ProblemDataConstraint(StorableConstructorFlag _) : base(_) { }
|
---|
66 |
|
---|
67 | protected ProblemDataConstraint(ProblemDataConstraint original, Cloner cloner)
|
---|
68 | : base(original, cloner) {
|
---|
69 | this.Input = original.Input;
|
---|
70 | this.constraints = original.Constraints.Select(cloner.Clone).ToList();
|
---|
71 | this.ProblemData = cloner.Clone(original.ProblemData);
|
---|
72 | }
|
---|
73 |
|
---|
74 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
75 | return new ProblemDataConstraint(this, cloner);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public ProblemDataConstraint() : base() {
|
---|
79 | this.Input = exampleInput;
|
---|
80 | this.constraints = new List<IntervalConstraint>();
|
---|
81 | this.ProblemData = null;
|
---|
82 | }
|
---|
83 |
|
---|
84 | public ProblemDataConstraint(IRegressionProblemData problemData) : base() {
|
---|
85 | this.Input = exampleInput;
|
---|
86 | this.constraints = new List<IntervalConstraint>();
|
---|
87 | this.ProblemData = problemData;
|
---|
88 | }
|
---|
89 |
|
---|
90 | public event EventHandler Changed;
|
---|
91 | protected virtual void OnChanged() {
|
---|
92 | EventHandler handlers = Changed;
|
---|
93 | if (handlers != null)
|
---|
94 | handlers(this, EventArgs.Empty);
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|