Changeset 15572 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators
- Timestamp:
- 01/03/18 00:28:51 (7 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators
- Files:
-
- 3 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 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/GQAPPathRelinking.cs
r15558 r15572 79 79 var sFit = problemInstance.ToSingleObjective(sourceEval); 80 80 var tFit = problemInstance.ToSingleObjective(targetEval); 81 GQAPSolution pi_star = sFit < tFit ? new GQAPSolution(source, sourceEval) : new GQAPSolution(target, targetEval); // line 1 of Algorithm 4 81 GQAPSolution pi_star = sFit < tFit 82 ? new GQAPSolution((IntegerVector)source.Clone(), (Evaluation)sourceEval.Clone()) 83 : new GQAPSolution((IntegerVector)target.Clone(), (Evaluation)targetEval.Clone()); // line 1 of Algorithm 4 82 84 double pi_star_Fit = problemInstance.ToSingleObjective(pi_star.Evaluation); // line 2 of Algorithm 4 83 85 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/RelocateEquipmentManipluator.cs
r15564 r15572 51 51 foreach (var equipment in equipments) { 52 52 var oldLoc = assignment[equipment]; 53 var newLoc =random.Next(locations - 1); 54 if (newLoc >= oldLoc) newLoc++; // don't reassign to current loc 55 assignment[equipment] = newLoc; 53 assignment[equipment] = (oldLoc + random.Next(1, locations)) % locations; 56 54 if (random.NextDouble() < stopProb) break; 57 55 }
Note: See TracChangeset
for help on using the changeset viewer.