Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/Multi/Moves/ChangePositionMove.cs @ 14046

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

#1966: unified namespaces

File size: 4.2 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("ChangePositionMove", "A move on a multi component vector that is specified by two indexes. The packing informations at the first index is inserted at the second one.")]
29  [StorableClass]
30  public class ChangePositionMove : MultiComponentVectorMove {
31    [Storable]
32    public int AffectedGroup { get; protected set; }
33    [Storable]
34    public int Index { get; protected set; }
35    [Storable]
36    public int TargetIndex { get; protected set; }
37
38    [StorableConstructor]
39    protected ChangePositionMove(bool deserializing) : base(deserializing) { }
40    protected ChangePositionMove(ChangePositionMove original, Cloner cloner)
41      : base(original, cloner) {
42      this.AffectedGroup = original.AffectedGroup;
43      this.Index = original.Index;
44      this.TargetIndex = original.TargetIndex;
45    }
46    public ChangePositionMove(int affectedBin, int index, int targetIndex, MultiComponentVectorEncoding multiComponentVector)
47      : base(multiComponentVector) {
48        AffectedGroup = affectedBin;
49        Index = index;
50        TargetIndex = targetIndex;
51    }
52
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new ChangePositionMove(this, cloner);
55    }
56
57    public override IPackingSolutionEncoding GetSolutionAfterMove() {
58      return GetVectorAfterMove(MultiComponentVector, AffectedGroup, Index, TargetIndex);
59    }
60    public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedBin, int index, int targetIndex) {
61      var result = multiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding;
62      var aux = result.PackingInformations[affectedBin][index];
63      result.PackingInformations[affectedBin].Remove(aux);
64      result.PackingInformations[affectedBin].Insert(targetIndex, aux);
65      return result;
66    }
67
68    public override System.Type GetMoveAttributeType() {
69      return typeof(ChangePositionMoveAttribute);
70    }
71
72    public override string ToString() {
73      return "PM(g=" + AffectedGroup  + ",i=" + Index + ",ti=" + TargetIndex + ")";
74    }
75
76    public override MultiComponentVectorMoveAttribute GetAttribute(double quality) {
77      return new ChangePositionMoveAttribute(AffectedGroup, Index,
78        MultiComponentVector.PackingInformations[AffectedGroup][Index].ItemID,
79        TargetIndex, quality);
80    }
81
82    public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) {
83      ChangePositionMoveAttribute actualAttribute = attribute as ChangePositionMoveAttribute;
84      if (actualAttribute != null) {
85        if (hardCriterion) {
86          if (Index == actualAttribute.Index
87          || TargetIndex == actualAttribute.TargetIndex
88          || MultiComponentVector.PackingInformations[AffectedGroup][Index].ItemID == actualAttribute.ItemID)
89            return true;
90        } else {
91          if (Index == actualAttribute.Index
92          && TargetIndex == actualAttribute.TargetIndex
93          && MultiComponentVector.PackingInformations[AffectedGroup][Index].ItemID == actualAttribute.ItemID)
94            return true;
95        }
96      }
97
98      return false;
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.