Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/old files/GroupingVector/Moves/SwapGrouping/SwapGroupingMove.cs @ 14498

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

#1966: unified namespaces

File size: 3.6 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 System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Problems.BinPacking;
28
29
30namespace HeuristicLab.Encodings.PackingEncoding.GroupingVector {
31  [Item("Swap Grouping Move", "A move on a grouping vector that is specified by two group-assignment-indexes.")]
32  [StorableClass]
33  public class SwapGroupingMove : GroupingMove, IPackingMove {
34    [Storable]
35    public int Index1 { get; protected set; }
36    [Storable]
37    public int Index2 { get; protected set; }
38
39    [StorableConstructor]
40    protected SwapGroupingMove(bool deserializing) : base(deserializing) { }
41    protected SwapGroupingMove(SwapGroupingMove original, Cloner cloner)
42      : base(original, cloner) {
43      this.Index1 = original.Index1;
44      this.Index2 = original.Index2;
45    }
46    public SwapGroupingMove(int index1, int index2, GroupingVectorEncoding groupingVector)
47      : base(groupingVector) {
48      Index1 = index1;
49      Index2 = index2;
50    }
51
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new SwapGroupingMove(this, cloner);
54    }
55
56    public override IPackingSolutionEncoding GetSolutionAfterMove() {
57      GroupingVectorEncoding newSolution = new GroupingVectorEncoding();
58      newSolution.GroupingVector = new IntegerVector(GroupingVector.GroupingVector);
59      newSolution.GroupingVector[Index1] = GroupingVector.GroupingVector[Index2];
60      newSolution.GroupingVector[Index2] = GroupingVector.GroupingVector[Index1];
61      return newSolution;
62    }
63
64    public override Type GetMoveAttributeType() {
65      return typeof(SwapGroupingMoveAttribute);
66    }
67
68    public override GroupingMoveAttribute GetAttribute(double quality) {
69      return new SwapGroupingMoveAttribute(Index1, Index2, GroupingVector.GroupingVector[Index1], GroupingVector.GroupingVector[Index2], quality);
70    }
71
72    public override bool BelongsToAttribute(GroupingMoveAttribute attribute, bool hardCriterion) {
73      var attr = attribute as SwapGroupingMoveAttribute;
74      if (attr != null) {
75        if (hardCriterion) {
76          if (Index1 == attr.ItemIndex1 || Index2 == attr.ItemIndex2)// || GroupingVector.GroupingVector[Index1] == attr.AssignedBin1 || GroupingVector.GroupingVector[Index2] == attr.AssignedBin2)
77            return true;
78        } else
79          if (Index1 == attr.ItemIndex1 && Index2 == attr.ItemIndex2)// && GroupingVector.GroupingVector[Index1] == attr.AssignedBin1 && GroupingVector.GroupingVector[Index2] == attr.AssignedBin2)
80            return true;
81      }
82      return false;
83    }
84
85    public override string ToString() {
86      return "SGM(i1="+Index1 + ", i2=" + Index2  +")";
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.