1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 | using HeuristicLab.PluginInfrastructure;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Analysis.SolutionCaching.RealVectorEncoding {
|
---|
35 | [Item("RealVectorMutationPointcut", "Wraps a mutation and applies after-mutation actions.")]
|
---|
36 | [StorableClass]
|
---|
37 | public class RealVectorMutationPointcut : MutationPointcut<IRealVectorAdvice, IRealVectorManipulator>, IRealVectorManipulator, IRealVectorPointcut {
|
---|
38 | public ILookupParameter<RealVector> RealVectorParameter {
|
---|
39 | get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
|
---|
40 | }
|
---|
41 | public IValueLookupParameter<DoubleMatrix> BoundsParameter {
|
---|
42 | get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
|
---|
43 | }
|
---|
44 |
|
---|
45 | [StorableConstructor]
|
---|
46 | protected RealVectorMutationPointcut(bool deserializing) : base(deserializing) { }
|
---|
47 | protected RealVectorMutationPointcut(RealVectorMutationPointcut original, Cloner cloner) : base(original, cloner) { }
|
---|
48 |
|
---|
49 | public RealVectorMutationPointcut()
|
---|
50 | : base() {
|
---|
51 | Parameters.Add(new LookupParameter<RealVector>("RealVector", "The real vector that is being manipulating."));
|
---|
52 | Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector."));
|
---|
53 |
|
---|
54 | //Would be nicer if it comes from operator collection, but MultiRealVector Crossover does the same thing.
|
---|
55 | //Also: MultiRealVectorCrossover cannot be used here as it would generate a cyclic recursion
|
---|
56 | //MultiRealVectorCrossover discovers RealVectorCrossoverPointcut which discovers Multi....
|
---|
57 | foreach (Type t in ApplicationManager.Manager.GetTypes(typeof(IRealVectorManipulator))) {
|
---|
58 | if ((!typeof(RealVectorMutationPointcut).IsAssignableFrom(t)) &&
|
---|
59 | (!typeof(MultiOperator<IRealVectorManipulator>).IsAssignableFrom(t))) {
|
---|
60 | MutatorsParameter.ValidValues.Add((IRealVectorManipulator)Activator.CreateInstance(t));
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | ParameterizeManipulators();
|
---|
65 | }
|
---|
66 |
|
---|
67 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
68 | return new RealVectorMutationPointcut(this, cloner);
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void ParameterizeManipulators() {
|
---|
72 | foreach (IRealVectorManipulator manipulator in MutatorsParameter.ValidValues.OfType<IRealVectorManipulator>()) {
|
---|
73 | manipulator.RealVectorParameter.ActualName = RealVectorParameter.Name;
|
---|
74 | manipulator.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
75 | }
|
---|
76 | foreach (IStochasticOperator manipulator in MutatorsParameter.ValidValues.OfType<IStochasticOperator>()) {
|
---|
77 | manipulator.RandomParameter.ActualName = RandomParameter.Name;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|