Changeset 15572 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/DiscreteLocationCrossover.cs
- Timestamp:
- 01/03/18 00:28:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/DiscreteLocationCrossover.cs
r15564 r15572 83 83 } 84 84 85 var order = Enumerable.Range(0, takenEquip.Length).Shuffle(random); // avoid bias 85 var order = Enumerable.Range(0, takenEquip.Length) 86 .Where(x => !takenEquip[x]) 87 .Shuffle(random); // avoid bias 86 88 foreach (var e in order) { 87 if (takenEquip[e]) continue;88 89 var assigned = false; 89 90 // try 1: find a parent where equipment can be assigned feasibly 90 foreach (var p in Enumerable.Range(0, parents.Length).Shuffle(random)) { 91 if (slack[parents[p][e]] >= demands[e]) { 92 child[e] = parents[p][e]; 91 var fallback = -1; 92 var count = 1; 93 foreach (var p in parents.Shuffle(random)) { 94 if (slack[p[e]] >= demands[e]) { 95 child[e] = p[e]; 93 96 slack[child[e]] -= demands[e]; 94 97 assigned = true; 95 98 break; 99 } else if (random.NextDouble() < 1.0 / count) { 100 fallback = p[e]; 96 101 } 102 count++; 97 103 } 98 104 // try 2: find a random feasible location … … 103 109 child[e] = loc; 104 110 slack[loc] -= demands[e]; 105 assigned = true; 111 } else { 112 // otherwise: fallback 113 child[e] = fallback; 114 slack[child[e]] -= demands[e]; 106 115 } 107 }108 // try 3: insert in a random location (no feasible insert found)109 if (!assigned) {110 child[e] = random.Next(locations);111 slack[child[e]] -= demands[e];112 116 } 113 117 }
Note: See TracChangeset
for help on using the changeset viewer.