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;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 |
|
---|
29 | namespace 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 | [StorableConstructor]
|
---|
37 | protected Configuration(bool deserializing) : base(deserializing) { }
|
---|
38 | protected Configuration(Configuration original, Cloner cloner)
|
---|
39 | : base(original, cloner) {
|
---|
40 | if (original.Parameters != null) {
|
---|
41 | Parameters = new Dictionary<string, ParameterConfiguration>();
|
---|
42 | foreach (var kvp in original.Parameters) {
|
---|
43 | Parameters.Add(kvp.Key, cloner.Clone(kvp.Value));
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 | public Configuration() {
|
---|
48 | Parameters = new Dictionary<string, ParameterConfiguration>();
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
52 | return new Configuration(this, cloner);
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | public Configuration AddBinary(string name, int length) {
|
---|
57 | if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
|
---|
58 | Parameters.Add(name, new BinaryParameterConfiguration(length));
|
---|
59 | return this;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public Configuration AddInteger(string name, int length, int min, int max, int? step = null) {
|
---|
63 | if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
|
---|
64 | Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step));
|
---|
65 | return this;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public Configuration AddInteger(string name, int length, IList<int> min, IList<int> max, IList<int> step = null) {
|
---|
69 | if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
|
---|
70 | Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step));
|
---|
71 | return this;
|
---|
72 | }
|
---|
73 |
|
---|
74 | public Configuration AddReal(string name, int length, double min, double max) {
|
---|
75 | if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
|
---|
76 | Parameters.Add(name, new RealParameterConfiguration(length, min, max));
|
---|
77 | return this;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public Configuration AddReal(string name, int length, IList<double> min, IList<double> max) {
|
---|
81 | if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
|
---|
82 | Parameters.Add(name, new RealParameterConfiguration(length, min, max));
|
---|
83 | return this;
|
---|
84 | }
|
---|
85 |
|
---|
86 | public Configuration AddPermutation(string name, int length, PermutationTypes type) {
|
---|
87 | if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
|
---|
88 | Parameters.Add(name, new PermutationParameterConfiguration(length, type));
|
---|
89 | return this;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|