Last change
on this file since 84 was
84,
checked in by abeham, 16 years ago
|
fixed ticket #73
- removed code duplicating operators in Permutation
- added general VariableStrengthRepeatingManipulator
|
File size:
1.4 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.Random;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.ES {
|
---|
10 | public class VariableStrengthRepeatingManipulator : OperatorBase {
|
---|
11 | public override string Description {
|
---|
12 | get { return @"Applies its suboperator a number of times depending on the ShakingFactor"; }
|
---|
13 | }
|
---|
14 |
|
---|
15 | public VariableStrengthRepeatingManipulator()
|
---|
16 | : base() {
|
---|
17 | AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
|
---|
18 | AddVariableInfo(new VariableInfo("ShakingFactor", "Determines the strength of the mutation (repeated application of the operator)", typeof(DoubleData), VariableKind.In));
|
---|
19 | }
|
---|
20 |
|
---|
21 | public override IOperation Apply(IScope scope) {
|
---|
22 | IRandom random = GetVariableValue<IRandom>("Random", scope, true);
|
---|
23 | double shakingFactor = scope.GetVariableValue<DoubleData>("ShakingFactor", true).Data;
|
---|
24 | NormalDistributedRandom N = new NormalDistributedRandom(random, 1.0, shakingFactor);
|
---|
25 | int strength = (int)Math.Ceiling(Math.Abs(N.NextDouble()));
|
---|
26 | if (strength == 0) strength = 1;
|
---|
27 |
|
---|
28 | CompositeOperation co = new CompositeOperation();
|
---|
29 | co.ExecuteInParallel = false;
|
---|
30 | for (int i = 0; i < strength; i++) {
|
---|
31 | co.AddOperation(new AtomicOperation(SubOperators[0], scope));
|
---|
32 | }
|
---|
33 |
|
---|
34 | return co;
|
---|
35 | }
|
---|
36 | }
|
---|
37 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.