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 |
|
---|
22 | using HeuristicLab.BioBoost.ProblemDescription;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
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 | using System.Linq;
|
---|
34 | using HeuristicLab.BioBoost.Representation;
|
---|
35 | using HEAL.Attic;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.BioBoost.SolutionCreation {
|
---|
38 |
|
---|
39 | [StorableType("531890AB-4D1C-4CC2-B2C8-66809BD010D7")]
|
---|
40 | public class BioBoostSolutionCreator : SingleSuccessorOperator, ISolutionCreator {
|
---|
41 |
|
---|
42 | #region Parameters
|
---|
43 | public ValueLookupParameter<IntMatrix> RegionBoundsParameter {
|
---|
44 | get { return (ValueLookupParameter<IntMatrix>) Parameters["RegionBounds"]; }
|
---|
45 | }
|
---|
46 | public ValueLookupParameter<IntValue> NRegionsParameter {
|
---|
47 | get { return (ValueLookupParameter<IntValue>) Parameters["NRegions"]; }
|
---|
48 | }
|
---|
49 | public ConstrainedValueParameter<IRealVectorCreator> RealVectorCreatorParameter {
|
---|
50 | get { return (ConstrainedValueParameter<IRealVectorCreator>) Parameters["RealVectorCreator"]; }
|
---|
51 | }
|
---|
52 | public ConstrainedValueParameter<IIntegerVectorCreator> IntegerVectorCreatorParameter {
|
---|
53 | get { return (ConstrainedValueParameter<IIntegerVectorCreator>) Parameters["IntegerVectorCreator"]; }
|
---|
54 | }
|
---|
55 | public LookupParameter<BioBoostProblemData> ProblemDataParameter {
|
---|
56 | get { return (LookupParameter<BioBoostProblemData>) Parameters["ProblemData"]; }
|
---|
57 | }
|
---|
58 | #endregion
|
---|
59 |
|
---|
60 | #region Parameter Values
|
---|
61 | public IntMatrix RegionBounds {
|
---|
62 | get { return RegionBoundsParameter.ActualValue; }
|
---|
63 | }
|
---|
64 | public IRealVectorCreator RealVectorCreator {
|
---|
65 | get { return RealVectorCreatorParameter.Value; }
|
---|
66 | set { RealVectorCreatorParameter.Value = value; }
|
---|
67 | }
|
---|
68 | public IIntegerVectorCreator IntegerVectorCreator {
|
---|
69 | get { return IntegerVectorCreatorParameter.Value; }
|
---|
70 | set { IntegerVectorCreatorParameter.Value = value; }
|
---|
71 | }
|
---|
72 | public BioBoostProblemData ProblemData {
|
---|
73 | get { return ProblemDataParameter.ActualValue; }
|
---|
74 | set { ProblemDataParameter.ActualValue = value; }
|
---|
75 | }
|
---|
76 | #endregion
|
---|
77 |
|
---|
78 | #region Construction & Cloning
|
---|
79 | [StorableConstructor]
|
---|
80 | protected BioBoostSolutionCreator(StorableConstructorFlag _) : base(_) { }
|
---|
81 | protected BioBoostSolutionCreator(BioBoostSolutionCreator orig, Cloner cloner) : base(orig, cloner) {}
|
---|
82 | public BioBoostSolutionCreator() {
|
---|
83 | Parameters.Add(new ValueLookupParameter<IntMatrix>("RegionBounds", "Limits of valid region ids."));
|
---|
84 | Parameters.Add(new ValueLookupParameter<IntValue>("NRegions", "Number of regions."));
|
---|
85 | Parameters.Add(new ConstrainedValueParameter<IRealVectorCreator>("RealVectorCreator", "Creator for initial feedstock utilizations."));
|
---|
86 | Parameters.Add(new ConstrainedValueParameter<IIntegerVectorCreator>("IntegerVectorCreator", "Creator for transport traget initialization."));
|
---|
87 | Parameters.Add(new LookupParameter<BioBoostProblemData>("ProblemData", "The problem data store."));
|
---|
88 | RegionBoundsParameter.Hidden = true;
|
---|
89 | foreach (var op in ApplicationManager.Manager.GetInstances<IRealVectorCreator>()) {
|
---|
90 | op.BoundsParameter.Value = new DoubleMatrix(new double[,] {{0, 1}});
|
---|
91 | op.LengthParameter.ActualName = NRegionsParameter.ActualName;
|
---|
92 | RealVectorCreatorParameter.ValidValues.Add(op);
|
---|
93 | }
|
---|
94 | foreach (var op in ApplicationManager.Manager.GetInstances<IIntegerVectorCreator>()) {
|
---|
95 | op.BoundsParameter.ActualName = RegionBoundsParameter.ActualName;
|
---|
96 | op.LengthParameter.ActualName = NRegionsParameter.ActualName;
|
---|
97 | IntegerVectorCreatorParameter.ValidValues.Add(op);
|
---|
98 | }
|
---|
99 | RealVectorCreatorParameter.Value = RealVectorCreatorParameter.ValidValues.FirstOrDefault(c => c.GetType() == typeof (ConstantValueRealVectorCreator));
|
---|
100 | IntegerVectorCreatorParameter.Value = IntegerVectorCreatorParameter.ValidValues.FirstOrDefault( c => c.GetType() == typeof (UniformRandomIntegerVectorCreator));
|
---|
101 | ((ConstantValueRealVectorCreator) RealVectorCreator).Value = 0.5;
|
---|
102 | }
|
---|
103 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
104 | return new BioBoostSolutionCreator(this, cloner);
|
---|
105 | }
|
---|
106 | #endregion
|
---|
107 |
|
---|
108 | public override IOperation Apply() {
|
---|
109 | var ops = new OperationCollection(base.Apply());
|
---|
110 | foreach (var n in ProblemData.TransportTargets.CheckedItems) {
|
---|
111 | var op = (IIntegerVectorCreator)IntegerVectorCreator.Clone();
|
---|
112 | op.IntegerVectorParameter.ActualName = LayerDescriptor.TransportTargets.NameWithPrefix(n.Value.Value);
|
---|
113 | ops.Add(ExecutionContext.CreateChildOperation(op));
|
---|
114 | }
|
---|
115 | foreach (var n in ProblemData.Utilizations.CheckedItems) {
|
---|
116 | var op = (IRealVectorCreator)RealVectorCreator.Clone();
|
---|
117 | op.RealVectorParameter.ActualName = LayerDescriptor.Utilizations.NameWithPrefix(n.Value.Value);
|
---|
118 | ops.Add(ExecutionContext.CreateChildOperation(op));
|
---|
119 | }
|
---|
120 | return ops;
|
---|
121 | }
|
---|
122 |
|
---|
123 | }
|
---|
124 | }
|
---|