Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/GRASP/GRASPContext.cs @ 15677

Last change on this file since 15677 was 15572, checked in by abeham, 7 years ago

#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)
File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.GRASP {
29  [Item("GRASP+PR (GQAP) Context", "Context for GRASP+PR (GQAP).")]
30  [StorableClass]
31  public sealed class GRASPContext : PopulationContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
32   
33    [Storable]
34    private IValueParameter<GQAP> problem;
35    public GQAP Problem {
36      get { return problem.Value; }
37      set { problem.Value = value; }
38    }
39
40    [Storable]
41    private IValueParameter<GQAPSolution> bestSolution;
42    public GQAPSolution BestSolution {
43      get { return bestSolution.Value; }
44      set { bestSolution.Value = value; }
45    }
46   
47    public void SortPopulation() {
48      Scope.SubScopes.Replace(Scope.SubScopes.OfType<ISingleObjectiveSolutionScope<GQAPSolution>>().OrderBy(x => Problem.Maximization ? -x.Fitness : x.Fitness).ToList());
49    }
50   
51    [StorableConstructor]
52    private GRASPContext(bool deserializing) : base(deserializing) { }
53    private GRASPContext(GRASPContext original, Cloner cloner)
54      : base(original, cloner) {
55      problem = cloner.Clone(original.problem);
56      bestSolution = cloner.Clone(original.bestSolution);
57    }
58    public GRASPContext() : this("GRASP+PR (GQAP) Context") { }
59    public GRASPContext(string name) : base(name) {
60      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
61      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new GRASPContext(this, cloner);
66    }
67
68    public ISingleObjectiveSolutionScope<GQAPSolution> ToScope(GQAPSolution code, double fitness = double.NaN) {
69      var name = Problem.Encoding.Name;
70      var scope = new SingleObjectiveSolutionScope<GQAPSolution>(code,
71        name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
72        Parent = Scope
73      };
74      scope.Variables.Add(new Variable(name, code.Assignment));
75      scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
76      return scope;
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.