[9563] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[13032] | 3 | * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[9563] | 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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[14046] | 25 | using HeuristicLab.Problems.BinPacking;
|
---|
[9563] | 26 |
|
---|
| 27 | namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
|
---|
| 28 | [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.")]
|
---|
| 29 | [StorableClass]
|
---|
| 30 | public class SingleGroupingMove : MultiComponentVectorMove {
|
---|
| 31 | [Storable]
|
---|
| 32 | public int OldGroup { get; protected set; }
|
---|
| 33 | [Storable]
|
---|
| 34 | public int Index { get; protected set; }
|
---|
| 35 | [Storable]
|
---|
| 36 | public int NewGroup { get; protected set; }
|
---|
| 37 |
|
---|
| 38 | [StorableConstructor]
|
---|
| 39 | protected SingleGroupingMove(bool deserializing) : base(deserializing) { }
|
---|
| 40 | protected SingleGroupingMove(SingleGroupingMove original, Cloner cloner)
|
---|
| 41 | : base(original, cloner) {
|
---|
| 42 | this.OldGroup = original.OldGroup;
|
---|
| 43 | this.Index = original.Index;
|
---|
| 44 | this.NewGroup = original.NewGroup;
|
---|
| 45 | }
|
---|
| 46 | public SingleGroupingMove(int oldGroup, int index, int newGroup, MultiComponentVectorEncoding multiComponentVector)
|
---|
| 47 | : base(multiComponentVector) {
|
---|
| 48 | OldGroup = oldGroup;
|
---|
| 49 | Index = index;
|
---|
| 50 | NewGroup = newGroup;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 54 | return new SingleGroupingMove(this, cloner);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public override IPackingSolutionEncoding GetSolutionAfterMove() {
|
---|
| 58 | return GetVectorAfterMove(MultiComponentVector, OldGroup, Index, NewGroup);
|
---|
| 59 | }
|
---|
| 60 | public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding originalSolution, int oldBin, int index, int newBin) {
|
---|
| 61 | var solution = originalSolution.Clone (new Cloner()) as MultiComponentVectorEncoding;
|
---|
| 62 | var itemgene = solution.PackingInformations[oldBin][index];
|
---|
| 63 | solution.PackingInformations[oldBin].Remove(itemgene);
|
---|
| 64 | solution.PackingInformations[newBin].Add(itemgene);
|
---|
| 65 | return solution;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | public override System.Type GetMoveAttributeType() {
|
---|
| 69 | return typeof(SingleGroupingMoveAttribute);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public override string ToString() {
|
---|
| 73 | return "GM(og"+OldGroup+",i="+Index+",ng="+NewGroup+")";
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public override MultiComponentVectorMoveAttribute GetAttribute(double quality) {
|
---|
| 77 | return new SingleGroupingMoveAttribute(OldGroup, Index,
|
---|
| 78 | MultiComponentVector.PackingInformations[OldGroup][Index].ItemID, NewGroup, quality);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) {
|
---|
| 82 | SingleGroupingMoveAttribute actualAttribute = attribute as SingleGroupingMoveAttribute;
|
---|
| 83 | if (actualAttribute != null) {
|
---|
| 84 | if (hardCriterion) {
|
---|
| 85 | if (MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID
|
---|
| 86 | || NewGroup == actualAttribute.NewGroup)
|
---|
| 87 | return true;
|
---|
| 88 | } else {
|
---|
| 89 | if (MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID
|
---|
| 90 | && NewGroup == actualAttribute.NewGroup)
|
---|
| 91 | return true;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | return false;
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | } |
---|