[10023] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 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 HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[10096] | 25 | using HeuristicLab.Optimization;
|
---|
[10023] | 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Analysis.SolutionCaching {
|
---|
[10105] | 29 | public enum ProducedBy { Other = 0, Crossover = 1, Mutation = 2, CrossoverAndMutation = 3, Move = 4 };
|
---|
[10023] | 30 |
|
---|
| 31 | [Item("SolutionInformation", "Stores meta-information about a solution.")]
|
---|
| 32 | [StorableClass]
|
---|
| 33 | public class SolutionInformation<T> : Item {
|
---|
| 34 | [Storable]
|
---|
| 35 | public ProducedBy ProducedBy { get; set; }
|
---|
| 36 | [Storable]
|
---|
[10105] | 37 | public List<T> Predecessors { get; set; }
|
---|
[10023] | 38 | [Storable]
|
---|
[10105] | 39 | public int Iteration { get; set; }
|
---|
[10096] | 40 | [Storable]
|
---|
| 41 | public ResultCollection InfoStore { get; set; }
|
---|
[10023] | 42 |
|
---|
[10096] | 43 | public SolutionInformation() {
|
---|
[10105] | 44 | Predecessors = new List<T>();
|
---|
[10096] | 45 | InfoStore = new ResultCollection();
|
---|
| 46 | }
|
---|
[10023] | 47 |
|
---|
| 48 | [StorableConstructor]
|
---|
| 49 | protected SolutionInformation(bool deserializing) : base(deserializing) { }
|
---|
| 50 | protected SolutionInformation(SolutionInformation<T> original, Cloner cloner)
|
---|
| 51 | : base(original, cloner) {
|
---|
| 52 | this.ProducedBy = original.ProducedBy;
|
---|
[10105] | 53 | this.Predecessors = new List<T>(original.Predecessors);
|
---|
| 54 | this.Iteration = original.Iteration;
|
---|
[10096] | 55 | this.InfoStore = (ResultCollection)original.InfoStore.Clone(cloner);
|
---|
[10023] | 56 | }
|
---|
| 57 |
|
---|
| 58 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 59 | return new SolutionInformation<T>(this, cloner);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public override bool Equals(object obj) {
|
---|
| 63 | SolutionInformation<T> pi = obj as SolutionInformation<T>;
|
---|
| 64 | if (pi == null) return false;
|
---|
| 65 |
|
---|
[10105] | 66 | if (ProducedBy == pi.ProducedBy && Iteration == pi.Iteration) {
|
---|
| 67 | if (pi.Predecessors == null && Predecessors == null) return true;
|
---|
| 68 | if (pi.Predecessors != null && Predecessors == null ||
|
---|
| 69 | pi.Predecessors == null && Predecessors != null) return false;
|
---|
| 70 | if (pi.Predecessors.Count != Predecessors.Count) return false;
|
---|
[10023] | 71 |
|
---|
[10105] | 72 | foreach (var p in Predecessors) {
|
---|
| 73 | if (!pi.Predecessors.Contains(p)) return false;
|
---|
[10023] | 74 | }
|
---|
[10096] | 75 | foreach (IResult info in InfoStore) {
|
---|
| 76 | if (!pi.InfoStore.Contains(info)) return false;
|
---|
| 77 | }
|
---|
[10023] | 78 | return true;
|
---|
| 79 | } else {
|
---|
| 80 | return false;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
[10096] | 83 |
|
---|
| 84 | public virtual void AddInfo(Result info) {
|
---|
| 85 | InfoStore.Add(info);
|
---|
| 86 | }
|
---|
[10023] | 87 | }
|
---|
| 88 | }
|
---|