source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMove.cs @ 7407

Last change on this file since 7407 was 7407, checked in by abeham, 8 years ago

#1614: worked on GQAP

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
29  [Item("n-move", "An n-move describes moving n equipments to n locations.")]
30  [StorableClass]
31  public class NMove : Item {
32    [Storable]
33    public int[] Equipments { get; private set; }
34    [Storable]
35    public int[] Locations { get; private set; }
36    [Storable]
37    public IntegerVector OriginalVector { get; private set; }
38
39    public int N { get { return Equipments.Length; } }
40
41    [StorableConstructor]
42    protected NMove(bool deserializing) : base(deserializing) { }
43    protected NMove(NMove original, Cloner cloner)
44      : base(original, cloner) {
45      Equipments = (int[])original.Equipments.Clone();
46      Locations = (int[])original.Locations.Clone();
47      if (original.OriginalVector != null)
48        OriginalVector = cloner.Clone(original.OriginalVector);
49    }
50    public NMove() : this(new int[0], new int[0], null) { }
51    public NMove(int[] equipments, int[] locations) : this(equipments, locations, null) { }
52    public NMove(int[] equipments, int[] locations, IntegerVector originalVector)
53      : base() {
54      if (equipments == null) throw new ArgumentNullException("equipments", "NMove: Equipments must not be null.");
55      if (locations == null) throw new ArgumentNullException("locations", "NMove: Locations must not be null.");
56      if (equipments.Length != locations.Length) throw new ArgumentException("NMove: Length of equipments and locations is not identical.");
57      Equipments = equipments;
58      Locations = locations;
59      OriginalVector = originalVector;
60    }
61
62    public override IDeepCloneable Clone(Cloner cloner) {
63      return new NMove(this, cloner);
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.