Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HLScript/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/JSMEncoding.cs @ 10568

Last change on this file since 10568 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.3 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.Text;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.PermutationEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix {
29  [Item("JobSequenceMatrixEncoding", "Represents an encoding for a scheduling Problem using a list of job sequences to deliver scheduleinformation.")]
30  [StorableClass]
31  public class JSMEncoding : Item, IScheduleEncoding {
32
33    [Storable]
34    public ItemList<Permutation> JobSequenceMatrix { get; set; }
35
36    [StorableConstructor]
37    protected JSMEncoding(bool deserializing) : base(deserializing) { }
38    protected JSMEncoding(JSMEncoding original, Cloner cloner)
39      : base(original, cloner) {
40      this.JobSequenceMatrix = cloner.Clone(original.JobSequenceMatrix);
41    }
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new JSMEncoding(this, cloner);
44    }
45    public JSMEncoding()
46      : base() {
47      JobSequenceMatrix = new ItemList<Permutation>();
48    }
49
50    public override string ToString() {
51      StringBuilder sb = new StringBuilder();
52      sb.Append("[ ");
53
54      foreach (Permutation p in JobSequenceMatrix) {
55        sb.Append(p.ToString() + " \n");
56      }
57
58      sb.Append("]");
59      return sb.ToString();
60    }
61
62
63    public override bool Equals(object obj) {
64      if (obj.GetType() == typeof(JSMEncoding))
65        return AreEqual(this, obj as JSMEncoding);
66
67      return false;
68    }
69    public override int GetHashCode() {
70      if (JobSequenceMatrix.Count == 1)
71        return JobSequenceMatrix[0].GetHashCode();
72      if (JobSequenceMatrix.Count == 2)
73        return JobSequenceMatrix[0].GetHashCode() ^ JobSequenceMatrix[1].GetHashCode();
74      return 0;
75    }
76    private static bool AreEqual(JSMEncoding jSMEncoding1, JSMEncoding jSMEncoding2) {
77      if (jSMEncoding1.JobSequenceMatrix.Count != jSMEncoding2.JobSequenceMatrix.Count)
78        return false;
79      for (int i = 0; i < jSMEncoding1.JobSequenceMatrix.Count; i++) {
80        if (!AreEqual(jSMEncoding1.JobSequenceMatrix[i], jSMEncoding2.JobSequenceMatrix[i]))
81          return false;
82      }
83      return true;
84    }
85
86    private static bool AreEqual(Permutation p1, Permutation p2) {
87      if (p1.Length != p2.Length)
88        return false;
89      for (int i = 0; i < p1.Length; i++) {
90        if (p1[i] != p2[i])
91          return false;
92      }
93      return true;
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.