Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/MultiEncoding.cs @ 11571

Last change on this file since 11571 was 11559, checked in by mkommend, 10 years ago

#2174: Adapted IEncoding and Encoding base class.

File size: 3.8 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("MultiEncoding", "Describes a combined encoding consisting of multiple simpler encodings.")]
31  [StorableClass]
32  public class MultiEncoding : Encoding<MultiEncodingCreator> {
33    [Storable]
34    public KeyedItemCollection<string, IEncoding> Encodings { get; protected set; }
35
36    [StorableConstructor]
37    protected MultiEncoding(bool deserializing) : base(deserializing) { }
38    protected MultiEncoding(MultiEncoding original, Cloner cloner)
39      : base(original, cloner) {
40      Encodings = cloner.Clone(original.Encodings);
41    }
42    public MultiEncoding()
43      : base("MultiEncoding") {
44      Encodings = new NamedItemCollection<IEncoding>();
45    }
46
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new MultiEncoding(this, cloner);
49    }
50
51    public MultiEncoding AddBinaryVector(string variableName, int length) {
52      if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
53      Encodings.Add(new BinaryEncoding(variableName, length));
54      return this;
55    }
56
57    public MultiEncoding AddIntegerVector(string variableName, int length, int min, int max, int? step = null) {
58      if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
59      Encodings.Add(new IntegerEncoding(variableName, length, min, max, step));
60      return this;
61    }
62
63    public MultiEncoding AddIntegerVector(string variableName, int length, IList<int> min, IList<int> max, IList<int> step = null) {
64      if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
65      Encodings.Add(new IntegerEncoding(variableName, length, min, max, step));
66      return this;
67    }
68
69    public MultiEncoding AddRealVector(string variableName, int length, double min, double max) {
70      if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
71      Encodings.Add(new RealEncoding(variableName, length, min, max));
72      return this;
73    }
74
75    public MultiEncoding AddRealVector(string variableName, int length, IList<double> min, IList<double> max) {
76      if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
77      Encodings.Add(new RealEncoding(variableName, length, min, max));
78      return this;
79    }
80
81    public MultiEncoding AddPermutation(string variableName, int length, PermutationTypes type) {
82      if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
83      Encodings.Add(new PermutationEncoding(variableName, length, type));
84      return this;
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.