Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/14/12 15:59:39 (12 years ago)
Author:
abeham
Message:

#1614, #1848

  • updated extension methods and operators that use them
Location:
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Analyzers/BestGQAPSolutionAnalyzer.cs

    r7470 r7807  
    157157      int bestIndex;
    158158      var tmp = qualities.Select((x, index) => new { Index = index, Value = x.Value });
    159       if (maximization) bestIndex = tmp.ChooseMax(x => x.Value).Index;
    160       else bestIndex = tmp.ChooseMin(x => x.Value).Index;
     159      if (maximization) bestIndex = tmp.MaxItems(x => x.Value).First().Index;
     160      else bestIndex = tmp.MinItems(x => x.Value).First().Index;
    161161
    162162      if (bestKnownQuality == null || HasSolutionImproved(bestKnownQuality.Value, qualities[bestIndex].Value, maximization)) {
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/GQAPPathRelinking.cs

    r7523 r7807  
    183183        if (B.Any()) {
    184184          GQAPSolution pi;
    185           if (maximization.Value) pi = B.ChooseProportionalRandom(random, 1, x => x.Quality.Value, false, true).First();
    186           else pi = B.ChooseProportionalRandom(random, 1, x => 1.0 / x.Quality.Value, false, true).First();
     185          if (maximization.Value) pi = B.SampleProportional(random, 1, B.Select(x => x.Quality.Value), false).First();
     186          else pi = B.SampleProportional(random, 1, B.Select(x => 1.0 / x.Quality.Value), false).First();
    187187          var diff = IntegerVectorEqualityComparer.GetDifferingIndices(pi.Assignment, target);
    188188          var I = phi.Except(diff);
    189           var i = I.ChooseUniformRandom(random);
     189          var i = I.SampleRandom(random);
    190190          fix.Add(i);
    191191          nonFix.Remove(i);
     
    226226          var T = nonFix.Where(x => x != equipment && assignment[x] == l && demands[x] <= maxSlack);
    227227          if (T.Any()) {
    228             int i = T.ChooseProportionalRandom(random, 1, x => demands[x], false, true).First();
    229             var j = Enumerable.Range(0, capacities.Length).Where(x => slack[x] >= demands[i]).ChooseUniformRandom(random);
     228            int i = T.SampleProportional(random, 1, T.Select(x => demands[x]), false).First();
     229            var j = Enumerable.Range(0, capacities.Length).Where(x => slack[x] >= demands[i]).SampleRandom(random);
    230230            result[i] = j;
    231231            slack[j] -= demands[i];
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/DemandEquivalentSwapEquipmentManipluator.cs

    r7523 r7807  
    8080          groupedLocations[location2].Remove(equipment2);
    8181          if (!groupedLocations[location2].Any()) break;
    82           equipment2 = groupedLocations[location2].ChooseUniformRandom(random);
     82          equipment2 = groupedLocations[location2].SampleRandom(random);
    8383        }
    8484      }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/RelocateEquipmentManipluator.cs

    r7523 r7807  
    7979      }
    8080
    81       var sourceLocation = overbookedLocations.ChooseUniformRandom(random);
    82       int equipmentToRelocate = groupedLocations[sourceLocation.Key].ChooseUniformRandom(random);
     81      var sourceLocation = overbookedLocations.SampleRandom(random);
     82      int equipmentToRelocate = groupedLocations[sourceLocation.Key].SampleRandom(random);
    8383      var bestFreeLocations = freeLocations.Where(x => capacities[x.Key] > x.Value + demands[equipmentToRelocate]);
    8484
    8585      if (bestFreeLocations.Any()) { // a feasible solution will still be feasible, an infeasible solution might become feasible
    86         var selected = bestFreeLocations.ChooseUniformRandom(random);
     86        var selected = bestFreeLocations.SampleRandom(random);
    8787        assignment[equipmentToRelocate] = sourceLocation.Key;
    8888      } else { // the solution will become infeasible
    89         sourceLocation = freeLocations.ChooseUniformRandom(random);
     89        sourceLocation = freeLocations.SampleRandom(random);
    9090        assignment[equipmentToRelocate] = sourceLocation.Key;
    9191      }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GreedyRandomizedSolutionCreator.cs

    r7593 r7807  
    8484        do {
    8585          if (L.Any() && random.NextDouble() < threshold) {
    86             int l = L.ChooseUniformRandom(random);
     86            int l = L.SampleRandom(random);
    8787            L.Remove(l);
    8888            CL.Add(l);
     
    9090          }
    9191          if (T.Any()) {
    92             int f = T.ChooseUniformRandom(random);
     92            int f = T.SampleRandom(random);
    9393            T.Remove(f);
    9494            F.Remove(f);
    9595            CF.Add(f);
    96             int l = WithSlackGreaterOrEqual(CL, demands[f], slack).ChooseUniformRandom(random);
     96            int l = WithSlackGreaterOrEqual(CL, demands[f], slack).SampleRandom(random);
    9797            assignment.Add(f, l);
    9898            slack[l] -= demands[f];
     
    108108          // complete the solution and remember the one with least violation
    109109          while (F.Any()) {
    110             var f = F.ChooseMax(x => demands[x]);
    111             var l = L.ChooseMax(x => slack[x]);
     110            var f = F.MaxItems(x => demands[x]).SampleRandom(random);
     111            var l = L.MaxItems(x => slack[x]).SampleRandom(random);
    112112            F.Remove(f);
    113113            assignment.Add(f, l);
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs

    r7593 r7807  
    7777        foreach (var equipment in Enumerable.Range(0, demands.Length).Shuffle(random)) {
    7878          var freeLocations = GetFreeLocations(equipment, demands, slack);
    79           assignment[equipment] = freeLocations.ChooseUniformRandom(random);
     79          assignment[equipment] = freeLocations.SampleRandom(random);
    8080          slack[assignment[equipment]] -= demands[equipment];
    8181        }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/SlackMinimizationSolutionCreator.cs

    r7679 r7807  
    111111          // complete the solution
    112112          while (remainingEquipment.Any()) {
    113             var f = remainingEquipment.ChooseMax(x => demands[x]);
    114             var l = Enumerable.Range(0, capacities.Length).ChooseMax(x => slack[x]);
     113            var f = remainingEquipment.MaxItems(x => demands[x]).SampleRandom(random);
     114            var l = Enumerable.Range(0, capacities.Length).MaxItems(x => slack[x]).SampleRandom(random);
    115115            remainingEquipment.Remove(f);
    116116            assignment.Add(f, l);
     
    133133      if (!feasibleEquipment.Any()) yield break;
    134134      if (depth == 0) {
    135         var e = feasibleEquipment.ChooseMax(x => demands[x]);
     135        var e = feasibleEquipment.MaxItems(x => demands[x]).First();
    136136        yield return e;
    137137        yield break;
     
    164164                && slack[assignment[e]] + demands[e] - demands[x] >= 0);
    165165          if (!partners.Any()) continue;
    166           var f = partners.ChooseUniformRandom(random);
     166          var f = partners.SampleRandom(random);
    167167          int h = assignment[e];
    168168          assignment[e] = assignment[f];
Note: See TracChangeset for help on using the changeset viewer.