1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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 |
|
---|
28 | namespace 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 | [Storable]
|
---|
33 | public ItemList<Permutation> JobSequenceMatrix { get; set; }
|
---|
34 |
|
---|
35 | [StorableConstructor]
|
---|
36 | protected JSMEncoding(bool deserializing) : base(deserializing) { }
|
---|
37 | protected JSMEncoding(JSMEncoding original, Cloner cloner)
|
---|
38 | : base(original, cloner) {
|
---|
39 | this.JobSequenceMatrix = cloner.Clone(original.JobSequenceMatrix);
|
---|
40 | }
|
---|
41 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
42 | return new JSMEncoding(this, cloner);
|
---|
43 | }
|
---|
44 | public JSMEncoding()
|
---|
45 | : base() {
|
---|
46 | JobSequenceMatrix = new ItemList<Permutation>();
|
---|
47 | }
|
---|
48 |
|
---|
49 | public override string ToString() {
|
---|
50 | StringBuilder sb = new StringBuilder();
|
---|
51 | sb.Append("[ ");
|
---|
52 |
|
---|
53 | foreach (Permutation p in JobSequenceMatrix) {
|
---|
54 | sb.Append(p.ToString() + " \n");
|
---|
55 | }
|
---|
56 |
|
---|
57 | sb.Append("]");
|
---|
58 | return sb.ToString();
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | public override bool Equals(object obj) {
|
---|
63 | if (obj.GetType() == typeof(JSMEncoding))
|
---|
64 | return AreEqual(this, obj as JSMEncoding);
|
---|
65 |
|
---|
66 | return false;
|
---|
67 | }
|
---|
68 | public override int GetHashCode() {
|
---|
69 | if (JobSequenceMatrix.Count == 1)
|
---|
70 | return JobSequenceMatrix[0].GetHashCode();
|
---|
71 | if (JobSequenceMatrix.Count == 2)
|
---|
72 | return JobSequenceMatrix[0].GetHashCode() ^ JobSequenceMatrix[1].GetHashCode();
|
---|
73 | return 0;
|
---|
74 | }
|
---|
75 | private static bool AreEqual(JSMEncoding jSMEncoding1, JSMEncoding jSMEncoding2) {
|
---|
76 | if (jSMEncoding1.JobSequenceMatrix.Count != jSMEncoding2.JobSequenceMatrix.Count)
|
---|
77 | return false;
|
---|
78 | for (int i = 0; i < jSMEncoding1.JobSequenceMatrix.Count; i++) {
|
---|
79 | if (!AreEqual(jSMEncoding1.JobSequenceMatrix[i], jSMEncoding2.JobSequenceMatrix[i]))
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 | return true;
|
---|
83 | }
|
---|
84 |
|
---|
85 | private static bool AreEqual(Permutation p1, Permutation p2) {
|
---|
86 | if (p1.Length != p2.Length)
|
---|
87 | return false;
|
---|
88 | for (int i = 0; i < p1.Length; i++) {
|
---|
89 | if (p1[i] != p2[i])
|
---|
90 | return false;
|
---|
91 | }
|
---|
92 | return true;
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|