Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/11/17 23:06:32 (7 years ago)
Author:
abeham
Message:

#1614: Improved performance by switching from Dictionary to Array

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMove.cs

    r15504 r15511  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
     23using System.Linq;
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Encodings.IntegerVectorEncoding;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2827
     
    3231  public class NMove : Item {
    3332    [Storable]
    34     public Dictionary<int, int> NewAssignments { get; private set; }
     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    }
    3543    [Storable]
    36     public IntegerVector OriginalVector { get; private set; }
     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    }
    3754
    38     public int N { get { return NewAssignments.Count; } }
     55    public int N { get { return Indices.Count; } }
    3956
    4057    [StorableConstructor]
     
    4259    protected NMove(NMove original, Cloner cloner)
    4360      : base(original, cloner) {
    44       NewAssignments = new Dictionary<int, int>(original.NewAssignments);
    45       if (original.OriginalVector != null)
    46         OriginalVector = cloner.Clone(original.OriginalVector);
     61      reassignments = original.reassignments.ToArray();
     62      indices = original.indices.ToList();
    4763    }
    48     public NMove() : this(new int[0], new int[0], null) { }
    49     public NMove(int[] equipments, int[] locations) : this(equipments, locations, null) { }
    50     public NMove(int[] equipments, int[] locations, IntegerVector originalVector)
     64    public NMove(int[] reassignments, List<int> indices)
    5165      : base() {
    52       if (equipments == null) throw new ArgumentNullException("equipments", "NMove: Equipments must not be null.");
    53       if (locations == null) throw new ArgumentNullException("locations", "NMove: Locations must not be null.");
    54       if (equipments.Length != locations.Length) throw new ArgumentException("NMove: Length of equipments and locations is not identical.");
    55       NewAssignments = new Dictionary<int, int>();
    56       for (int i = 0; i < equipments.Length; i++)
    57         NewAssignments[equipments[i]] = locations[i];
    58       OriginalVector = originalVector;
     66      this.reassignments = reassignments;
     67      this.indices = indices;
    5968    }
    6069
Note: See TracChangeset for help on using the changeset viewer.