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