Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Crossover/CompoundCrossover.cs @ 13071

Last change on this file since 13071 was 13071, checked in by gkronber, 9 years ago

#2499: added license headers and removed unused usings

File size: 6.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using HeuristicLab.BioBoost.ProblemDescription;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.IntegerVectorEncoding;
27using HeuristicLab.Encodings.RealVectorEncoding;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.PluginInfrastructure;
33using System.Linq;
34using HeuristicLab.BioBoost.Representation;
35using DiscreteIntegerVectorCrossover = HeuristicLab.Encodings.IntegerVectorEncoding.DiscreteCrossover;
36using DiscreteRealVectorCrossover = HeuristicLab.Encodings.RealVectorEncoding.DiscreteCrossover;
37using SinglePointRealVectorCrossover = HeuristicLab.Encodings.RealVectorEncoding.SinglePointCrossover;
38using SinglePointInteverVectorCrossover = HeuristicLab.Encodings.IntegerVectorEncoding.SinglePointCrossover;
39
40namespace HeuristicLab.BioBoost.Operators.Crossover {
41  [StorableClass]
42  public class CompoundCrossover : SingleSuccessorOperator, ICrossover {
43
44    #region Parameters
45    public ValueLookupParameter<IntMatrix> RegionBoundsParameter {
46      get { return (ValueLookupParameter<IntMatrix>) Parameters["RegionBounds"]; }
47    }
48    public LookupParameter<BioBoostProblemData> ProblemDataParameter {
49      get { return (LookupParameter<BioBoostProblemData>) Parameters["ProblemData"]; }
50    }
51    public ConstrainedValueParameter<IIntegerVectorCrossover> TransportTargetCrossoverParameter {
52      get { return (ConstrainedValueParameter<IIntegerVectorCrossover>) Parameters["TransportTargetCrossover"]; }
53    }
54    public ConstrainedValueParameter<IRealVectorCrossover> FeedstockUtilizationCrossoverParameter {
55      get { return (ConstrainedValueParameter<IRealVectorCrossover>) Parameters["FeedstockUtilizationCrossover"]; }
56    }
57    #endregion
58
59    #region Parameter Values
60    public BioBoostProblemData ProblemData {
61      get { return ProblemDataParameter.ActualValue; }
62    }
63    #endregion
64
65    #region Construction & Cloning
66    [StorableConstructor]
67    protected CompoundCrossover(bool isDeserializing) : base(isDeserializing) {}
68    protected CompoundCrossover(CompoundCrossover orig, Cloner cloner) : base(orig, cloner) { }
69    public CompoundCrossover() {
70      Parameters.Add(new LookupParameter<BioBoostProblemData>("ProblemData", "The data store of the detailed problem description."));
71      Parameters.Add(new ValueLookupParameter<IntMatrix>("RegionBounds", "The limits of valid region ids."));
72      Parameters.Add(new ConstrainedValueParameter<IIntegerVectorCrossover>("TransportTargetCrossover", "The manipulator to apply to the transport target vectors."));
73      Parameters.Add(new ConstrainedValueParameter<IRealVectorCrossover>("FeedstockUtilizationCrossover", "The manipulator for the feedstock utilization vectors."));
74      foreach (var op in ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>()) {
75        var bop = op as IBoundedIntegerVectorOperator;
76        if (bop != null)
77          bop.BoundsParameter.ActualName = RegionBoundsParameter.ActualName;
78        TransportTargetCrossoverParameter.ValidValues.Add(op);
79      }
80      foreach (var op in ApplicationManager.Manager.GetInstances<IRealVectorCrossover>()) {
81        op.BoundsParameter.Value = new DoubleMatrix(new double[,]{{0, 1}});
82        FeedstockUtilizationCrossoverParameter.ValidValues.Add(op);
83      }
84      TransportTargetCrossoverParameter.Value =
85        TransportTargetCrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == typeof (MultiIntegerVectorCrossover));
86      FeedstockUtilizationCrossoverParameter.Value =
87        FeedstockUtilizationCrossoverParameter.ValidValues.FirstOrDefault(
88          c => c.GetType() == typeof (MultiRealVectorCrossover));
89      var tc = (MultiIntegerVectorCrossover) TransportTargetCrossoverParameter.Value;
90      foreach (var op in tc.Operators) {
91        if (op is DiscreteIntegerVectorCrossover ||
92            op is SinglePointInteverVectorCrossover) {
93          // accept
94        } else {
95          tc.Operators.SetItemCheckedState(op, false);
96        }
97      }
98      var uc = (MultiRealVectorCrossover) FeedstockUtilizationCrossoverParameter.Value;
99      foreach (var op in uc.Operators) {
100        if (op is BlendAlphaCrossover ||
101            op is DiscreteRealVectorCrossover ||
102            op is HeuristicCrossover ||
103            op is LocalCrossover ||
104            op is RandomConvexCrossover ||
105            op is SinglePointRealVectorCrossover ||
106            op is UniformAllPositionsArithmeticCrossover ||
107            op is UniformSomePositionsArithmeticCrossover) {
108          // accept
109        } else {
110          uc.Operators.SetItemCheckedState(op, false);
111        }
112      }
113    }
114    public override IDeepCloneable Clone(Cloner cloner) {
115      return new CompoundCrossover(this, cloner);
116    }
117    #endregion
118
119    public override IOperation Apply() {
120      var ops = new OperationCollection(base.Apply());
121      foreach (var n in ProblemData.TransportTargets.CheckedItems) {
122        if (TransportTargetCrossoverParameter.ActualValue != null) {
123          var t = (IIntegerVectorCrossover) TransportTargetCrossoverParameter.ActualValue.Clone();
124          t.ParentsParameter.ActualName = LayerDescriptor.TransportTargets.NameWithPrefix(n.Value.Value);
125          t.ChildParameter.ActualName = LayerDescriptor.TransportTargets.NameWithPrefix(n.Value.Value);
126          ops.Add(ExecutionContext.CreateChildOperation(t));
127        }
128      }
129      foreach (var n in ProblemData.Utilizations.CheckedItems) {
130        if (FeedstockUtilizationCrossoverParameter.ActualValue != null) {
131          var u = (IRealVectorCrossover) FeedstockUtilizationCrossoverParameter.ActualValue.Clone();
132          u.ParentsParameter.ActualName = LayerDescriptor.Utilizations.NameWithPrefix(n.Value.Value);
133          u.ChildParameter.ActualName = LayerDescriptor.Utilizations.NameWithPrefix(n.Value.Value);
134          ops.Add(ExecutionContext.CreateChildOperation(u));
135        }
136      }
137      return ops;
138    }
139
140  }
141}
Note: See TracBrowser for help on using the repository browser.