[17887] | 1 | #region License Information
|
---|
| 2 |
|
---|
| 3 | /* HeuristicLab
|
---|
[17896] | 4 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[17887] | 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;
|
---|
[17891] | 24 | using System.Linq;
|
---|
[17887] | 25 | using System.Collections.Generic;
|
---|
| 26 | using HEAL.Attic;
|
---|
| 27 | using HeuristicLab.Common;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
[17891] | 29 | using HeuristicLab.Collections;
|
---|
[17887] | 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.")]
|
---|
[17891] | 34 | public class ShapeConstraints : CheckedItemList<ShapeConstraint> {
|
---|
| 35 | public IEnumerable<ShapeConstraint> EnabledConstraints => base.CheckedItems.Select(checkedItem => checkedItem.Value);
|
---|
[17887] | 36 |
|
---|
[17891] | 37 | protected override void OnItemsAdded(IEnumerable<IndexedItem<ShapeConstraint>> items) {
|
---|
[17887] | 38 | base.OnItemsAdded(items);
|
---|
| 39 | foreach (var item in items)
|
---|
[17891] | 40 | item.Value.Changed += Item_Changed;
|
---|
[17887] | 41 | }
|
---|
| 42 |
|
---|
[17891] | 43 | protected override void OnItemsRemoved(IEnumerable<IndexedItem<ShapeConstraint>> items) {
|
---|
[17887] | 44 | base.OnItemsRemoved(items);
|
---|
| 45 | foreach (var item in items)
|
---|
[17891] | 46 | item.Value.Changed -= Item_Changed;
|
---|
[17887] | 47 | }
|
---|
| 48 |
|
---|
[17891] | 49 | protected override void OnCollectionReset(
|
---|
| 50 | IEnumerable<IndexedItem<ShapeConstraint>> items,
|
---|
| 51 | IEnumerable<IndexedItem<ShapeConstraint>> oldItems) {
|
---|
[17887] | 52 | base.OnCollectionReset(items, oldItems);
|
---|
| 53 | foreach (var item in items)
|
---|
[17891] | 54 | item.Value.Changed += Item_Changed;
|
---|
[17887] | 55 | foreach (var item in oldItems)
|
---|
[17891] | 56 | item.Value.Changed -= Item_Changed;
|
---|
[17887] | 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 |
|
---|
[17896] | 74 | public ShapeConstraints() : base() {
|
---|
[17887] | 75 | }
|
---|
| 76 |
|
---|
| 77 | public event EventHandler Changed;
|
---|
| 78 |
|
---|
| 79 | private void RaiseChanged() {
|
---|
| 80 | var handlers = Changed;
|
---|
| 81 | if (handlers != null)
|
---|
| 82 | handlers(this, EventArgs.Empty);
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | } |
---|