#region License Information
/* HeuristicLab
* Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Encodings.PermutationEncoding;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Problems.Programmable {
[Item("MultiEncoding", "Describes a combined encoding consisting of multiple simpler encodings.")]
[StorableClass]
public class MultiEncoding : Encoding {
[Storable]
public KeyedItemCollection Encodings { get; protected set; }
[StorableConstructor]
protected MultiEncoding(bool deserializing) : base(deserializing) { }
protected MultiEncoding(MultiEncoding original, Cloner cloner)
: base(original, cloner) {
Encodings = cloner.Clone(original.Encodings);
}
public MultiEncoding()
: base("MultiEncoding") {
Encodings = new NamedItemCollection();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new MultiEncoding(this, cloner);
}
public MultiEncoding AddBinaryVector(string variableName, int length) {
if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
Encodings.Add(new BinaryEncoding(variableName, length));
return this;
}
public MultiEncoding AddIntegerVector(string variableName, int length, int min, int max, int? step = null) {
if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
Encodings.Add(new IntegerEncoding(variableName, length, min, max, step));
return this;
}
public MultiEncoding AddIntegerVector(string variableName, int length, IList min, IList max, IList step = null) {
if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
Encodings.Add(new IntegerEncoding(variableName, length, min, max, step));
return this;
}
public MultiEncoding AddRealVector(string variableName, int length, double min, double max) {
if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
Encodings.Add(new RealEncoding(variableName, length, min, max));
return this;
}
public MultiEncoding AddRealVector(string variableName, int length, IList min, IList max) {
if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
Encodings.Add(new RealEncoding(variableName, length, min, max));
return this;
}
public MultiEncoding AddPermutation(string variableName, int length, PermutationTypes type) {
if (Encodings.ContainsKey(variableName)) throw new ArgumentException("variableName must be unique", "variableName");
Encodings.Add(new PermutationEncoding(variableName, length, type));
return this;
}
}
}