Last change
on this file since 3348 was
3348,
checked in by mkofler, 14 years ago
|
Added project for particle swarm optimization algorithm #852 (WIP)
|
File size:
1.6 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 | using HeuristicLab.Parameters;
|
---|
9 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
10 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
11 | using HeuristicLab.Collections;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
|
---|
14 | public class PermutationToRealVectorEncoder : SingleSuccessorOperator, IRealVectorEncoder, IPermutationManipulator {
|
---|
15 |
|
---|
16 | public ILookupParameter<RealVector> RealVectorParameter {
|
---|
17 | get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
|
---|
18 | }
|
---|
19 |
|
---|
20 | public ILookupParameter<Permutation> PermutationParameter {
|
---|
21 | get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
|
---|
22 | }
|
---|
23 |
|
---|
24 | public PermutationToRealVectorEncoder() : base() {
|
---|
25 | Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation to encode."));
|
---|
26 | Parameters.Add(new LookupParameter<RealVector>("RealVector", "The resulting real vector."));
|
---|
27 | }
|
---|
28 |
|
---|
29 | public override IOperation Apply() {
|
---|
30 | Permutation permutation = PermutationParameter.ActualValue;
|
---|
31 |
|
---|
32 | RealVector realVector = new RealVector(permutation.Length);
|
---|
33 | double max = permutation.Length;
|
---|
34 | for (int i = 0; i < permutation.Length; i++) {
|
---|
35 | realVector[permutation[i]] = max;
|
---|
36 | max = max - 1;
|
---|
37 | }
|
---|
38 | RealVectorParameter.ActualValue = realVector;
|
---|
39 | return base.Apply();
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override bool CanChangeName {
|
---|
43 | get { return false; }
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.