1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Data;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
11 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
12 | using HeuristicLab.Collections;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
|
---|
15 | public class PermutationToRealVectorEncoder : SingleSuccessorOperator, IRealVectorEncoder, IPermutationManipulator {
|
---|
16 |
|
---|
17 | public ILookupParameter<RealVector> RealVectorParameter {
|
---|
18 | get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
|
---|
19 | }
|
---|
20 |
|
---|
21 | public ILookupParameter<Permutation> PermutationParameter {
|
---|
22 | get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
|
---|
23 | }
|
---|
24 |
|
---|
25 | public PermutationToRealVectorEncoder() : base() {
|
---|
26 | Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation to encode."));
|
---|
27 | Parameters.Add(new LookupParameter<RealVector>("RealVector", "The resulting real vector."));
|
---|
28 | }
|
---|
29 |
|
---|
30 | public override IOperation Apply() {
|
---|
31 | Permutation permutation = PermutationParameter.ActualValue;
|
---|
32 |
|
---|
33 | RealVector realVector = new RealVector(permutation.Length);
|
---|
34 | double max = permutation.Length;
|
---|
35 | for (int i = 0; i < permutation.Length; i++) {
|
---|
36 | realVector[permutation[i]] = max;
|
---|
37 | max = max - 1;
|
---|
38 | }
|
---|
39 | RealVectorParameter.ActualValue = realVector;
|
---|
40 | return base.Apply();
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override bool CanChangeName {
|
---|
44 | get { return false; }
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|