source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/SolutionCreation/BioBoostSolutionCreator.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 7 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 5.0 KB
Line 
1using HeuristicLab.BioBoost.ProblemDescription;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Encodings.IntegerVectorEncoding;
6using HeuristicLab.Encodings.RealVectorEncoding;
7using HeuristicLab.Operators;
8using HeuristicLab.Optimization;
9using HeuristicLab.Parameters;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using HeuristicLab.PluginInfrastructure;
12using System.Linq;
13using HeuristicLab.BioBoost.Representation;
14
15namespace HeuristicLab.BioBoost.SolutionCreation {
16
17  [StorableClass]
18  public class BioBoostSolutionCreator : SingleSuccessorOperator, ISolutionCreator {
19
20    #region Parameters
21    public ValueLookupParameter<IntMatrix> RegionBoundsParameter {
22      get { return (ValueLookupParameter<IntMatrix>) Parameters["RegionBounds"]; }
23    }
24    public ValueLookupParameter<IntValue> NRegionsParameter {
25      get { return (ValueLookupParameter<IntValue>) Parameters["NRegions"]; }
26    }
27    public ConstrainedValueParameter<IRealVectorCreator> RealVectorCreatorParameter {
28      get { return (ConstrainedValueParameter<IRealVectorCreator>) Parameters["RealVectorCreator"]; }
29    }
30    public ConstrainedValueParameter<IIntegerVectorCreator> IntegerVectorCreatorParameter {
31      get { return (ConstrainedValueParameter<IIntegerVectorCreator>) Parameters["IntegerVectorCreator"]; }
32    }
33    public LookupParameter<BioBoostProblemData> ProblemDataParameter {
34      get { return (LookupParameter<BioBoostProblemData>) Parameters["ProblemData"]; }
35    }
36    #endregion
37
38    #region Parameter Values
39    public IntMatrix RegionBounds {
40      get { return RegionBoundsParameter.ActualValue; }
41    }
42    public IRealVectorCreator RealVectorCreator {
43      get { return RealVectorCreatorParameter.Value; }
44      set { RealVectorCreatorParameter.Value = value; }
45    }
46    public IIntegerVectorCreator IntegerVectorCreator {
47      get { return IntegerVectorCreatorParameter.Value; }
48      set { IntegerVectorCreatorParameter.Value = value; }
49    }
50    public BioBoostProblemData ProblemData {
51      get { return ProblemDataParameter.ActualValue; }
52      set { ProblemDataParameter.ActualValue = value; }
53    }
54    #endregion
55
56    #region Construction & Cloning
57    [StorableConstructor]
58    protected BioBoostSolutionCreator(bool isDeserializing) : base(isDeserializing) {}
59    protected BioBoostSolutionCreator(BioBoostSolutionCreator orig, Cloner cloner) : base(orig, cloner) {}
60    public BioBoostSolutionCreator() {
61      Parameters.Add(new ValueLookupParameter<IntMatrix>("RegionBounds", "Limits of valid region ids."));
62      Parameters.Add(new ValueLookupParameter<IntValue>("NRegions", "Number of regions."));
63      Parameters.Add(new ConstrainedValueParameter<IRealVectorCreator>("RealVectorCreator", "Creator for initial feedstock utilizations."));
64      Parameters.Add(new ConstrainedValueParameter<IIntegerVectorCreator>("IntegerVectorCreator", "Creator for transport traget initialization."));
65      Parameters.Add(new LookupParameter<BioBoostProblemData>("ProblemData", "The problem data store."));
66      RegionBoundsParameter.Hidden = true;
67      foreach (var op in ApplicationManager.Manager.GetInstances<IRealVectorCreator>()) {
68        op.BoundsParameter.Value = new DoubleMatrix(new double[,] {{0, 1}});
69        op.LengthParameter.ActualName = NRegionsParameter.ActualName;
70        RealVectorCreatorParameter.ValidValues.Add(op);
71      }
72      foreach (var op in ApplicationManager.Manager.GetInstances<IIntegerVectorCreator>()) {
73        op.BoundsParameter.ActualName = RegionBoundsParameter.ActualName;
74        op.LengthParameter.ActualName = NRegionsParameter.ActualName;
75        IntegerVectorCreatorParameter.ValidValues.Add(op);
76      }
77      RealVectorCreatorParameter.Value = RealVectorCreatorParameter.ValidValues.FirstOrDefault(c => c.GetType() == typeof (ConstantValueRealVectorCreator));
78      IntegerVectorCreatorParameter.Value = IntegerVectorCreatorParameter.ValidValues.FirstOrDefault( c => c.GetType() == typeof (UniformRandomIntegerVectorCreator));
79      ((ConstantValueRealVectorCreator) RealVectorCreator).Value = 0.5;
80    }
81    public override IDeepCloneable Clone(Cloner cloner) {
82      return new BioBoostSolutionCreator(this, cloner);
83    }
84    #endregion
85
86    public override IOperation Apply() {
87      var ops = new OperationCollection(base.Apply());
88      foreach (var n in ProblemData.TransportTargets.CheckedItems) {
89        var op = (IIntegerVectorCreator)IntegerVectorCreator.Clone();
90        op.IntegerVectorParameter.ActualName = LayerDescriptor.TransportTargets.NameWithPrefix(n.Value.Value);
91        ops.Add(ExecutionContext.CreateChildOperation(op));
92      }
93      foreach (var n in ProblemData.Utilizations.CheckedItems) {
94        var op = (IRealVectorCreator)RealVectorCreator.Clone();
95        op.RealVectorParameter.ActualName = LayerDescriptor.Utilizations.NameWithPrefix(n.Value.Value);
96        ops.Add(ExecutionContext.CreateChildOperation(op));
97      }
98      return ops;
99    }
100
101  }
102}
Note: See TracBrowser for help on using the repository browser.