[10558] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16453] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10558] | 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 |
|
---|
[10947] | 22 | using System;
|
---|
[10558] | 23 | using System.Drawing;
|
---|
[16462] | 24 | using HEAL.Fossil;
|
---|
[10947] | 25 | using HeuristicLab.Common;
|
---|
[10558] | 26 | using HeuristicLab.Common.Resources;
|
---|
[10549] | 27 | using HeuristicLab.Core;
|
---|
[10588] | 28 | using HeuristicLab.Data;
|
---|
[10549] | 29 |
|
---|
[10947] | 30 | namespace HeuristicLab.DataPreprocessing.Filter {
|
---|
| 31 | [Item("ComparisonFilter", "A filter which compares the member of the preprocessing data with the constraint data.")]
|
---|
[16474] | 32 | [StorableType("6529899a-987c-48b3-ba14-154d25a7cc8e")]
|
---|
[10947] | 33 | public class ComparisonFilter : ComparisonConstraint, IFilter {
|
---|
| 34 | public override string ItemName {
|
---|
| 35 | get { return "ComparisonFilter"; }
|
---|
| 36 | }
|
---|
[10582] | 37 |
|
---|
[10947] | 38 | public override Image ItemImage {
|
---|
| 39 | get { return VSImageLibrary.Filter; }
|
---|
| 40 | }
|
---|
[10582] | 41 |
|
---|
[10947] | 42 | public new IPreprocessingData ConstrainedValue {
|
---|
| 43 | get { return (IPreprocessingData)base.ConstrainedValue; }
|
---|
| 44 | set { base.ConstrainedValue = value; }
|
---|
| 45 | }
|
---|
[10582] | 46 |
|
---|
[10947] | 47 | public new IStringConvertibleValue ConstraintData {
|
---|
| 48 | get { return (IStringConvertibleValue)base.ConstraintData; }
|
---|
| 49 | set {
|
---|
| 50 | if (!(value is IComparable))
|
---|
| 51 | throw new ArgumentException("Only IComparables allowed for ConstraintData");
|
---|
| 52 | base.ConstraintData = value;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
[10582] | 55 |
|
---|
[10999] | 56 | public ComparisonFilter() : base() { }
|
---|
[16462] | 57 | [StorableConstructor]
|
---|
| 58 | protected ComparisonFilter(StorableConstructorFlag _) : base(_) { }
|
---|
[10582] | 59 |
|
---|
[10999] | 60 | public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData)
|
---|
| 61 | : base(constrainedValue, constraintOperation, constraintData) {
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData, bool active)
|
---|
| 65 | : base(constrainedValue, constraintOperation, constraintData, active) {
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | protected ComparisonFilter(ComparisonFilter original, Cloner cloner)
|
---|
| 69 | : base(original, cloner) {
|
---|
| 70 | constraintColumn = original.constraintColumn;
|
---|
| 71 | }
|
---|
| 72 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 73 | return new ComparisonFilter(this, cloner);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[10947] | 76 | private int constraintColumn;
|
---|
| 77 | public int ConstraintColumn {
|
---|
| 78 | get { return constraintColumn; }
|
---|
| 79 | set {
|
---|
| 80 | if (ConstrainedValue.Columns < value)
|
---|
| 81 | throw new ArgumentException("Could not set ConstraintData to not existing column index.");
|
---|
[10587] | 82 |
|
---|
[10947] | 83 | if (constraintColumn != value) {
|
---|
| 84 | constraintColumn = value;
|
---|
| 85 | this.OnConstraintColumnChanged();
|
---|
| 86 | this.OnToStringChanged();
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
[10619] | 90 |
|
---|
[15466] | 91 | // return remaining rows
|
---|
[10947] | 92 | public new bool[] Check() {
|
---|
| 93 | bool[] result = new bool[ConstrainedValue.Rows];
|
---|
[10582] | 94 |
|
---|
[10947] | 95 | if (!Active)
|
---|
| 96 | return result;
|
---|
[10582] | 97 |
|
---|
[10947] | 98 | for (int row = 0; row < ConstrainedValue.Rows; ++row) {
|
---|
| 99 | object item = null;
|
---|
[11156] | 100 | if (ConstrainedValue.VariableHasType<double>(constraintColumn)) {
|
---|
[10947] | 101 | item = new HeuristicLab.Data.DoubleValue(ConstrainedValue.GetCell<double>(ConstraintColumn, row));
|
---|
[11156] | 102 | } else if (ConstrainedValue.VariableHasType<DateTime>(constraintColumn)) {
|
---|
[10947] | 103 | item = new HeuristicLab.Data.DateTimeValue(ConstrainedValue.GetCell<DateTime>(ConstraintColumn, row));
|
---|
| 104 | } else {
|
---|
| 105 | item = new StringValue(ConstrainedValue.GetCell<string>(ConstraintColumn, row));
|
---|
[10582] | 106 | }
|
---|
| 107 |
|
---|
[15466] | 108 | result[row] = base.Check(item);
|
---|
[10947] | 109 | }
|
---|
[10582] | 110 |
|
---|
[10947] | 111 | return result;
|
---|
| 112 | }
|
---|
[10704] | 113 |
|
---|
[10947] | 114 | public new bool[] Check(out string errorMessage) {
|
---|
| 115 | errorMessage = string.Empty;
|
---|
| 116 | return this.Check();
|
---|
| 117 | }
|
---|
[10704] | 118 |
|
---|
[10947] | 119 | public override string ToString() {
|
---|
| 120 | string s = string.Empty;
|
---|
| 121 | if (ConstrainedValue != null)
|
---|
| 122 | s += ConstrainedValue.GetVariableName(ConstraintColumn) + " ";
|
---|
[10704] | 123 |
|
---|
[10947] | 124 | if (ConstraintOperation != null)
|
---|
| 125 | s += ConstraintOperation.ToString() + " ";
|
---|
| 126 |
|
---|
| 127 | if (ConstraintData != null)
|
---|
| 128 | s += ConstraintData.ToString();
|
---|
| 129 | else
|
---|
| 130 | s += "null";
|
---|
| 131 |
|
---|
| 132 | s += ".";
|
---|
| 133 | return s;
|
---|
[10549] | 134 | }
|
---|
[10999] | 135 |
|
---|
| 136 | public event EventHandler ConstraintColumnChanged;
|
---|
| 137 | protected virtual void OnConstraintColumnChanged() {
|
---|
| 138 | EventHandler handler = ConstraintColumnChanged;
|
---|
| 139 | if (handler != null)
|
---|
| 140 | handler(this, EventArgs.Empty);
|
---|
| 141 | }
|
---|
[10947] | 142 | }
|
---|
[10549] | 143 | }
|
---|