Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2174: The problem is now not Sim# specific anymore, but the parameters of Sim# models could be optimized using this problem. It's all about being able to program the evaluation function and parameter vector.

File size: 2.5 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 = new HashSet<string>();
35      integerParameters = new Dictionary<string, Tuple<int, int, int?>>();
36      realParameters = new Dictionary<string, Tuple<double, double>>();
37      permutationParameter = null;
38    }
39
40    public ParameterVectorBuilder AddBoolean(string name) {
41      booleanParameters.Add(name);
42      return this;
43    }
44
45    public ParameterVectorBuilder AddInteger(string name, int min, int max, int? step = null) {
46      integerParameters.Add(name, Tuple.Create(min, max, step));
47      return this;
48    }
49
50    public ParameterVectorBuilder AddReal(string name, double min, double max) {
51      realParameters.Add(name, Tuple.Create(min, max));
52      return this;
53    }
54
55    public ParameterVectorBuilder SetPermutation(PermutationTypes type, int length) {
56      permutationParameter = Tuple.Create(type, length);
57      return this;
58    }
59
60    public ParameterVector Build() {
61      var vector = new ParameterVector();
62      vector.SetBooleanParameters(booleanParameters);
63      vector.SetIntegerParameters(integerParameters);
64      vector.SetRealParameters(realParameters);
65      vector.SetPermutationParameters(permutationParameter);
66      return vector;
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.