Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10850 was 10850, checked in by abeham, 10 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: 4.0 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.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.Programmable {
30  [Item("Configuration", "")]
31  [StorableClass]
32  public class Configuration : Item {
33    [Storable]
34    public Dictionary<string, ParameterConfiguration> Parameters { get; protected set; }
35
36    [Storable]
37    public bool Maximization { get; protected set; }
38
39    [StorableConstructor]
40    protected Configuration(bool deserializing) : base(deserializing) { }
41    protected Configuration(Configuration original, Cloner cloner)
42      : base(original, cloner) {
43      if (original.Parameters != null) {
44        Parameters = new Dictionary<string, ParameterConfiguration>();
45        foreach (var kvp in original.Parameters) {
46          Parameters.Add(kvp.Key, cloner.Clone(kvp.Value));
47        }
48      }
49      Maximization = original.Maximization;
50    }
51    public Configuration() {
52      Parameters = new Dictionary<string, ParameterConfiguration>();
53    }
54
55    public override IDeepCloneable Clone(Cloner cloner) {
56      return new Configuration(this, cloner);
57    }
58
59
60    public Configuration AddBoolean(string name, int length) {
61      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
62      Parameters.Add(name, new BinaryParameterConfiguration(length));
63      return this;
64    }
65
66    public Configuration AddInteger(string name, int length, int min, int max, int? step = null) {
67      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
68      Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step));
69      return this;
70    }
71
72    public Configuration AddInteger(string name, int length, IList<int> min, IList<int> max, IList<int> step = null) {
73      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
74      Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step));
75      return this;
76    }
77
78    public Configuration AddReal(string name, int length, double min, double max) {
79      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
80      Parameters.Add(name, new RealParameterConfiguration(length, min, max));
81      return this;
82    }
83
84    public Configuration AddReal(string name, int length, IList<double> min, IList<double> max) {
85      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
86      Parameters.Add(name, new RealParameterConfiguration(length, min, max));
87      return this;
88    }
89
90    public Configuration AddPermutation(string name, PermutationTypes type, int length) {
91      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
92      Parameters.Add(name, new PermutationParameterConfiguration(length, type));
93      return this;
94    }
95
96    public Configuration SetMaximization(bool maximization) {
97      Maximization = maximization;
98      return this;
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.