#region License Information
/* HeuristicLab
* Copyright (C) 2002-2013 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.Optimization;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Analysis.SolutionCaching {
public enum ProducedBy { Other = 0, Crossover = 1, Mutation = 2, CrossoverAndMutation = 3, Move = 4 };
[Item("SolutionInformation", "Stores meta-information about a solution.")]
[StorableClass]
public class SolutionInformation : Item {
[Storable]
public ProducedBy ProducedBy { get; set; }
[Storable]
public List Predecessors { get; set; }
[Storable]
public int Iteration { get; set; }
[Storable]
public ResultCollection InfoStore { get; set; }
public SolutionInformation() {
Predecessors = new List();
InfoStore = new ResultCollection();
}
[StorableConstructor]
protected SolutionInformation(bool deserializing) : base(deserializing) { }
protected SolutionInformation(SolutionInformation original, Cloner cloner)
: base(original, cloner) {
this.ProducedBy = original.ProducedBy;
this.Predecessors = new List(original.Predecessors);
this.Iteration = original.Iteration;
this.InfoStore = (ResultCollection)original.InfoStore.Clone(cloner);
}
public override IDeepCloneable Clone(Cloner cloner) {
return new SolutionInformation(this, cloner);
}
public override bool Equals(object obj) {
SolutionInformation pi = obj as SolutionInformation;
if (pi == null) return false;
if (ProducedBy == pi.ProducedBy && Iteration == pi.Iteration) {
if (pi.Predecessors == null && Predecessors == null) return true;
if (pi.Predecessors != null && Predecessors == null ||
pi.Predecessors == null && Predecessors != null) return false;
if (pi.Predecessors.Count != Predecessors.Count) return false;
foreach (var p in Predecessors) {
if (!pi.Predecessors.Contains(p)) return false;
}
foreach (IResult info in InfoStore) {
if (!pi.InfoStore.Contains(info)) return false;
}
return true;
} else {
return false;
}
}
public virtual void AddInfo(Result info) {
InfoStore.Add(info);
}
}
}