Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/Multi/Moves/SingleItemRotationMove.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: 4.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("SingleItemRotationMove", "A move on a multi component vector that is specified by a single index. The item at the specified index is rotated.")]
30  [StorableClass]
31  public class SingleItemRotationMove : MultiComponentVectorMove {
32    [Storable]
33    public int AffectedGroup { get; protected set; }
34    [Storable]
35    public int Index { get; protected set; }
36
37    [StorableConstructor]
38    protected SingleItemRotationMove(bool deserializing) : base(deserializing) { }
39    protected SingleItemRotationMove(SingleItemRotationMove original, Cloner cloner)
40      : base(original, cloner) {
41        this.AffectedGroup = original.AffectedGroup;
42        this.Index = original.Index;
43    }
44    public SingleItemRotationMove(int affectedBin, int index, MultiComponentVectorEncoding multiComponentVector)
45      : base(multiComponentVector) {
46        AffectedGroup = affectedBin;
47        Index = index;
48    }
49
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new SingleItemRotationMove(this, cloner);
52    }
53
54    public override IPackingSolutionEncoding GetSolutionAfterMove() {
55      return GetVectorAfterMove (MultiComponentVector, AffectedGroup, Index);
56    }
57    public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedGroup, int index) {
58      var result = multiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding;
59      result.PackingInformations[affectedGroup][index].Rotated = !result.PackingInformations[affectedGroup][index].Rotated;
60      return result;
61    }
62
63    public override System.Type GetMoveAttributeType() {
64      return typeof(SingleItemRotationMoveAttribute);
65    }
66
67    public override string ToString() {
68      return "RM(g=" + AffectedGroup + ",i=" + Index + ")";
69    }
70
71    public override MultiComponentVectorMoveAttribute GetAttribute(double quality) {
72        return new SingleItemRotationMoveAttribute(AffectedGroup, Index,
73          MultiComponentVector.PackingInformations[AffectedGroup][Index].ItemID,
74          MultiComponentVector.PackingInformations[AffectedGroup][Index].Rotated, quality);
75    }
76
77    public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) {
78      SingleItemRotationMoveAttribute actualAttribute = attribute as SingleItemRotationMoveAttribute;
79      if (actualAttribute != null) {
80        if (hardCriterion) {
81          if (AffectedGroup == actualAttribute.AffectedGroup || MultiComponentVector.PackingInformations[AffectedGroup][Index].Rotated == actualAttribute.ItemRotation)
82            return true;
83        } else {
84          if (AffectedGroup == actualAttribute.AffectedGroup && MultiComponentVector.PackingInformations[AffectedGroup][Index].Rotated == actualAttribute.ItemRotation)
85            return true;
86        }
87      }
88      return false;
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.