#region License Information /* HeuristicLab * Copyright (C) 2002-2017 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.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.IntegerVectorEncoding; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { [Item("N-Move Generator", "Base class for move operators that generate N-Move moves.")] [StorableClass] public abstract class GQAPNMoveGenerator : GQAPMoveGenerator, IGQAPNMoveOperator { #region Parameter Descriptions public static readonly string MoveDescription = "Moves represent changes to the current solution. The n-move changes the assignment of up to or exactly n equipments."; #endregion public ILookupParameter MoveParameter { get { return (ILookupParameter)Parameters["Move"]; } } public IValueLookupParameter NParameter { get { return (IValueLookupParameter)Parameters["N"]; } } [StorableConstructor] protected GQAPNMoveGenerator(bool deserializing) : base(deserializing) { } protected GQAPNMoveGenerator(GQAPNMoveGenerator original, Cloner cloner) : base(original, cloner) { } public GQAPNMoveGenerator() : base() { Parameters.Add(new LookupParameter("Move", MoveDescription)); Parameters.Add(new ValueLookupParameter("N", "The maximum number of equipment(s) that should be moved.", new IntValue(2))); } public override IOperation Apply() { List scopes = new List(); int counter = 0; string name = MoveParameter.TranslatedName; foreach (var move in GenerateMoves(AssignmentParameter.ActualValue, NParameter.ActualValue.Value, ProblemInstanceParameter.ActualValue)) { scopes.Add(new Scope(counter.ToString())); scopes.Last().Variables.Add(new Variable(name, move)); counter++; } ExecutionContext.Scope.SubScopes.AddRange(scopes); return base.Apply(); } public abstract IEnumerable GenerateMoves(IntegerVector assignment, int n, GQAPInstance problemInstance); } }