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