Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/30/17 23:10:29 (7 years ago)
Author:
abeham
Message:

#1614:

  • Added LAHC and pLAHC-s
  • Changed all algorithms to update high frequency results only every second
Location:
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Evolutionary
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Evolutionary/ESContext.cs

    r15562 r15563  
    4545    }
    4646
     47    [Storable]
     48    private IValueParameter<IRandom> normalRand;
     49    public IRandom NormalRand {
     50      get { return normalRand.Value; }
     51      set { normalRand.Value = value; }
     52    }
     53
    4754    public void ReplacePopulation(IEnumerable<ISingleObjectiveSolutionScope<ESGQAPSolution>> replacement) {
    4855      Scope.SubScopes.Replace(replacement);
     
    5562      problem = cloner.Clone(original.problem);
    5663      bestSolution = cloner.Clone(original.bestSolution);
     64      normalRand = cloner.Clone(original.normalRand);
    5765    }
    5866    public ESContext() : this("Evolution Strategy (GQAP) Context") { }
     
    6068      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
    6169      Parameters.Add(bestSolution = new ValueParameter<ESGQAPSolution>("BestFoundSolution"));
     70      Parameters.Add(normalRand = new ValueParameter<IRandom>("NormalRand"));
    6271    }
    6372
     
    7483      scope.Variables.Add(new Variable(name, code.Assignment));
    7584      scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
     85      scope.Variables.Add(new Variable("StrategyParameter", code.sParam));
    7686      return scope;
    7787    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Evolutionary/ESGQAPSolution.cs

    r15562 r15563  
    2121
    2222using HeuristicLab.Common;
     23using HeuristicLab.Data;
    2324using HeuristicLab.Encodings.IntegerVectorEncoding;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2829
    2930    [Storable]
    30     private double sParam;
     31    internal DoubleValue sParam;
    3132    public double SParam {
    32       get { return sParam; }
     33      get { return sParam.Value; }
    3334      set {
    34         if (sParam == value) return;
    35         sParam = value;
     35        if (sParam.Value == value) return;
     36        sParam.Value = value;
    3637        OnPropertyChanged(nameof(SParam));
    3738      }
     
    4243    protected ESGQAPSolution(ESGQAPSolution original, Cloner cloner)
    4344    : base(original, cloner) {
    44       sParam = original.sParam;
     45      sParam = cloner.Clone(original.sParam);
    4546    }
    4647    public ESGQAPSolution(IntegerVector assignment, Evaluation eval, double sParam)
    4748      : base(assignment, eval) {
    48       this.sParam = sParam;
     49      this.sParam = new DoubleValue(sParam);
    4950    }
    5051   
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Evolutionary/EvolutionStrategy.cs

    r15562 r15563  
    106106      base.Initialize(cancellationToken);
    107107
     108      Context.NormalRand = new NormalDistributedRandom(Context.Random, 0, 1);
    108109      Context.Problem = Problem;     
    109110      Context.BestQuality = double.NaN;
    110111      Context.BestSolution = null;
    111 
     112     
    112113      for (var m = 0; m < Mu; m++) {
    113114        var assign = new IntegerVector(Problem.ProblemInstance.Demands.Length, Context.Random, 0, Problem.ProblemInstance.Capacities.Length);
     
    115116        Context.EvaluatedSolutions++;
    116117
    117         var ind = new ESGQAPSolution(assign, eval, 1.0 / assign.Length);
     118        var ind = new ESGQAPSolution(assign, eval, Context.Random.NextDouble() * 2 - 1);
    118119        var fit = Problem.ProblemInstance.ToSingleObjective(eval);
    119120        Context.AddToPopulation(Context.ToScope(ind, fit));
     
    133134
    134135    protected override void Run(CancellationToken cancellationToken) {
     136      var lastUpdate = ExecutionTime;
     137
    135138      while (!StoppingCriterion()) {
    136139        var nextGen = new List<ISingleObjectiveSolutionScope<ESGQAPSolution>>(Lambda);
     
    141144          var offspring = (ESGQAPSolution)m.Solution.Clone();
    142145          var count = Mutate(m, offspring);
    143           offspring.SParam += ((1.0 / count) - offspring.SParam) / 10.0;
     146          offspring.SParam += 0.7071 * Context.NormalRand.NextDouble(); //((1.0 / count) - offspring.SParam) / 10.0;
    144147
    145148          offspring.Evaluation = Problem.ProblemInstance.Evaluate(offspring.Assignment);
     
    162165
    163166        IResult result;
    164         if (Results.TryGetValue("Iterations", out result))
    165           ((IntValue)result.Value).Value = Context.Iterations;
    166         else Results.Add(new Result("Iterations", new IntValue(Context.Iterations)));
    167         if (Results.TryGetValue("EvaluatedSolutions", out result))
    168           ((IntValue)result.Value).Value = Context.EvaluatedSolutions;
    169         else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions)));
     167        if (ExecutionTime - lastUpdate > TimeSpan.FromSeconds(1)) {
     168          if (Results.TryGetValue("Iterations", out result))
     169            ((IntValue)result.Value).Value = Context.Iterations;
     170          else Results.Add(new Result("Iterations", new IntValue(Context.Iterations)));
     171          if (Results.TryGetValue("EvaluatedSolutions", out result))
     172            ((IntValue)result.Value).Value = Context.EvaluatedSolutions;
     173          else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions)));
     174          lastUpdate = ExecutionTime;
     175        }
    170176        if (Results.TryGetValue("BestQuality", out result))
    171177          ((DoubleValue)result.Value).Value = Context.BestQuality;
     
    180186        if (cancellationToken.IsCancellationRequested) break;
    181187      }
     188      IResult result2;
     189      if (Results.TryGetValue("Iterations", out result2))
     190        ((IntValue)result2.Value).Value = Context.Iterations;
     191      else Results.Add(new Result("Iterations", new IntValue(Context.Iterations)));
     192      if (Results.TryGetValue("EvaluatedSolutions", out result2))
     193        ((IntValue)result2.Value).Value = Context.EvaluatedSolutions;
     194      else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions)));
    182195    }
    183196
    184197    private int Mutate(ISingleObjectiveSolutionScope<ESGQAPSolution> m, ESGQAPSolution offspring) {
     198      var stopProb = (Math.Tanh(m.Solution.SParam) + 1) / 2.0; // squash strategy parameter to ]0;1[
    185199      var offspringFeasible = offspring.Evaluation.IsFeasible;
    186200      double[] slack = null;
     
    210224          offspring.Assignment[equip] = newLoc;
    211225        }
    212         if (Context.Random.NextDouble() < m.Solution.SParam) break;
     226        if (Context.Random.NextDouble() < stopProb) break;
    213227        count++;
    214228      }
Note: See TracChangeset for help on using the changeset viewer.