Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15704 for branches


Ignore:
Timestamp:
02/01/18 10:25:57 (7 years ago)
Author:
abeham
Message:

#1614:

  • fixed exception in case no solution could be found
  • fixed behavior in GRASP regarding infeasible solutions
Location:
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/GRASP/GRASP.cs

    r15700 r15704  
    170170        IntegerVector pi_prime_vec = null;
    171171        try {
    172           pi_prime_vec = GreedyRandomizedSolutionCreator.CreateSolution(Context.Random, Problem.ProblemInstance, 1000, false, cancellationToken);
     172          pi_prime_vec = GreedyRandomizedSolutionCreator.CreateSolution(Context.Random, Problem.ProblemInstance, 10, true, cancellationToken);
    173173        } catch (OperationCanceledException) { break; }
    174174
     
    204204                                          .OrderByDescending(x => similarities[x.Index]) // line 14 in Algorithm 1
    205205                                          .FirstOrDefault();
    206               if (replacement != null) { 
     206              if (replacement != null) {
    207207                Context.ReplaceAtPopulation(replacement.Index, Context.ToScope(pi_prime, fitness)); // line 14 in Algorithm 1
    208208              }
     
    223223            Context.BestQuality = fitness;
    224224            Context.BestSolution = (GQAPSolution)pi_prime.Clone();
     225          }
     226        } else if (Context.PopulationCount == 0) {
     227          // Book-keeping
     228          // pi_prime_vec is not feasible, but no other feasible solution has been found so far
     229          var eval = Problem.ProblemInstance.Evaluate(pi_prime_vec);
     230          Context.EvaluatedSolutions++;
     231          var fit = Problem.ProblemInstance.ToSingleObjective(eval);
     232          if (double.IsNaN(Context.BestQuality) || fit < Context.BestQuality) {
     233            Context.BestQuality = fit;
     234            Context.BestSolution = new GQAPSolution(pi_prime_vec, eval);
    225235          }
    226236        }
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Algorithms/ContextAlgorithm.cs

    r15703 r15704  
    193193      elapsed += stopwatch.Elapsed;
    194194      stopwatch.Reset();
    195       firstHitGraph.Values[firstHitGraph.Values.Count - 1] = Tuple.Create(elapsed.TotalSeconds, Context.BestQuality);
     195      if (firstHitGraph.Values.Count > 0)
     196        firstHitGraph.Values[firstHitGraph.Values.Count - 1] = Tuple.Create(elapsed.TotalSeconds, Context.BestQuality);
    196197      base.OnPaused();
    197198    }
     
    201202        elapsed += stopwatch.Elapsed;
    202203        stopwatch.Reset();
    203         firstHitGraph.Values[firstHitGraph.Values.Count - 1] = Tuple.Create(elapsed.TotalSeconds, Context.BestQuality);
     204        if (firstHitGraph.Values.Count > 0)
     205          firstHitGraph.Values[firstHitGraph.Values.Count - 1] = Tuple.Create(elapsed.TotalSeconds, Context.BestQuality);
    204206      }
    205207      // base call must be done last as the results will be cloned and a run is created
Note: See TracChangeset for help on using the changeset viewer.