[11396] | 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.Core;
|
---|
| 25 | using HeuristicLab.Encodings.BinaryVectorEncoding;
|
---|
| 26 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 27 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 28 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.Programmable {
|
---|
| 31 | internal static class Helper {
|
---|
| 32 | internal static ParameterVector Extract(IScope scope, Configuration config) {
|
---|
| 33 | var binDict = new Dictionary<string, BinaryVector>();
|
---|
| 34 | var intDict = new Dictionary<string, IntegerVector>();
|
---|
| 35 | var realDict = new Dictionary<string, RealVector>();
|
---|
| 36 | var permDict = new Dictionary<string, Permutation>();
|
---|
| 37 | foreach (var param in config.Parameters) {
|
---|
| 38 | var binConfig = param.Value as BinaryParameterConfiguration;
|
---|
| 39 | if (binConfig != null) {
|
---|
| 40 | binDict.Add(param.Key, (BinaryVector)scope.Variables[param.Key].Value);
|
---|
| 41 | continue;
|
---|
| 42 | }
|
---|
| 43 | var intConfig = param.Value as IntegerParameterConfiguration;
|
---|
| 44 | if (intConfig != null) {
|
---|
| 45 | intDict.Add(param.Key, (IntegerVector)scope.Variables[param.Key].Value);
|
---|
| 46 | continue;
|
---|
| 47 | }
|
---|
| 48 | var realConfig = param.Value as RealParameterConfiguration;
|
---|
| 49 | if (realConfig != null) {
|
---|
| 50 | realDict.Add(param.Key, (RealVector)scope.Variables[param.Key].Value);
|
---|
| 51 | continue;
|
---|
| 52 | }
|
---|
| 53 | var permConfig = param.Value as PermutationParameterConfiguration;
|
---|
| 54 | if (permConfig != null) {
|
---|
| 55 | permDict.Add(param.Key, (Permutation)scope.Variables[param.Key].Value);
|
---|
| 56 | continue;
|
---|
| 57 | }
|
---|
| 58 | throw new InvalidOperationException("Parameter " + param.Key + " not found.");
|
---|
| 59 | }
|
---|
| 60 | return new ParameterVector(
|
---|
| 61 | binaryVectors: binDict.Count > 0 ? binDict : null,
|
---|
| 62 | integerVectors: intDict.Count > 0 ? intDict : null,
|
---|
| 63 | realVectors: realDict.Count > 0 ? realDict : null,
|
---|
| 64 | permutations: permDict.Count > 0 ? permDict : null);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | }
|
---|