Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/PackingSequenceEncoding.cs @ 13032

Last change on this file since 13032 was 13032, checked in by gkronber, 9 years ago

#1966:

  • removed unused using
  • added/updated license headers
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.Interfaces;
29
30namespace HeuristicLab.Encodings.PackingEncoding.PackingSequence {
31  [Item("Packing Sequence Encoding", "Represents an encoding for a bin packing problem using permutation of item-indexes to define the packing sequence.")]
32  [StorableClass]
33  public class PackingSequenceEncoding : Item, IPackingSolutionEncoding {
34
35    [Storable]
36    public Permutation PackingSequence { get; set; }
37
38    [StorableConstructor]
39    protected PackingSequenceEncoding(bool deserializing) : base(deserializing) { }
40    protected PackingSequenceEncoding(PackingSequenceEncoding original, Cloner cloner)
41      : base(original, cloner) {
42      this.PackingSequence = cloner.Clone(original.PackingSequence);
43    }
44    public override IDeepCloneable Clone(Cloner cloner) {
45      return new PackingSequenceEncoding(this, cloner);
46    }
47
48    public PackingSequenceEncoding()
49      : base() {
50      PackingSequence = new Permutation();
51    }
52
53    public override string ToString() {
54      StringBuilder sb = new StringBuilder();
55      sb.Append("[ ");
56      sb.Append(PackingSequence.ToString() + " \n");
57      sb.Append("]");
58      return sb.ToString();
59    }
60
61
62    public override bool Equals(object obj) {
63      if (obj.GetType() == typeof(PackingSequenceEncoding))
64        return AreEqual(this, obj as PackingSequenceEncoding);
65
66      return false;
67    }
68    public override int GetHashCode() {
69      return PackingSequence.GetHashCode();
70    }
71    private static bool AreEqual(PackingSequenceEncoding packingSequenceEncoding1, PackingSequenceEncoding packingSequenceEncoding2) {
72      return AreEqual(packingSequenceEncoding1.PackingSequence, packingSequenceEncoding2.PackingSequence);
73    }
74
75    private static bool AreEqual(Permutation p1, Permutation p2) {
76      if (p1.Length != p2.Length)
77        return false;
78      for (int i = 0; i < p1.Length; i++) {
79        if (p1[i] != p2[i])
80          return false;
81      }
82      return true;
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.