Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/GroupingVectorEncoding.cs @ 9348

Last change on this file since 9348 was 9348, checked in by jhelm, 11 years ago

#1966: First working version of bin-packing problems.

File size: 3.0 KB
Line 
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
22using System.Text;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.IntegerVectorEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.BinPacking.Interfaces;
29
30namespace HeuristicLab.Encodings.PackingEncoding.GroupingVector {
31  [Item("Grouping Vector Encoding", "Represents an encoding for a bin packing problem using an array of group-assignments for every packing-item.")]
32  [StorableClass]
33  public class GroupingVectorEncoding : Item, IPackingSolutionEncoding{
34
35    [Storable]
36    public IntegerVector GroupingVector { get; set; }
37
38    [StorableConstructor]
39    protected GroupingVectorEncoding(bool deserializing) : base(deserializing) { }
40    protected GroupingVectorEncoding(GroupingVectorEncoding original, Cloner cloner)
41      : base(original, cloner) {
42        this.GroupingVector = cloner.Clone(original.GroupingVector);
43    }
44    public override IDeepCloneable Clone(Cloner cloner) {
45      return new GroupingVectorEncoding(this, cloner);
46    }
47
48    public GroupingVectorEncoding()
49      : base() {
50        GroupingVector = new IntegerVector();
51    }
52
53    public override string ToString() {
54      StringBuilder sb = new StringBuilder();
55      sb.Append("[ ");
56      sb.Append(GroupingVector.ToString());         
57      sb.Append("]");
58      return sb.ToString();
59    }
60
61
62    public override bool Equals(object obj) {
63      if (obj.GetType() == typeof(GroupingVectorEncoding))
64        return AreEqual(this, obj as GroupingVectorEncoding);
65
66      return false;
67    }
68    public override int GetHashCode() {
69      return GroupingVector.GetHashCode();
70    }
71    private static bool AreEqual(GroupingVectorEncoding groupingVectorEncoding1, GroupingVectorEncoding groupingVectorEncoding2) {
72      return AreEqual(groupingVectorEncoding1.GroupingVector, groupingVectorEncoding2.GroupingVector);
73    }
74
75    private static bool AreEqual(IntArray v1, IntArray v2) {
76      if (v1.Length != v2.Length)
77        return false;
78      for (int i = 0; i < v1.Length; i++) {
79        if (v1[i] != v2[i])
80          return false;
81      }
82      return true;
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.