#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("Configuration", "")] [StorableClass] public class Configuration : Item { [Storable] public Dictionary Parameters { get; protected set; } [StorableConstructor] protected Configuration(bool deserializing) : base(deserializing) { } protected Configuration(Configuration original, Cloner cloner) : base(original, cloner) { if (original.Parameters != null) { Parameters = new Dictionary(); foreach (var kvp in original.Parameters) { Parameters.Add(kvp.Key, cloner.Clone(kvp.Value)); } } } public Configuration() { Parameters = new Dictionary(); } public override IDeepCloneable Clone(Cloner cloner) { return new Configuration(this, cloner); } public Configuration AddBinary(string name, int length) { if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); Parameters.Add(name, new BinaryParameterConfiguration(length)); return this; } public Configuration AddInteger(string name, int length, int min, int max, int? step = null) { if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step)); return this; } public Configuration AddInteger(string name, int length, IList min, IList max, IList step = null) { if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step)); return this; } public Configuration AddReal(string name, int length, double min, double max) { if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); Parameters.Add(name, new RealParameterConfiguration(length, min, max)); return this; } public Configuration AddReal(string name, int length, IList min, IList max) { if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); Parameters.Add(name, new RealParameterConfiguration(length, min, max)); return this; } public Configuration AddPermutation(string name, int length, PermutationTypes type) { if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); Parameters.Add(name, new PermutationParameterConfiguration(length, type)); return this; } } }