Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/FilterLogic.cs @ 10849

Last change on this file since 10849 was 10849, checked in by psteiner, 10 years ago

Filter Logic And/Or Conjunction

File size: 2.8 KB
RevLine 
[10539]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
[10244]21
[10619]22using System.Collections.Generic;
[10666]23using System.Linq;
[10843]24using HeuristicLab.DataPreprocessing.Filter;
[10783]25using HeuristicLab.DataPreprocessing.Interfaces;
[10539]26namespace HeuristicLab.DataPreprocessing {
27  public class FilterLogic : IFilterLogic {
[10619]28
[10783]29    private IFilteredPreprocessingData preprocessingData;
[10619]30
[10843]31    public FilterLogic(IFilteredPreprocessingData preprocessingData) {
[10619]32      this.preprocessingData = preprocessingData;
33    }
34
[10844]35    public bool[] GetFilterResult(IList<IFilter> filters, bool isAndCombination) {
[10843]36      IList<IFilter> activeFilters = filters.Where(f => f.Active && f.ConstraintData != null).ToList<IFilter>();
37
38      if (activeFilters.Count == 0) {
[10696]39        return new bool[preprocessingData.Rows];
[10843]40      }
[10696]41
[10849]42      bool[] result = CreateBoolArray(preprocessingData.Rows, !isAndCombination);
[10802]43
[10843]44      foreach (IFilter filter in activeFilters) {
45        bool[] filterResult = filter.Check();
46        for (int row = 0; row < result.Length; ++row) {
47          result[row] = Result(result[row], filterResult[row], isAndCombination);
48        }
49      }
[10844]50      return result;
51    }
[10619]52
[10844]53    public bool[] Preview(IList<IFilter> filters, bool isAndCombination) {
54      var result = GetFilterResult(filters, isAndCombination);
[10843]55      preprocessingData.SetFilter(result);
56      return result;
[10619]57    }
58
[10843]59    public bool[] CreateBoolArray(int rows, bool value) {
60      return Enumerable.Repeat<bool>(value, rows).ToArray();
[10802]61    }
62
[10843]63    public bool Result(bool current, bool addition, bool isAndCombination) {
[10849]64      return isAndCombination ? current || addition : current && addition;
[10802]65    }
66
[10843]67    public void Apply(IList<IFilter> filters, bool isAndCombination) {
68      preprocessingData.SetFilter(Preview(filters, isAndCombination));
69      preprocessingData.PersistFilter();
[10783]70    }
[10619]71
[10783]72    public void Reset() {
73      preprocessingData.ResetFilter();
74    }
[10638]75
[10843]76    public IPreprocessingData PreprocessingData {
[10638]77      get { return preprocessingData; }
78    }
[10244]79  }
80}
Note: See TracBrowser for help on using the repository browser.