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.Linq;
|
---|
25 | using System.Collections.Generic;
|
---|
26 | using HEAL.Attic;
|
---|
27 | using HeuristicLab.Common;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 | using HeuristicLab.Collections;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
32 | [StorableType("A56BFB05-8F11-4766-9FBF-20C7010F1CA3")]
|
---|
33 | [Item("ShapeConstraints", "Represents shape constraints associated with a regression problem data e.g. monotonicity constraints.")]
|
---|
34 | public class ShapeConstraints : CheckedItemList<ShapeConstraint> {
|
---|
35 | // private static readonly string exampleInput = "# Example for a target variable constraint:" + Environment.NewLine +
|
---|
36 | // "f in [0 .. 100]" + Environment.NewLine + Environment.NewLine +
|
---|
37 | // "# Example for constraints on model parameters: " + Environment.NewLine +
|
---|
38 | // "df/d'x' in [0 .. 10]" + Environment.NewLine +
|
---|
39 | // "∂²f/∂'x'² in [-1 .. inf.]";
|
---|
40 | //
|
---|
41 | // [Storable]
|
---|
42 | // private string input;
|
---|
43 |
|
---|
44 | // public string Input {
|
---|
45 | // get => input;
|
---|
46 | // set {
|
---|
47 | // if (input == value) return;
|
---|
48 | // input = value;
|
---|
49 | // OnChanged();
|
---|
50 | // }
|
---|
51 | // }
|
---|
52 |
|
---|
53 | // [Storable]
|
---|
54 | // private string infoText;
|
---|
55 |
|
---|
56 | // public string InfoText {
|
---|
57 | // get => infoText;
|
---|
58 | // set {
|
---|
59 | // if (infoText == value) return;
|
---|
60 | // infoText = value;
|
---|
61 | // OnChanged();
|
---|
62 | // }
|
---|
63 | // }
|
---|
64 | //
|
---|
65 | // [Storable]
|
---|
66 | // private Color infoColor;
|
---|
67 | //
|
---|
68 | // public Color InfoColor {
|
---|
69 | // get => infoColor;
|
---|
70 | // set {
|
---|
71 | // if (infoColor == value) return;
|
---|
72 | // infoColor = value;
|
---|
73 | // OnChanged();
|
---|
74 | // }
|
---|
75 | // }
|
---|
76 |
|
---|
77 | // [Storable]
|
---|
78 | // private IEnumerable<IntervalConstraint> constraints;
|
---|
79 |
|
---|
80 | // public IEnumerable<IntervalConstraint> Constraints {
|
---|
81 | // get => constraints;
|
---|
82 | // set {
|
---|
83 | // if (constraints == value) return;
|
---|
84 | // constraints = value.ToList();
|
---|
85 | // OnChanged();
|
---|
86 | // }
|
---|
87 | // }
|
---|
88 |
|
---|
89 | public IEnumerable<ShapeConstraint> EnabledConstraints => base.CheckedItems.Select(checkedItem => checkedItem.Value);
|
---|
90 |
|
---|
91 | protected override void OnItemsAdded(IEnumerable<IndexedItem<ShapeConstraint>> items) {
|
---|
92 | base.OnItemsAdded(items);
|
---|
93 | foreach (var item in items)
|
---|
94 | item.Value.Changed += Item_Changed;
|
---|
95 | }
|
---|
96 |
|
---|
97 | protected override void OnItemsRemoved(IEnumerable<IndexedItem<ShapeConstraint>> items) {
|
---|
98 | base.OnItemsRemoved(items);
|
---|
99 | foreach (var item in items)
|
---|
100 | item.Value.Changed -= Item_Changed;
|
---|
101 | }
|
---|
102 |
|
---|
103 | protected override void OnCollectionReset(
|
---|
104 | IEnumerable<IndexedItem<ShapeConstraint>> items,
|
---|
105 | IEnumerable<IndexedItem<ShapeConstraint>> oldItems) {
|
---|
106 | base.OnCollectionReset(items, oldItems);
|
---|
107 | foreach (var item in items)
|
---|
108 | item.Value.Changed += Item_Changed;
|
---|
109 | foreach (var item in oldItems)
|
---|
110 | item.Value.Changed -= Item_Changed;
|
---|
111 | }
|
---|
112 |
|
---|
113 | private void Item_Changed(object sender, EventArgs e) {
|
---|
114 | RaiseChanged();
|
---|
115 | }
|
---|
116 |
|
---|
117 | // [Storable]
|
---|
118 | // public IRegressionProblemData ProblemData { get; private set; }
|
---|
119 |
|
---|
120 | [StorableConstructor]
|
---|
121 | protected ShapeConstraints(StorableConstructorFlag _) : base(_) { }
|
---|
122 |
|
---|
123 | protected ShapeConstraints(ShapeConstraints original, Cloner cloner)
|
---|
124 | : base(original, cloner) {
|
---|
125 | // Input = original.Input;
|
---|
126 | // InfoText = original.InfoText;
|
---|
127 | // infoColor = original.InfoColor;
|
---|
128 | // constraints = original.Constraints.Select(cloner.Clone).ToList();
|
---|
129 | // ProblemData = cloner.Clone(original.ProblemData);
|
---|
130 | }
|
---|
131 |
|
---|
132 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
133 | return new ShapeConstraints(this, cloner);
|
---|
134 | }
|
---|
135 |
|
---|
136 | public ShapeConstraints() {
|
---|
137 | // Input = exampleInput;
|
---|
138 | // InfoText = "";
|
---|
139 | // InfoColor = Color.DarkOrange;
|
---|
140 | // constraints = new List<IntervalConstraint>();
|
---|
141 | // ProblemData = null;
|
---|
142 | }
|
---|
143 |
|
---|
144 | // public ShapeConstraints(IRegressionProblemData problemData) {
|
---|
145 | // Input = exampleInput;
|
---|
146 | // InfoText = infoText;
|
---|
147 | // InfoColor = InfoColor;
|
---|
148 | // constraints = new List<IntervalConstraint>();
|
---|
149 | // ProblemData = problemData;
|
---|
150 | // }
|
---|
151 |
|
---|
152 | public event EventHandler Changed;
|
---|
153 |
|
---|
154 | private void RaiseChanged() {
|
---|
155 | var handlers = Changed;
|
---|
156 | if (handlers != null)
|
---|
157 | handlers(this, EventArgs.Empty);
|
---|
158 | }
|
---|
159 | }
|
---|
160 | } |
---|