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

Last change on this file since 15511 was 15511, checked in by abeham, 21 months ago

#1614: Improved performance by switching from Dictionary to Array

File size: 2.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
29  [Item("N-Move", "An N-Move describes the relocation of n equipments to n different locations.")]
30  [StorableClass]
31  public class NMove : Item {
32    [Storable]
33    private int[] reassignments;
34    /// <summary>
35    /// Contains for each equipment the newly assigned location.
36    /// </summary>
37    /// <remarks>
38    /// Locations are 1-based. A 0 indicates that this equipment is not reassigned.
39    /// </remarks>
40    public IReadOnlyList<int> Reassignments {
41      get { return reassignments; }
42    }
43    [Storable]
44    private List<int> indices;
45    /// <summary>
46    /// Which indices (=equipments) are reassigned.
47    /// </summary>
48    /// <remarks>
49    /// Equipments are 0-based.
50    /// </remarks>
51    public IReadOnlyList<int> Indices {
52      get { return indices; }
53    }
54
55    public int N { get { return Indices.Count; } }
56
57    [StorableConstructor]
58    protected NMove(bool deserializing) : base(deserializing) { }
59    protected NMove(NMove original, Cloner cloner)
60      : base(original, cloner) {
61      reassignments = original.reassignments.ToArray();
62      indices = original.indices.ToList();
63    }
64    public NMove(int[] reassignments, List<int> indices)
65      : base() {
66      this.reassignments = reassignments;
67      this.indices = indices;
68    }
69
70    public override IDeepCloneable Clone(Cloner cloner) {
71      return new NMove(this, cloner);
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.