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/StochasticNMoveSingleMoveGenerator.cs

    r15504 r15511  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     
    2830using HeuristicLab.Parameters;
    2931using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HeuristicLab.Random;
    3033
    3134namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
     
    5558
    5659    public static NMove GenerateExactlyN(IRandom random, IntegerVector assignment, int n, DoubleArray capacities) {
    57       int[] equipments = new int[n], locations = new int[n];
    58       HashSet<int> chosenEquipments = new HashSet<int>();
    59       for (int i = 0; i < n; i++) {
     60      if (capacities.Length <= 1) throw new ArgumentException("There must be at least two locations.");
     61      var dim = assignment.Length;
     62      var reassignment = new int[dim];
     63      var equipments = Enumerable.Range(0, dim).SampleRandomWithoutRepetition(random, n, dim).ToList();
     64      for (var i = 0; i < n; i++) {
     65        var equip = equipments[i];
    6066        do {
    61           equipments[i] = random.Next(assignment.Length);
    62         } while (chosenEquipments.Contains(equipments[i]));
    63         chosenEquipments.Add(equipments[i]);
    64         do {
    65           locations[i] = random.Next(capacities.Length);
    66         } while (locations[i] == assignment[equipments[i]]);
     67          reassignment[equip] = random.Next(capacities.Length) + 1;
     68        } while (reassignment[equip] == assignment[equip] + 1);
    6769      }
    68       return new NMove(equipments, locations);
     70      return new NMove(reassignment, equipments);
    6971    }
    7072
Note: See TracChangeset for help on using the changeset viewer.