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