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 @ 13032

Last change on this file since 13032 was 13032, checked in by gkronber, 8 years ago

#1966:

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