#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Services.OKB.DataAccess;
namespace HeuristicLab.Services.OKB {
public class ExperimentEqualityComparer : IEqualityComparer {
public bool Equals(Experiment x, Experiment y) {
bool equal = true;
equal = equal && x.AlgorithmId == y.AlgorithmId;
equal = equal && x.ProblemId == y.ProblemId;
equal = equal && x.AlgorithmParameterBlobValues.Count == y.AlgorithmParameterBlobValues.Count;
equal = equal && x.AlgorithmParameterBoolValues.Count == y.AlgorithmParameterBoolValues.Count;
equal = equal && x.AlgorithmParameterFloatValues.Count == y.AlgorithmParameterFloatValues.Count;
equal = equal && x.AlgorithmParameterIntValues.Count == y.AlgorithmParameterIntValues.Count;
equal = equal && x.AlgorithmParameterStringValues.Count == y.AlgorithmParameterStringValues.Count;
equal = equal && x.ProblemParameterBlobValues.Count == y.ProblemParameterBlobValues.Count;
equal = equal && x.ProblemParameterBoolValues.Count == y.ProblemParameterBoolValues.Count;
equal = equal && x.ProblemParameterFloatValues.Count == y.ProblemParameterFloatValues.Count;
equal = equal && x.ProblemParameterIntValues.Count == y.ProblemParameterIntValues.Count;
equal = equal && x.ProblemParameterStringValues.Count == y.ProblemParameterStringValues.Count;
if (equal) {
var values = x.AlgorithmParameterBlobValues.Zip(y.AlgorithmParameterBlobValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value.Length == value.Y.Value.Length;
if (equal) {
byte[] xBlob = value.X.Value.ToArray();
byte[] yBlob = value.Y.Value.ToArray();
int i = 0;
while (equal && (i < xBlob.Length)) {
equal = equal && xBlob[i] == yBlob[i];
i++;
}
}
}
}
if (equal) {
var values = x.AlgorithmParameterBoolValues.Zip(y.AlgorithmParameterBoolValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value == value.Y.Value;
}
}
if (equal) {
var values = x.AlgorithmParameterFloatValues.Zip(y.AlgorithmParameterFloatValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value == value.Y.Value;
}
}
if (equal) {
var values = x.AlgorithmParameterIntValues.Zip(y.AlgorithmParameterIntValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value == value.Y.Value;
}
}
if (equal) {
var values = x.AlgorithmParameterStringValues.Zip(y.AlgorithmParameterStringValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.AlgorithmParameterId == value.Y.AlgorithmParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value == value.Y.Value;
}
}
if (equal) {
var values = x.ProblemParameterBlobValues.Zip(y.ProblemParameterBlobValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value.Length == value.Y.Value.Length;
if (equal) {
byte[] xBlob = value.X.Value.ToArray();
byte[] yBlob = value.Y.Value.ToArray();
int i = 0;
while (equal && (i < xBlob.Length)) {
equal = equal && xBlob[i] == yBlob[i];
i++;
}
}
}
}
if (equal) {
var values = x.ProblemParameterBoolValues.Zip(y.ProblemParameterBoolValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value == value.Y.Value;
}
}
if (equal) {
var values = x.ProblemParameterFloatValues.Zip(y.ProblemParameterFloatValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value == value.Y.Value;
}
}
if (equal) {
var values = x.ProblemParameterIntValues.Zip(y.ProblemParameterIntValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value == value.Y.Value;
}
}
if (equal) {
var values = x.ProblemParameterStringValues.Zip(y.ProblemParameterStringValues, (a, b) => new { X = a, Y = b });
foreach (var value in values) {
equal = equal && value.X.ProblemParameterId == value.Y.ProblemParameterId;
equal = equal && value.X.DataTypeId == value.Y.DataTypeId;
equal = equal && value.X.Value == value.Y.Value;
}
}
return equal;
}
public int GetHashCode(Experiment obj) {
return obj.GetHashCode();
}
}
}