Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1966_HeuristicLab.BinPacking/old files/PackingSequence/PackingSequenceEncoding.cs @ 16755

Last change on this file since 16755 was 14046, checked in by gkronber, 8 years ago

#1966: unified namespaces

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Joseph Helm and 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
23using System.Text;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.BinPacking;
29
30
31namespace HeuristicLab.Encodings.PackingEncoding.PackingSequence {
32  [Item("Packing Sequence Encoding", "Represents an encoding for a bin packing problem using permutation of item-indexes to define the packing sequence.")]
33  [StorableClass]
34  public class PackingSequenceEncoding : Item, IPackingSolutionEncoding {
35
36    [Storable]
37    public Permutation PackingSequence { get; set; }
38
39    [StorableConstructor]
40    protected PackingSequenceEncoding(bool deserializing) : base(deserializing) { }
41    protected PackingSequenceEncoding(PackingSequenceEncoding original, Cloner cloner)
42      : base(original, cloner) {
43      this.PackingSequence = cloner.Clone(original.PackingSequence);
44    }
45    public override IDeepCloneable Clone(Cloner cloner) {
46      return new PackingSequenceEncoding(this, cloner);
47    }
48
49    public PackingSequenceEncoding()
50      : base() {
51      PackingSequence = new Permutation();
52    }
53
54    public override string ToString() {
55      StringBuilder sb = new StringBuilder();
56      sb.Append("[ ");
57      sb.Append(PackingSequence.ToString() + " \n");
58      sb.Append("]");
59      return sb.ToString();
60    }
61
62
63    public override bool Equals(object obj) {
64      if (obj.GetType() == typeof(PackingSequenceEncoding))
65        return AreEqual(this, obj as PackingSequenceEncoding);
66
67      return false;
68    }
69    public override int GetHashCode() {
70      return PackingSequence.GetHashCode();
71    }
72    private static bool AreEqual(PackingSequenceEncoding packingSequenceEncoding1, PackingSequenceEncoding packingSequenceEncoding2) {
73      return AreEqual(packingSequenceEncoding1.PackingSequence, packingSequenceEncoding2.PackingSequence);
74    }
75
76    private static bool AreEqual(Permutation p1, Permutation p2) {
77      if (p1.Length != p2.Length)
78        return false;
79      for (int i = 0; i < p1.Length; i++) {
80        if (p1[i] != p2[i])
81          return false;
82      }
83      return true;
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.