#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 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 HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Encodings.ConditionActionEncoding;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Encodings.VariableVector {
[StorableClass]
[Item("VariableVectorActionComparer", "")]
public class VariableVectorActionComparer : Item, IEqualityComparer, IClassifierComparer {
[StorableConstructor]
protected VariableVectorActionComparer(bool deserializing) : base(deserializing) { }
protected VariableVectorActionComparer(VariableVectorActionComparer original, Cloner cloner)
: base(original, cloner) {
}
public override IDeepCloneable Clone(Cloner cloner) {
return new VariableVectorActionComparer(this, cloner);
}
public VariableVectorActionComparer() : base() { }
public bool Equals(VariableVectorAction x, VariableVectorAction y) {
var xEnumerator = x.VariableDictionary.Keys.GetEnumerator();
var yEnumerator = y.VariableDictionary.Keys.GetEnumerator();
while (xEnumerator.MoveNext() && yEnumerator.MoveNext()) {
if (xEnumerator.Current != yEnumerator.Current ||
!x.VariableDictionary[xEnumerator.Current].Identical(y.VariableDictionary[yEnumerator.Current])) {
return false;
}
}
return !xEnumerator.MoveNext() && !yEnumerator.MoveNext();
}
public int GetHashCode(VariableVectorAction obj) {
int result = 1;
foreach (var key in obj.VariableDictionary.Keys) {
result = 37 * result + key.GetHashCode();
}
foreach (var val in obj.VariableDictionary.Values) {
result = 37 * result + val.GetHashCode();
}
return result;
}
public bool Equals(IAction x, IAction y) {
var xCast = x as VariableVectorAction;
var yCast = y as VariableVectorAction;
return x != null && y != null && Equals(xCast, yCast);
}
public int GetHashCode(IAction obj) {
var objCast = obj as VariableVectorAction;
return objCast != null ? GetHashCode(objCast) : obj.GetHashCode();
}
}
}