Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/Triple/Moves/MCVTripleMove.cs @ 9563

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

#1966: Implemented additional Operator-Wrappers for PackingSequence and GroupingVector; Implemented additional problem-class for Rosenbauer-Problemstatement; Added marker-interfaces for decoder-types;

File size: 5.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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using HeuristicLab.Problems.BinPacking.Interfaces;
27
28namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
29  [Item("MCVTripleMove", "A move on a multi component vector that is specified by a rotation-value, two indexes and a groupNr.")]
30  [StorableClass]
31  public class MCVTripleMove : MultiComponentVectorMove {   
32    [Storable]
33    public int OldGroup { get; protected set; }
34    [Storable]
35    public int NewGroup { get; protected set; }
36    [Storable]
37    public int Index { get; protected set; }   
38    [Storable]
39    public int TargetIndex { get; protected set; }
40    [Storable]
41    public bool Rotation { get; protected set; }
42
43    [StorableConstructor]
44    protected MCVTripleMove(bool deserializing) : base(deserializing) { }
45    protected MCVTripleMove(MCVTripleMove original, Cloner cloner)
46      : base(original, cloner) {     
47      this.OldGroup = original.OldGroup;
48      this.NewGroup = original.NewGroup;
49      this.Index = original.Index;       
50      this.TargetIndex = original.TargetIndex;
51      this.Rotation = original.Rotation;
52    }
53    public MCVTripleMove(int oldGroup, int newGroup, int index, int targetIndex, bool rotation, MultiComponentVectorEncoding multiComponentVector)
54      : base(multiComponentVector) {
55        OldGroup = oldGroup;
56        NewGroup = newGroup;
57        Index = index;       
58        TargetIndex = targetIndex;
59        Rotation = rotation;
60    }
61
62    public override IDeepCloneable Clone(Cloner cloner) {
63      return new MCVTripleMove(this, cloner);
64    }
65
66    public override IPackingSolutionEncoding GetSolutionAfterMove() {
67      var result = MultiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding;
68      if (Rotation)
69        result = SingleItemRotationMove.GetVectorAfterMove(result, OldGroup, Index);
70      if (!OldGroup.Equals(NewGroup)) {
71        result = SingleGroupingMove.GetVectorAfterMove(result, OldGroup, Index, NewGroup);
72        int newIndex = result.PackingInformations[NewGroup].Count - 1;
73        if (!newIndex.Equals(TargetIndex))
74          result = ChangePositionMove.GetVectorAfterMove(result, NewGroup, newIndex, TargetIndex);
75      } else if (!Index.Equals(TargetIndex))
76          result = ChangePositionMove.GetVectorAfterMove(result, NewGroup, Index, TargetIndex);
77      return result;
78    }
79
80    public override System.Type GetMoveAttributeType() {
81      return typeof(MCVTripleMoveAttribute);
82    }
83
84    public override string ToString() {
85      return "TM(og=" + OldGroup + ",ng=" + NewGroup + ",i=" + Index + ",ti=" + TargetIndex + ",r=" + Rotation + ")";
86    }
87
88
89    public override MultiComponentVectorMoveAttribute GetAttribute(double quality) {
90      return new MCVTripleMoveAttribute(Index, TargetIndex, MultiComponentVector.PackingInformations[OldGroup][Index].ItemID,
91        Rotation, OldGroup, NewGroup, quality);
92    }
93
94    public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) {
95      MCVTripleMoveAttribute actualAttribute = attribute as MCVTripleMoveAttribute;
96      if (actualAttribute != null) {
97        if (hardCriterion) {
98          if (Index == actualAttribute.Index || TargetIndex == actualAttribute.TargetIndex
99                  || MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID
100                  //|| (OldGroup == actualAttribute.GroupBefore && NewGroup == actualAttribute.GroupAfter)
101            )
102            return true;
103        } else {
104          if ((Index == actualAttribute.Index && TargetIndex == actualAttribute.TargetIndex)
105                  && MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID
106                  //&& Rotation == actualAttribute.Rotation
107                  //&& (OldGroup == actualAttribute.GroupBefore && NewGroup == actualAttribute.GroupAfter)
108            )
109            return true;
110        }
111      }
112      return false;
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.