Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive.cs @ 15762

Last change on this file since 15762 was 14690, checked in by abeham, 8 years ago

#2457: working on identification of problem instances

File size: 2.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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;
23using System.Collections.Generic;
24using System.Threading;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.PermutationEncoding;
27
28namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch {
29  public static class Exhaustive {
30#if DEBUG
31    private const bool VALIDATE = true;
32#else
33  private const bool VALIDATE = false;
34#endif
35
36    public static IEnumerable<Tuple<Encodings.PermutationEncoding.Permutation, double, int>> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm,
37      double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval,
38      CancellationToken token, bool[,] subspace = null) {
39      if (double.IsNaN(quality)) quality = eval(perm, token);
40      IEnumerable<Tuple<Encodings.PermutationEncoding.Permutation, double, int>> localSearchPath;
41      switch (perm.PermutationType) {
42        case PermutationTypes.Absolute:
43          localSearchPath = ExhaustiveSwap2.HillClimb(random, perm, quality, maximization, eval, token, subspace);
44          break;
45        case PermutationTypes.RelativeDirected:
46          localSearchPath = Exhaustive1Shift.HillClimb(random, perm, quality, maximization, eval, token, subspace);
47          break;
48        case PermutationTypes.RelativeUndirected:
49          localSearchPath = Exhaustive2Opt.HillClimb(random, perm, quality, maximization, eval, token, subspace);
50          break;
51        default: throw new ArgumentException(string.Format("Permutation type {0} is not known", perm.PermutationType));
52      }
53      if (VALIDATE && !perm.Validate()) throw new ArgumentException("HillClimb produced invalid child");
54      return localSearchPath;
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.