Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/03/18 00:28:51 (7 years ago)
Author:
abeham
Message:

#1614:

  • fixed a bug in GRASP where solutions in the elite set would be mutated
  • introduced termination criteria when reaching best-known quality
  • tweaked generating random numbers in StochasticNMoveSingleMoveGenerator
  • changed DiscreteLocationCrossover to use an allele from one of the parents instead of introducing a mutation in case no feasible insert location is found
  • changed OSGA maxselpress to 500
  • slight change to contexts, introduced single-objectiveness much earlier in the class hierachy
    • limited ContextAlgorithm to SingleObjectiveBasicProblems (doesn't matter here)
Location:
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/StochasticNMoveSingleMoveGenerator.cs

    r15553 r15572  
    6565
    6666      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;
    6868
    6969      return new NMove(reassignment, equipments);
     
    7474      if (locations <= 1) throw new ArgumentException("There must be at least two locations.");
    7575      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);
    8078
    8179      var reassignment = new int[dim];
    8280      for (var i = 0; i < 2; i++) {
    8381        var equip = equipments[i];
    84         reassignment[equip] = ReassignEquipment(random, equip, assignment[equip], locations);
     82        reassignment[equip] = 1 + (assignment[equip] + random.Next(1, locations)) % locations;
    8583      }
    8684      return new NMove(reassignment, equipments);
     
    9896      for (var i = 0; i < n; i++) {
    9997        var equip = equipments[i];
    100         reassignment[equip] = ReassignEquipment(random, equip, assignment[equip], locations);
     98        reassignment[equip] = 1 + (assignment[equip] + random.Next(1, locations)) % locations;
    10199      }
    102100      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;
    110101    }
    111102
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/DiscreteLocationCrossover.cs

    r15564 r15572  
    8383      }
    8484
    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
    8688      foreach (var e in order) {
    87         if (takenEquip[e]) continue;
    8889        var assigned = false;
    8990        // 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];
    9396            slack[child[e]] -= demands[e];
    9497            assigned = true;
    9598            break;
     99          } else if (random.NextDouble() < 1.0 / count) {
     100            fallback = p[e];
    96101          }
     102          count++;
    97103        }
    98104        // try 2: find a random feasible location
     
    103109            child[e] = loc;
    104110            slack[loc] -= demands[e];
    105             assigned = true;
     111          } else {
     112            // otherwise: fallback
     113            child[e] = fallback;
     114            slack[child[e]] -= demands[e];
    106115          }
    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];
    112116        }
    113117      }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/GQAPPathRelinking.cs

    r15558 r15572  
    7979      var sFit = problemInstance.ToSingleObjective(sourceEval);
    8080      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
    8284      double pi_star_Fit = problemInstance.ToSingleObjective(pi_star.Evaluation); // line 2 of Algorithm 4
    8385     
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/RelocateEquipmentManipluator.cs

    r15564 r15572  
    5151      foreach (var equipment in equipments) {
    5252        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;
    5654        if (random.NextDouble() < stopProb) break;
    5755      }
Note: See TracChangeset for help on using the changeset viewer.