[10539] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10539] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[15535] | 22 | using System.Collections.Generic;
|
---|
[10539] | 23 | using System.Drawing;
|
---|
[15535] | 24 | using System.Linq;
|
---|
[10539] | 25 | using HeuristicLab.Common;
|
---|
[10245] | 26 | using HeuristicLab.Core;
|
---|
[10813] | 27 | using HeuristicLab.DataPreprocessing.Filter;
|
---|
[17097] | 28 | using HEAL.Attic;
|
---|
[10242] | 29 |
|
---|
[10539] | 30 | namespace HeuristicLab.DataPreprocessing {
|
---|
[10313] | 31 | [Item("Filter", "Represents the filter grid.")]
|
---|
[17097] | 32 | [StorableType("A1676153-6E8F-48B5-8FC4-EB0E8060179D")]
|
---|
[15535] | 33 | public class FilterContent : PreprocessingContent, IViewShortcut {
|
---|
[10313] | 34 | public static new Image StaticItemImage {
|
---|
| 35 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Filter; }
|
---|
| 36 | }
|
---|
[15535] | 37 | [Storable]
|
---|
[15242] | 38 | public ICheckedItemCollection<IFilter> Filters { get; private set; }
|
---|
[10813] | 39 |
|
---|
[15535] | 40 | [Storable]
|
---|
[15242] | 41 | public bool IsAndCombination { get; set; }
|
---|
[10842] | 42 |
|
---|
[15535] | 43 | public IEnumerable<IFilter> ActiveFilters {
|
---|
| 44 | get { return Filters.Where(f => f.Active && f.ConstraintData != null); }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public bool[] GetRemainingRows() {
|
---|
| 48 | var remainingRows = new bool[PreprocessingData.Rows];
|
---|
| 49 | if (ActiveFilters.Any()) {
|
---|
| 50 | var filterResults = ActiveFilters.Select(f => f.Check()).ToList();
|
---|
| 51 | var rowFilterResults = new bool[filterResults.Count];
|
---|
| 52 | for (int row = 0; row < remainingRows.Length; row++) {
|
---|
| 53 | for (int i = 0; i < filterResults.Count; i++)
|
---|
| 54 | rowFilterResults[i] = filterResults[i][row];
|
---|
| 55 |
|
---|
| 56 | remainingRows[row] = IsAndCombination
|
---|
| 57 | ? rowFilterResults.All(x => x)
|
---|
| 58 | : rowFilterResults.Any(x => x);
|
---|
| 59 | }
|
---|
| 60 | } else {
|
---|
| 61 | // if not filters active => all rows are remaining
|
---|
| 62 | for (int i = 0; i < remainingRows.Length; i++)
|
---|
| 63 | remainingRows[i] = true;
|
---|
| 64 | }
|
---|
| 65 | return remainingRows;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | #region Constructor, Cloning & Persistence
|
---|
| 69 | public FilterContent(IFilteredPreprocessingData preprocessingData)
|
---|
| 70 | : base(preprocessingData) {
|
---|
[15242] | 71 | Filters = new CheckedItemCollection<IFilter>();
|
---|
| 72 | IsAndCombination = true;
|
---|
[10964] | 73 | }
|
---|
| 74 |
|
---|
[15535] | 75 | protected FilterContent(FilterContent original, Cloner cloner)
|
---|
| 76 | : base(original, cloner) {
|
---|
| 77 | Filters = cloner.Clone(original.Filters);
|
---|
| 78 | IsAndCombination = original.IsAndCombination;
|
---|
[10245] | 79 | }
|
---|
[10539] | 80 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[10245] | 81 | return new FilterContent(this, cloner);
|
---|
| 82 | }
|
---|
[15535] | 83 |
|
---|
| 84 | [StorableConstructor]
|
---|
[17097] | 85 | protected FilterContent(StorableConstructorFlag _) : base(_) { }
|
---|
[15535] | 86 | #endregion
|
---|
[10242] | 87 | }
|
---|
| 88 | }
|
---|