#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.Core; using HeuristicLab.Encodings.BinaryVectorEncoding; using HeuristicLab.Encodings.IntegerVectorEncoding; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.Encodings.RealVectorEncoding; namespace HeuristicLab.Problems.Programmable { internal static class Helper { internal static ParameterVector Extract(IScope scope, Configuration config) { var binDict = new Dictionary(); var intDict = new Dictionary(); var realDict = new Dictionary(); var permDict = new Dictionary(); foreach (var param in config.Parameters) { var binConfig = param.Value as BinaryParameterConfiguration; if (binConfig != null) { binDict.Add(param.Key, (BinaryVector)scope.Variables[param.Key].Value); continue; } var intConfig = param.Value as IntegerParameterConfiguration; if (intConfig != null) { intDict.Add(param.Key, (IntegerVector)scope.Variables[param.Key].Value); continue; } var realConfig = param.Value as RealParameterConfiguration; if (realConfig != null) { realDict.Add(param.Key, (RealVector)scope.Variables[param.Key].Value); continue; } var permConfig = param.Value as PermutationParameterConfiguration; if (permConfig != null) { permDict.Add(param.Key, (Permutation)scope.Variables[param.Key].Value); continue; } throw new InvalidOperationException("Parameter " + param.Key + " not found."); } return new ParameterVector( binaryVectors: binDict.Count > 0 ? binDict : null, integerVectors: intDict.Count > 0 ? intDict : null, realVectors: realDict.Count > 0 ? realDict : null, permutations: permDict.Count > 0 ? permDict : null); } } }