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 HeuristicLab.Algorithms.MemPR.Interfaces;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Algorithms.MemPR.Permutation.SolutionModel.Univariate {
|
---|
29 | public enum ModelBiasOptions { Rank, Fitness }
|
---|
30 |
|
---|
31 | public static class Trainer {
|
---|
32 | public static ISolutionModel<Encodings.PermutationEncoding.Permutation> TrainUnbiased(IRandom random, IList<Encodings.PermutationEncoding.Permutation> pop, int N) {
|
---|
33 | ISolutionModel<Encodings.PermutationEncoding.Permutation> model;
|
---|
34 | switch (pop[0].PermutationType) {
|
---|
35 | case PermutationTypes.Absolute:
|
---|
36 | model = UnivariateAbsoluteModel.CreateUnbiased(random, pop, N);
|
---|
37 | break;
|
---|
38 | case PermutationTypes.RelativeDirected:
|
---|
39 | model = UnivariateRelativeModel.CreateDirected(random, pop, N);
|
---|
40 | break;
|
---|
41 | case PermutationTypes.RelativeUndirected:
|
---|
42 | model = UnivariateRelativeModel.CreateUndirected(random, pop, N);
|
---|
43 | break;
|
---|
44 | default: throw new ArgumentException(string.Format("unknown permutation type {0}", pop[0].PermutationType));
|
---|
45 | }
|
---|
46 | return model;
|
---|
47 | }
|
---|
48 |
|
---|
49 | public static ISolutionModel<Encodings.PermutationEncoding.Permutation> TrainBiased(ModelBiasOptions modelBias, IRandom random, bool maximization, IList<Encodings.PermutationEncoding.Permutation> pop, IList<double> qualities, int N) {
|
---|
50 | if (pop.Count != qualities.Count) throw new ArgumentException("Unequal length of population and qualities list.");
|
---|
51 | ISolutionModel<Encodings.PermutationEncoding.Permutation> model;
|
---|
52 | switch (pop[0].PermutationType) {
|
---|
53 | case PermutationTypes.Absolute:
|
---|
54 | if (modelBias == ModelBiasOptions.Rank)
|
---|
55 | model = UnivariateAbsoluteModel.CreateWithRankBias(random, maximization, pop, qualities, N);
|
---|
56 | else if (modelBias == ModelBiasOptions.Fitness)
|
---|
57 | model = UnivariateAbsoluteModel.CreateWithFitnessBias(random, maximization, pop, qualities, N);
|
---|
58 | else throw new ArgumentException(string.Format("Bias type {0} is not supported.", modelBias));
|
---|
59 | break;
|
---|
60 | case PermutationTypes.RelativeDirected:
|
---|
61 | if (modelBias == ModelBiasOptions.Rank)
|
---|
62 | model = UnivariateRelativeModel.CreateDirectedWithRankBias(random, maximization, pop, qualities, N);
|
---|
63 | else if (modelBias == ModelBiasOptions.Fitness)
|
---|
64 | model = UnivariateRelativeModel.CreateDirectedWithFitnessBias(random, maximization, pop, qualities, N);
|
---|
65 | else throw new ArgumentException(string.Format("Bias type {0} is not supported.", modelBias));
|
---|
66 | break;
|
---|
67 | case PermutationTypes.RelativeUndirected:
|
---|
68 | if (modelBias == ModelBiasOptions.Rank)
|
---|
69 | model = UnivariateRelativeModel.CreateUndirectedWithRankBias(random, maximization, pop, qualities, N);
|
---|
70 | else if (modelBias == ModelBiasOptions.Fitness)
|
---|
71 | model = UnivariateRelativeModel.CreateUndirectedWithFitnessBias(random, maximization, pop, qualities, N);
|
---|
72 | else throw new ArgumentException(string.Format("Bias type {0} is not supported.", modelBias));
|
---|
73 | break;
|
---|
74 | default: throw new ArgumentException(string.Format("unknown permutation type {0}", pop[0].PermutationType));
|
---|
75 | }
|
---|
76 | return model;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|