Free cookie consent management tool by TermsFeed Policy Generator

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