Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SimSharp/HeuristicLab.Encodings.ParameterVector/ParameterVectorBuilder.cs @ 10754

Last change on this file since 10754 was 10754, checked in by abeham, 10 years ago

#2174: minor refactorings

File size: 2.7 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;
23using System.Collections.Generic;
24using HeuristicLab.Encodings.PermutationEncoding;
25
26namespace HeuristicLab.Encodings.ParameterVectorEncoding {
27  public class ParameterVectorBuilder {
28    private HashSet<string> booleanParameters;
29    private Dictionary<string, Tuple<int, int, int?>> integerParameters;
30    private Dictionary<string, Tuple<double, double>> realParameters;
31    private Tuple<PermutationTypes, int> permutationParameter;
32
33    public ParameterVectorBuilder() {
34      booleanParameters = null;
35      integerParameters = null;
36      realParameters = null;
37      permutationParameter = null;
38    }
39
40    public ParameterVectorBuilder AddBoolean(string name) {
41      if (booleanParameters == null) booleanParameters = new HashSet<string>();
42      booleanParameters.Add(name);
43      return this;
44    }
45
46    public ParameterVectorBuilder AddInteger(string name, int min, int max, int? step = null) {
47      if (integerParameters == null) integerParameters = new Dictionary<string, Tuple<int, int, int?>>();
48      integerParameters.Add(name, Tuple.Create(min, max, step));
49      return this;
50    }
51
52    public ParameterVectorBuilder AddReal(string name, double min, double max) {
53      if (realParameters == null) realParameters = new Dictionary<string, Tuple<double, double>>();
54      realParameters.Add(name, Tuple.Create(min, max));
55      return this;
56    }
57
58    public ParameterVectorBuilder SetPermutation(PermutationTypes type, int length) {
59      permutationParameter = Tuple.Create(type, length);
60      return this;
61    }
62
63    public ParameterVector Build() {
64      var vector = new ParameterVector();
65      vector.SetBooleanParameters(booleanParameters);
66      vector.SetIntegerParameters(integerParameters);
67      vector.SetRealParameters(realParameters);
68      vector.SetPermutationParameters(permutationParameter);
69      return vector;
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.