#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.IntegerVectorEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.BinPacking; namespace HeuristicLab.Encodings.PackingEncoding.GroupingVector { [Item("Change Grouping Move", "A move on a grouping vector that is specified by a single group-assignment-index.")] [StorableClass] public class ChangeGroupingMove : GroupingMove, IPackingMove { [Storable] public int Index { get; protected set; } [Storable] public int NewGroup { get; protected set; } [StorableConstructor] protected ChangeGroupingMove(bool deserializing) : base(deserializing) { } protected ChangeGroupingMove(ChangeGroupingMove original, Cloner cloner) : base(original, cloner) { this.Index = original.Index; this.NewGroup = original.NewGroup; } public ChangeGroupingMove(int index, int newGroup, GroupingVectorEncoding groupingVector) : base(groupingVector) { Index = index; } public override IDeepCloneable Clone(Cloner cloner) { return new ChangeGroupingMove(this, cloner); } public override IPackingSolutionEncoding GetSolutionAfterMove() { GroupingVectorEncoding newSolution = new GroupingVectorEncoding(); newSolution.GroupingVector = new IntegerVector(GroupingVector.GroupingVector); newSolution.GroupingVector[Index] = NewGroup; return newSolution; } public override Type GetMoveAttributeType() { return typeof(ChangeGroupingMoveAttribute); } public override GroupingMoveAttribute GetAttribute(double quality) { return new ChangeGroupingMoveAttribute(Index, NewGroup, quality); } public override bool BelongsToAttribute(GroupingMoveAttribute attribute, bool hardCriterion) { var attr = attribute as ChangeGroupingMoveAttribute; if (attr != null) { if (hardCriterion) { if (Index == attr.ItemIndex) //|| GroupingVector.GroupingVector[Index] == attr.AssignedBin) return true; } else if (Index == attr.ItemIndex && GroupingVector.GroupingVector[Index] == attr.AssignedBin) return true; } return false; } public override string ToString() { return "CGM(i=" + Index + ", g=" + NewGroup + ")"; } } }