Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/SolutionInformation.cs @ 10129

Last change on this file since 10129 was 10105, checked in by ascheibe, 11 years ago

#1886 renamed some properties in SolutionInformation as suggested by swagner

File size: 3.2 KB
Line 
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
22using System.Collections.Generic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Optimization;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Analysis.SolutionCaching {
29  public enum ProducedBy { Other = 0, Crossover = 1, Mutation = 2, CrossoverAndMutation = 3, Move = 4 };
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]
37    public List<T> Predecessors { get; set; }
38    [Storable]
39    public int Iteration { get; set; }
40    [Storable]
41    public ResultCollection InfoStore { get; set; }
42
43    public SolutionInformation() {
44      Predecessors = new List<T>();
45      InfoStore = new ResultCollection();
46    }
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;
53      this.Predecessors = new List<T>(original.Predecessors);
54      this.Iteration = original.Iteration;
55      this.InfoStore = (ResultCollection)original.InfoStore.Clone(cloner);
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
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;
71
72        foreach (var p in Predecessors) {
73          if (!pi.Predecessors.Contains(p)) return false;
74        }
75        foreach (IResult info in InfoStore) {
76          if (!pi.InfoStore.Contains(info)) return false;
77        }
78        return true;
79      } else {
80        return false;
81      }
82    }
83
84    public virtual void AddInfo(Result info) {
85      InfoStore.Add(info);
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.