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 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
25 | using HeuristicLab.Problems.BinPacking;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
|
---|
28 | [Item("SwapPositionMove", "A move on a multi component vector that is specified by two indexes. The packing informations at the speciefied indexes are beeing swapped.")]
|
---|
29 | [StorableClass]
|
---|
30 | public class SwapPositionMove : MultiComponentVectorMove {
|
---|
31 | [Storable]
|
---|
32 | public int AffectedGroup { get; protected set; }
|
---|
33 | [Storable]
|
---|
34 | public int Index1 { get; protected set; }
|
---|
35 | [Storable]
|
---|
36 | public int Index2 { get; protected set; }
|
---|
37 |
|
---|
38 | [StorableConstructor]
|
---|
39 | protected SwapPositionMove(bool deserializing) : base(deserializing) { }
|
---|
40 | protected SwapPositionMove(SwapPositionMove original, Cloner cloner)
|
---|
41 | : base(original, cloner) {
|
---|
42 | this.AffectedGroup = original.AffectedGroup;
|
---|
43 | this.Index1 = original.Index1;
|
---|
44 | this.Index2 = original.Index2;
|
---|
45 | }
|
---|
46 | public SwapPositionMove(int affectedGroup, int index1, int index2, MultiComponentVectorEncoding multiComponentVector)
|
---|
47 | : base(multiComponentVector) {
|
---|
48 | AffectedGroup = affectedGroup;
|
---|
49 | Index1 = index1;
|
---|
50 | Index2 = index2;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
54 | return new SwapPositionMove(this, cloner);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public override IPackingSolutionEncoding GetSolutionAfterMove() {
|
---|
58 | return GetVectorAfterMove(MultiComponentVector, AffectedGroup, Index1, Index2);
|
---|
59 | }
|
---|
60 | public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedGroup, int index1, int index2) {
|
---|
61 | var result = multiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding;
|
---|
62 | var aux = result.PackingInformations[affectedGroup][index1];
|
---|
63 | result.PackingInformations[affectedGroup][index1] = result.PackingInformations[affectedGroup][index2];
|
---|
64 | result.PackingInformations[affectedGroup][index2] = aux;
|
---|
65 | return result;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public override System.Type GetMoveAttributeType() {
|
---|
69 | return typeof(SwapPositionMoveAttribute);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public override string ToString() {
|
---|
73 | return "SPM(g=" + AffectedGroup + ",i1=" + Index1 + ",i2=" + Index2 + ")";
|
---|
74 | }
|
---|
75 |
|
---|
76 | public override MultiComponentVectorMoveAttribute GetAttribute(double quality) {
|
---|
77 | return new SwapPositionMoveAttribute(AffectedGroup, Index1, Index2,
|
---|
78 | MultiComponentVector.PackingInformations[AffectedGroup][Index1].ItemID,
|
---|
79 | MultiComponentVector.PackingInformations[AffectedGroup][Index2].ItemID, quality);
|
---|
80 | }
|
---|
81 |
|
---|
82 | public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) {
|
---|
83 | SwapPositionMoveAttribute actualAttribute = attribute as SwapPositionMoveAttribute;
|
---|
84 | if (actualAttribute != null) {
|
---|
85 | if (hardCriterion) {
|
---|
86 | if (Index1 == actualAttribute.Index1
|
---|
87 | || Index2 == actualAttribute.Index2
|
---|
88 | || MultiComponentVector.PackingInformations[AffectedGroup][Index1].ItemID == actualAttribute.ItemID1
|
---|
89 | || MultiComponentVector.PackingInformations[AffectedGroup][Index2].ItemID == actualAttribute.ItemID2)
|
---|
90 | return true;
|
---|
91 | } else {
|
---|
92 | if (Index1 == actualAttribute.Index1
|
---|
93 | && Index2 == actualAttribute.Index2
|
---|
94 | && MultiComponentVector.PackingInformations[AffectedGroup][Index1].ItemID == actualAttribute.ItemID1
|
---|
95 | && MultiComponentVector.PackingInformations[AffectedGroup][Index2].ItemID == actualAttribute.ItemID2)
|
---|
96 | return true;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | return false;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | } |
---|