1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Common.Resources;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 |
|
---|
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 {
|
---|
32 | public override string ItemName {
|
---|
33 | get { return "ComparisonFilter"; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public override Image ItemImage {
|
---|
37 | get { return VSImageLibrary.Filter; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public new IPreprocessingData ConstrainedValue {
|
---|
41 | get { return (IPreprocessingData)base.ConstrainedValue; }
|
---|
42 | set { base.ConstrainedValue = value; }
|
---|
43 | }
|
---|
44 |
|
---|
45 | public new IStringConvertibleValue ConstraintData {
|
---|
46 | get { return (IStringConvertibleValue)base.ConstraintData; }
|
---|
47 | set {
|
---|
48 | if (!(value is IComparable))
|
---|
49 | throw new ArgumentException("Only IComparables allowed for ConstraintData");
|
---|
50 | base.ConstraintData = value;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public ComparisonFilter() : base() { }
|
---|
55 | protected ComparisonFilter(bool deserializing) : base(deserializing) { }
|
---|
56 |
|
---|
57 | public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData)
|
---|
58 | : base(constrainedValue, constraintOperation, constraintData) {
|
---|
59 | }
|
---|
60 |
|
---|
61 | public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData, bool active)
|
---|
62 | : base(constrainedValue, constraintOperation, constraintData, active) {
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected ComparisonFilter(ComparisonFilter original, Cloner cloner)
|
---|
66 | : base(original, cloner) {
|
---|
67 | constraintColumn = original.constraintColumn;
|
---|
68 | }
|
---|
69 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
70 | return new ComparisonFilter(this, cloner);
|
---|
71 | }
|
---|
72 |
|
---|
73 | private int constraintColumn;
|
---|
74 | public int ConstraintColumn {
|
---|
75 | get { return constraintColumn; }
|
---|
76 | set {
|
---|
77 | if (ConstrainedValue.Columns < value)
|
---|
78 | throw new ArgumentException("Could not set ConstraintData to not existing column index.");
|
---|
79 |
|
---|
80 | if (constraintColumn != value) {
|
---|
81 | constraintColumn = value;
|
---|
82 | this.OnConstraintColumnChanged();
|
---|
83 | this.OnToStringChanged();
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | // return remaining rows
|
---|
89 | public new bool[] Check() {
|
---|
90 | bool[] result = new bool[ConstrainedValue.Rows];
|
---|
91 |
|
---|
92 | if (!Active)
|
---|
93 | return result;
|
---|
94 |
|
---|
95 | for (int row = 0; row < ConstrainedValue.Rows; ++row) {
|
---|
96 | object item = null;
|
---|
97 | if (ConstrainedValue.VariableHasType<double>(constraintColumn)) {
|
---|
98 | item = new HeuristicLab.Data.DoubleValue(ConstrainedValue.GetCell<double>(ConstraintColumn, row));
|
---|
99 | } else if (ConstrainedValue.VariableHasType<DateTime>(constraintColumn)) {
|
---|
100 | item = new HeuristicLab.Data.DateTimeValue(ConstrainedValue.GetCell<DateTime>(ConstraintColumn, row));
|
---|
101 | } else {
|
---|
102 | item = new StringValue(ConstrainedValue.GetCell<string>(ConstraintColumn, row));
|
---|
103 | }
|
---|
104 |
|
---|
105 | result[row] = base.Check(item);
|
---|
106 | }
|
---|
107 |
|
---|
108 | return result;
|
---|
109 | }
|
---|
110 |
|
---|
111 | public new bool[] Check(out string errorMessage) {
|
---|
112 | errorMessage = string.Empty;
|
---|
113 | return this.Check();
|
---|
114 | }
|
---|
115 |
|
---|
116 | public override string ToString() {
|
---|
117 | string s = string.Empty;
|
---|
118 | if (ConstrainedValue != null)
|
---|
119 | s += ConstrainedValue.GetVariableName(ConstraintColumn) + " ";
|
---|
120 |
|
---|
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;
|
---|
131 | }
|
---|
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 | }
|
---|
139 | }
|
---|
140 | }
|
---|