Changeset 15511 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/StochasticNMoveSingleMoveGenerator.cs
- Timestamp:
- 12/11/17 23:06:32 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/StochasticNMoveSingleMoveGenerator.cs
r15504 r15511 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 28 30 using HeuristicLab.Parameters; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Random; 30 33 31 34 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { … … 55 58 56 59 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]; 60 66 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); 67 69 } 68 return new NMove( equipments, locations);70 return new NMove(reassignment, equipments); 69 71 } 70 72
Note: See TracChangeset
for help on using the changeset viewer.