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 HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Operators;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Parameters;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 | using HeuristicLab.PluginInfrastructure;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Analysis.SolutionCaching {
|
---|
31 | [StorableClass]
|
---|
32 | public abstract class CrossoverPointcut<TA, TC> : SingleSuccessorOperator, ICrossover, IStochasticOperator, IPointcut
|
---|
33 | where TA : class, IAdvice
|
---|
34 | where TC : class, ICrossover {
|
---|
35 | protected const string AdviceParameterName = "Advice";
|
---|
36 | protected const string CrossoversParameterName = "Crossovers";
|
---|
37 |
|
---|
38 | public ConstrainedValueParameter<TC> CrossoversParameter {
|
---|
39 | get { return (ConstrainedValueParameter<TC>)Parameters[CrossoversParameterName]; }
|
---|
40 | }
|
---|
41 | public ConstrainedValueParameter<TA> AdviceParameter {
|
---|
42 | get { return (ConstrainedValueParameter<TA>)Parameters[AdviceParameterName]; }
|
---|
43 | }
|
---|
44 | public ILookupParameter<IRandom> RandomParameter {
|
---|
45 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | [StorableConstructor]
|
---|
49 | protected CrossoverPointcut(bool deserializing) : base(deserializing) { }
|
---|
50 | protected CrossoverPointcut(CrossoverPointcut<TA, TC> original, Cloner cloner) : base(original, cloner) { }
|
---|
51 |
|
---|
52 | public CrossoverPointcut()
|
---|
53 | : base() {
|
---|
54 | var advices = new ConstrainedValueParameter<TA>(AdviceParameterName,
|
---|
55 | "Advice to introduce after crossover");
|
---|
56 | foreach (var a in ApplicationManager.Manager.GetInstances<TA>()) {
|
---|
57 | advices.ValidValues.Add(a);
|
---|
58 | }
|
---|
59 | Parameters.Add(advices);
|
---|
60 | Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
|
---|
61 | Parameters.Add(new ConstrainedValueParameter<TC>(CrossoversParameterName, "The crossovers."));
|
---|
62 | }
|
---|
63 |
|
---|
64 | public override IOperation Apply() {
|
---|
65 | IOperation successor = base.Apply();
|
---|
66 | IOperation crossoverOperation = ExecutionContext.CreateChildOperation(CrossoversParameter.Value);
|
---|
67 | IOperation adviceOperation = ExecutionContext.CreateChildOperation(AdviceParameter.Value);
|
---|
68 |
|
---|
69 | var opCol = new OperationCollection();
|
---|
70 | opCol.Add(crossoverOperation);
|
---|
71 | opCol.Add(adviceOperation);
|
---|
72 | if (successor != null)
|
---|
73 | opCol.Add(successor);
|
---|
74 |
|
---|
75 | return opCol;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|