Free cookie consent management tool by TermsFeed Policy Generator

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