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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Threading;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
27 |
|
---|
28 | namespace 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 | }
|
---|