1 | #region License Information
|
---|
2 |
|
---|
3 | /* HeuristicLab
|
---|
4 | * Copyright (C) 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 | public IEnumerable<ShapeConstraint> EnabledConstraints => base.CheckedItems.Select(checkedItem => checkedItem.Value);
|
---|
36 |
|
---|
37 | protected override void OnItemsAdded(IEnumerable<IndexedItem<ShapeConstraint>> items) {
|
---|
38 | base.OnItemsAdded(items);
|
---|
39 | foreach (var item in items)
|
---|
40 | item.Value.Changed += Item_Changed;
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected override void OnItemsRemoved(IEnumerable<IndexedItem<ShapeConstraint>> items) {
|
---|
44 | base.OnItemsRemoved(items);
|
---|
45 | foreach (var item in items)
|
---|
46 | item.Value.Changed -= Item_Changed;
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected override void OnCollectionReset(
|
---|
50 | IEnumerable<IndexedItem<ShapeConstraint>> items,
|
---|
51 | IEnumerable<IndexedItem<ShapeConstraint>> oldItems) {
|
---|
52 | base.OnCollectionReset(items, oldItems);
|
---|
53 | foreach (var item in items)
|
---|
54 | item.Value.Changed += Item_Changed;
|
---|
55 | foreach (var item in oldItems)
|
---|
56 | item.Value.Changed -= Item_Changed;
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void Item_Changed(object sender, EventArgs e) {
|
---|
60 | RaiseChanged();
|
---|
61 | }
|
---|
62 |
|
---|
63 | [StorableConstructor]
|
---|
64 | protected ShapeConstraints(StorableConstructorFlag _) : base(_) { }
|
---|
65 |
|
---|
66 | protected ShapeConstraints(ShapeConstraints original, Cloner cloner)
|
---|
67 | : base(original, cloner) {
|
---|
68 | }
|
---|
69 |
|
---|
70 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
71 | return new ShapeConstraints(this, cloner);
|
---|
72 | }
|
---|
73 |
|
---|
74 | public ShapeConstraints() : base() {
|
---|
75 | }
|
---|
76 |
|
---|
77 | public event EventHandler Changed;
|
---|
78 |
|
---|
79 |
|
---|
80 | private void RaiseChanged() {
|
---|
81 | var handlers = Changed;
|
---|
82 | if (handlers != null)
|
---|
83 | handlers(this, EventArgs.Empty);
|
---|
84 | }
|
---|
85 | }
|
---|
86 | } |
---|