Changeset 15572 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves
- Timestamp:
- 01/03/18 00:28:51 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/StochasticNMoveSingleMoveGenerator.cs
r15553 r15572 65 65 66 66 var reassignment = new int[dim]; 67 reassignment[equip] = ReassignEquipment(random, equip, assignment[equip], locations);67 reassignment[equip] = 1 + (assignment[equip] + random.Next(1, locations)) % locations; 68 68 69 69 return new NMove(reassignment, equipments); … … 74 74 if (locations <= 1) throw new ArgumentException("There must be at least two locations."); 75 75 var dim = assignment.Length; 76 var equipments = new List<int>(2) { random.Next(dim), -1 }; 77 do { 78 equipments[1] = random.Next(dim); 79 } while (equipments[0] == equipments[1]); 76 var equipments = new List<int>(2) { random.Next(dim) }; 77 equipments.Add((equipments[0] + random.Next(1, dim)) % dim); 80 78 81 79 var reassignment = new int[dim]; 82 80 for (var i = 0; i < 2; i++) { 83 81 var equip = equipments[i]; 84 reassignment[equip] = ReassignEquipment(random, equip, assignment[equip], locations);82 reassignment[equip] = 1 + (assignment[equip] + random.Next(1, locations)) % locations; 85 83 } 86 84 return new NMove(reassignment, equipments); … … 98 96 for (var i = 0; i < n; i++) { 99 97 var equip = equipments[i]; 100 reassignment[equip] = ReassignEquipment(random, equip, assignment[equip], locations);98 reassignment[equip] = 1 + (assignment[equip] + random.Next(1, locations)) % locations; 101 99 } 102 100 return new NMove(reassignment, equipments); 103 }104 105 private static int ReassignEquipment(IRandom random, int equip, int prevLocation, int locations) {106 var newLoc = random.Next(locations) + 1;107 while (newLoc == prevLocation + 1)108 newLoc = random.Next(locations) + 1;109 return newLoc;110 101 } 111 102
Note: See TracChangeset
for help on using the changeset viewer.