Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/PermutationToRealVectorEncoder.cs @ 3629

Last change on this file since 3629 was 3376, checked in by swagner, 15 years ago

Moved interfaces and classes for deep cloning from HeuristicLab.Core to HeuristicLab.Common (#975).

File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Operators;
6using HeuristicLab.Common;
7using HeuristicLab.Core;
8using HeuristicLab.Data;
9using HeuristicLab.Parameters;
10using HeuristicLab.Encodings.PermutationEncoding;
11using HeuristicLab.Encodings.RealVectorEncoding;
12using HeuristicLab.Collections;
13
14namespace 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}
Note: See TracBrowser for help on using the repository browser.