1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Services.OKB.DataAccess;
|
---|
25 |
|
---|
26 | namespace HeuristicLab.Services.OKB {
|
---|
27 | public class ExperimentEqualityComparer : IEqualityComparer<Experiment> {
|
---|
28 | public bool Equals(Experiment x, Experiment y) {
|
---|
29 | bool equal = true;
|
---|
30 | equal = equal && x.AlgorithmId == y.AlgorithmId;
|
---|
31 | equal = equal && x.ProblemId == y.ProblemId;
|
---|
32 | equal = equal && x.AlgorithmParameterBlobValues.Count == y.AlgorithmParameterBlobValues.Count;
|
---|
33 | equal = equal && x.AlgorithmParameterBoolValues.Count == y.AlgorithmParameterBoolValues.Count;
|
---|
34 | equal = equal && x.AlgorithmParameterFloatValues.Count == y.AlgorithmParameterFloatValues.Count;
|
---|
35 | equal = equal && x.AlgorithmParameterIntValues.Count == y.AlgorithmParameterIntValues.Count;
|
---|
36 | equal = equal && x.AlgorithmParameterStringValues.Count == y.AlgorithmParameterStringValues.Count;
|
---|
37 | equal = equal && x.ProblemParameterBlobValues.Count == y.ProblemParameterBlobValues.Count;
|
---|
38 | equal = equal && x.ProblemParameterBoolValues.Count == y.ProblemParameterBoolValues.Count;
|
---|
39 | equal = equal && x.ProblemParameterFloatValues.Count == y.ProblemParameterFloatValues.Count;
|
---|
40 | equal = equal && x.ProblemParameterIntValues.Count == y.ProblemParameterIntValues.Count;
|
---|
41 | equal = equal && x.ProblemParameterStringValues.Count == y.ProblemParameterStringValues.Count;
|
---|
42 |
|
---|
43 | if (equal) {
|
---|
44 | var values = x.AlgorithmParameterBlobValues.Zip(y.AlgorithmParameterBlobValues, (a, b) => new { X = a, Y = b });
|
---|
45 | foreach (var value in values) {
|
---|
46 | equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
|
---|
47 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
48 | equal = equal && value.X.Value.Length == value.Y.Value.Length;
|
---|
49 | if (equal) {
|
---|
50 | byte[] xBlob = value.X.Value.ToArray();
|
---|
51 | byte[] yBlob = value.Y.Value.ToArray();
|
---|
52 | int i = 0;
|
---|
53 | while (equal && (i < xBlob.Length)) {
|
---|
54 | equal = equal && xBlob[i] == yBlob[i];
|
---|
55 | i++;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 | if (equal) {
|
---|
61 | var values = x.AlgorithmParameterBoolValues.Zip(y.AlgorithmParameterBoolValues, (a, b) => new { X = a, Y = b });
|
---|
62 | foreach (var value in values) {
|
---|
63 | equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
|
---|
64 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
65 | equal = equal && value.X.Value == value.Y.Value;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | if (equal) {
|
---|
69 | var values = x.AlgorithmParameterFloatValues.Zip(y.AlgorithmParameterFloatValues, (a, b) => new { X = a, Y = b });
|
---|
70 | foreach (var value in values) {
|
---|
71 | equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
|
---|
72 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
73 | equal = equal && value.X.Value == value.Y.Value;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | if (equal) {
|
---|
77 | var values = x.AlgorithmParameterIntValues.Zip(y.AlgorithmParameterIntValues, (a, b) => new { X = a, Y = b });
|
---|
78 | foreach (var value in values) {
|
---|
79 | equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
|
---|
80 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
81 | equal = equal && value.X.Value == value.Y.Value;
|
---|
82 | }
|
---|
83 | }
|
---|
84 | if (equal) {
|
---|
85 | var values = x.AlgorithmParameterStringValues.Zip(y.AlgorithmParameterStringValues, (a, b) => new { X = a, Y = b });
|
---|
86 | foreach (var value in values) {
|
---|
87 | equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
|
---|
88 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
89 | equal = equal && value.X.Value == value.Y.Value;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (equal) {
|
---|
94 | var values = x.ProblemParameterBlobValues.Zip(y.ProblemParameterBlobValues, (a, b) => new { X = a, Y = b });
|
---|
95 | foreach (var value in values) {
|
---|
96 | equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
|
---|
97 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
98 | equal = equal && value.X.Value.Length == value.Y.Value.Length;
|
---|
99 | if (equal) {
|
---|
100 | byte[] xBlob = value.X.Value.ToArray();
|
---|
101 | byte[] yBlob = value.Y.Value.ToArray();
|
---|
102 | int i = 0;
|
---|
103 | while (equal && (i < xBlob.Length)) {
|
---|
104 | equal = equal && xBlob[i] == yBlob[i];
|
---|
105 | i++;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | if (equal) {
|
---|
111 | var values = x.ProblemParameterBoolValues.Zip(y.ProblemParameterBoolValues, (a, b) => new { X = a, Y = b });
|
---|
112 | foreach (var value in values) {
|
---|
113 | equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
|
---|
114 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
115 | equal = equal && value.X.Value == value.Y.Value;
|
---|
116 | }
|
---|
117 | }
|
---|
118 | if (equal) {
|
---|
119 | var values = x.ProblemParameterFloatValues.Zip(y.ProblemParameterFloatValues, (a, b) => new { X = a, Y = b });
|
---|
120 | foreach (var value in values) {
|
---|
121 | equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
|
---|
122 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
123 | equal = equal && value.X.Value == value.Y.Value;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | if (equal) {
|
---|
127 | var values = x.ProblemParameterIntValues.Zip(y.ProblemParameterIntValues, (a, b) => new { X = a, Y = b });
|
---|
128 | foreach (var value in values) {
|
---|
129 | equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
|
---|
130 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
131 | equal = equal && value.X.Value == value.Y.Value;
|
---|
132 | }
|
---|
133 | }
|
---|
134 | if (equal) {
|
---|
135 | var values = x.ProblemParameterStringValues.Zip(y.ProblemParameterStringValues, (a, b) => new { X = a, Y = b });
|
---|
136 | foreach (var value in values) {
|
---|
137 | equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
|
---|
138 | equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
|
---|
139 | equal = equal && value.X.Value == value.Y.Value;
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | return equal;
|
---|
144 | }
|
---|
145 |
|
---|
146 | public int GetHashCode(Experiment obj) {
|
---|
147 | return obj.GetHashCode();
|
---|
148 | }
|
---|
149 | }
|
---|
150 | }
|
---|