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

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

#1966: unified namespaces

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