1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Encodings.BinaryVectorEncoding;
|
---|
26 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
27 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
28 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.Programmable {
|
---|
31 | public sealed class ParameterVector : IDeepCloneable {
|
---|
32 | private Dictionary<string, BinaryVector> BinaryParameters;
|
---|
33 | private Dictionary<string, IntegerVector> IntegerParameters;
|
---|
34 | private Dictionary<string, RealVector> RealParameters;
|
---|
35 | private Dictionary<string, Permutation> PermutationParameters;
|
---|
36 |
|
---|
37 | public ParameterVector(IEnumerable<KeyValuePair<string, BinaryVector>> binaryVectors = null,
|
---|
38 | IEnumerable<KeyValuePair<string, IntegerVector>> integerVectors = null,
|
---|
39 | IEnumerable<KeyValuePair<string, RealVector>> realVectors = null,
|
---|
40 | IEnumerable<KeyValuePair<string, Permutation>> permutations = null) {
|
---|
41 | if (binaryVectors != null) BinaryParameters = binaryVectors.ToDictionary(x => x.Key, x => x.Value);
|
---|
42 | if (integerVectors != null) IntegerParameters = integerVectors.ToDictionary(x => x.Key, x => x.Value);
|
---|
43 | if (realVectors != null) RealParameters = realVectors.ToDictionary(x => x.Key, x => x.Value);
|
---|
44 | if (permutations != null) PermutationParameters = permutations.ToDictionary(x => x.Key, x => x.Value);
|
---|
45 | }
|
---|
46 | private ParameterVector(ParameterVector original, Cloner cloner) {
|
---|
47 | cloner.RegisterClonedObject(original, this);
|
---|
48 | if (original.BinaryParameters != null) {
|
---|
49 | BinaryParameters = new Dictionary<string, BinaryVector>(original.BinaryParameters.Comparer);
|
---|
50 | foreach (var param in original.BinaryParameters)
|
---|
51 | BinaryParameters[param.Key] = cloner.Clone(param.Value);
|
---|
52 | }
|
---|
53 | if (original.IntegerParameters != null) {
|
---|
54 | IntegerParameters = new Dictionary<string, IntegerVector>(original.IntegerParameters.Comparer);
|
---|
55 | foreach (var param in original.IntegerParameters)
|
---|
56 | IntegerParameters[param.Key] = cloner.Clone(param.Value);
|
---|
57 | }
|
---|
58 | if (original.RealParameters != null) {
|
---|
59 | RealParameters = new Dictionary<string, RealVector>(original.RealParameters.Comparer);
|
---|
60 | foreach (var param in original.RealParameters)
|
---|
61 | RealParameters[param.Key] = cloner.Clone(param.Value);
|
---|
62 | }
|
---|
63 | if (original.PermutationParameters != null) {
|
---|
64 | PermutationParameters = new Dictionary<string, Permutation>(original.PermutationParameters.Comparer);
|
---|
65 | foreach (var param in original.PermutationParameters)
|
---|
66 | PermutationParameters[param.Key] = cloner.Clone(param.Value);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public object Clone() {
|
---|
71 | return Clone(new Cloner());
|
---|
72 | }
|
---|
73 |
|
---|
74 | public IDeepCloneable Clone(Cloner cloner) {
|
---|
75 | return new ParameterVector(this, cloner);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public BinaryVector BinaryVector(string name) {
|
---|
79 | return BinaryParameters[name];
|
---|
80 | }
|
---|
81 |
|
---|
82 | public bool BinaryValue(string name, int index) {
|
---|
83 | return BinaryParameters[name][index];
|
---|
84 | }
|
---|
85 |
|
---|
86 | public IEnumerable<string> BinaryNames {
|
---|
87 | get { return BinaryParameters != null ? BinaryParameters.Keys : Enumerable.Empty<string>(); }
|
---|
88 | }
|
---|
89 |
|
---|
90 | public IntegerVector IntegerVector(string name) {
|
---|
91 | return IntegerParameters[name];
|
---|
92 | }
|
---|
93 |
|
---|
94 | public int IntegerValue(string name, int index) {
|
---|
95 | return IntegerParameters[name][index];
|
---|
96 | }
|
---|
97 |
|
---|
98 | public IEnumerable<string> IntegerNames {
|
---|
99 | get { return IntegerParameters != null ? IntegerParameters.Keys : Enumerable.Empty<string>(); }
|
---|
100 | }
|
---|
101 |
|
---|
102 | public RealVector RealVector(string name) {
|
---|
103 | return RealParameters[name];
|
---|
104 | }
|
---|
105 |
|
---|
106 | public double RealValue(string name, int index) {
|
---|
107 | return RealParameters[name][index];
|
---|
108 | }
|
---|
109 |
|
---|
110 | public IEnumerable<string> RealNames {
|
---|
111 | get { return RealParameters != null ? RealParameters.Keys : Enumerable.Empty<string>(); }
|
---|
112 | }
|
---|
113 |
|
---|
114 | public Permutation Permutation(string name) {
|
---|
115 | return PermutationParameters[name];
|
---|
116 | }
|
---|
117 |
|
---|
118 | public IEnumerable<string> PermutationNames {
|
---|
119 | get { return PermutationParameters != null ? PermutationParameters.Keys : Enumerable.Empty<string>(); }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|