source: branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/ParameterVector.cs @ 10850

Last change on this file since 10850 was 10850, checked in by abeham, 6 years ago

#2174: Major refactoring:

  • ParameterVector is only a temporary datastructure that is constructed for evaluation purposes only
  • Multiple permutations are allowed
  • Special support for single-vector encodings (to apply specialized algorithms such as PSO or CMA-ES)
  • General support for multi-vector encoding
File size: 3.3 KB
Line 
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
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Encodings.BinaryVectorEncoding;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Encodings.RealVectorEncoding;
28
29namespace HeuristicLab.Problems.Programmable {
30  public class ParameterVector {
31    protected Dictionary<string, BinaryVector> BinaryParameters;
32    protected Dictionary<string, IntegerVector> IntegerParameters;
33    protected Dictionary<string, RealVector> RealParameters;
34    protected Dictionary<string, Permutation> PermutationParameters;
35
36    public ParameterVector(IEnumerable<KeyValuePair<string, BinaryVector>> binaryVectors = null,
37      IEnumerable<KeyValuePair<string, IntegerVector>> integerVectors = null,
38      IEnumerable<KeyValuePair<string, RealVector>> realVectors = null,
39      IEnumerable<KeyValuePair<string, Permutation>> permutations = null) {
40      if (binaryVectors != null) BinaryParameters = binaryVectors.ToDictionary(x => x.Key, x => x.Value);
41      if (integerVectors != null) IntegerParameters = integerVectors.ToDictionary(x => x.Key, x => x.Value);
42      if (realVectors != null) RealParameters = realVectors.ToDictionary(x => x.Key, x => x.Value);
43      if (permutations != null) PermutationParameters = permutations.ToDictionary(x => x.Key, x => x.Value);
44    }
45
46    public BinaryVector Binary(string name) {
47      return BinaryParameters[name];
48    }
49
50    public bool Binary(string name, int index) {
51      return BinaryParameters[name][index];
52    }
53
54    public IEnumerable<string> BinaryNames {
55      get { return BinaryParameters.Keys; }
56    }
57
58    public IntegerVector Integer(string name) {
59      return IntegerParameters[name];
60    }
61
62    public int Integer(string name, int index) {
63      return IntegerParameters[name][index];
64    }
65
66    public IEnumerable<string> IntegerNames {
67      get { return IntegerParameters.Keys; }
68    }
69
70    public RealVector Real(string name) {
71      return RealParameters[name];
72    }
73
74    public double Real(string name, int index) {
75      return RealParameters[name][index];
76    }
77
78    public IEnumerable<string> RealNames {
79      get { return RealParameters.Keys; }
80    }
81
82    public Permutation Permutation(string name) {
83      return PermutationParameters[name];
84    }
85
86    public IEnumerable<string> PermutationNames {
87      get { return PermutationParameters.Keys; }
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.