#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 HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.BinPacking; namespace HeuristicLab.Encodings.PackingEncoding.GroupingVector { [Item("Change Grouping Move Generator", "Base class for all ChangeGrouping move generators.")] [StorableClass] public abstract class ChangeGroupingMoveGenerator : SingleSuccessorOperator, IGroupingVectorMoveOperator, IMoveGenerator { public override bool CanChangeName { get { return false; } } public ILookupParameter GroupingVectorParameter { get { return (ILookupParameter)Parameters["GroupingVector"]; } } public ILookupParameter PackingMoveParameter { get { return (LookupParameter)Parameters["PackingMove"]; } } protected ScopeParameter CurrentScopeParameter { get { return (ScopeParameter)Parameters["CurrentScope"]; } } [StorableConstructor] protected ChangeGroupingMoveGenerator(bool deserializing) : base(deserializing) { } protected ChangeGroupingMoveGenerator(ChangeGroupingMoveGenerator original, Cloner cloner) : base(original, cloner) { } public ChangeGroupingMoveGenerator() : base() { Parameters.Add(new LookupParameter("GroupingVector", "The grouping vector for which moves should be generated.")); Parameters.Add(new LookupParameter("PackingMove", "The moves that should be generated in subscopes.")); Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); } public override IOperation Apply() { GroupingVectorEncoding gv = GroupingVectorParameter.ActualValue; ChangeGroupingMove[] moves = GenerateMoves(gv); Scope[] moveScopes = new Scope[moves.Length]; for (int i = 0; i < moveScopes.Length; i++) { moveScopes[i] = new Scope(i.ToString()); moveScopes[i].Variables.Add(new Variable(PackingMoveParameter.ActualName, moves[i])); } CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes); return base.Apply(); } protected abstract ChangeGroupingMove[] GenerateMoves(GroupingVectorEncoding groupingVector); } }