#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 System.Linq; 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) { if (!x.Order.SequenceEqual(y.Order)) return false; foreach (var key in x.Keys) { if (!x[key].Identical(y[key])) { return false; } } return true; } public int GetHashCode(VariableVectorAction obj) { int result = 1; foreach (var key in obj.Keys) { result = 37 * result + key.GetHashCode(); } foreach (var val in obj.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(); } } }