using HeuristicLab.BioBoost.ProblemDescription; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.IntegerVectorEncoding; using HeuristicLab.Encodings.RealVectorEncoding; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.PluginInfrastructure; using System.Linq; using HeuristicLab.BioBoost.Representation; namespace HeuristicLab.BioBoost.SolutionCreation { [StorableClass] public class BioBoostSolutionCreator : SingleSuccessorOperator, ISolutionCreator { #region Parameters public ValueLookupParameter RegionBoundsParameter { get { return (ValueLookupParameter) Parameters["RegionBounds"]; } } public ValueLookupParameter NRegionsParameter { get { return (ValueLookupParameter) Parameters["NRegions"]; } } public ConstrainedValueParameter RealVectorCreatorParameter { get { return (ConstrainedValueParameter) Parameters["RealVectorCreator"]; } } public ConstrainedValueParameter IntegerVectorCreatorParameter { get { return (ConstrainedValueParameter) Parameters["IntegerVectorCreator"]; } } public LookupParameter ProblemDataParameter { get { return (LookupParameter) Parameters["ProblemData"]; } } #endregion #region Parameter Values public IntMatrix RegionBounds { get { return RegionBoundsParameter.ActualValue; } } public IRealVectorCreator RealVectorCreator { get { return RealVectorCreatorParameter.Value; } set { RealVectorCreatorParameter.Value = value; } } public IIntegerVectorCreator IntegerVectorCreator { get { return IntegerVectorCreatorParameter.Value; } set { IntegerVectorCreatorParameter.Value = value; } } public BioBoostProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } set { ProblemDataParameter.ActualValue = value; } } #endregion #region Construction & Cloning [StorableConstructor] protected BioBoostSolutionCreator(bool isDeserializing) : base(isDeserializing) {} protected BioBoostSolutionCreator(BioBoostSolutionCreator orig, Cloner cloner) : base(orig, cloner) {} public BioBoostSolutionCreator() { Parameters.Add(new ValueLookupParameter("RegionBounds", "Limits of valid region ids.")); Parameters.Add(new ValueLookupParameter("NRegions", "Number of regions.")); Parameters.Add(new ConstrainedValueParameter("RealVectorCreator", "Creator for initial feedstock utilizations.")); Parameters.Add(new ConstrainedValueParameter("IntegerVectorCreator", "Creator for transport traget initialization.")); Parameters.Add(new LookupParameter("ProblemData", "The problem data store.")); RegionBoundsParameter.Hidden = true; foreach (var op in ApplicationManager.Manager.GetInstances()) { op.BoundsParameter.Value = new DoubleMatrix(new double[,] {{0, 1}}); op.LengthParameter.ActualName = NRegionsParameter.ActualName; RealVectorCreatorParameter.ValidValues.Add(op); } foreach (var op in ApplicationManager.Manager.GetInstances()) { op.BoundsParameter.ActualName = RegionBoundsParameter.ActualName; op.LengthParameter.ActualName = NRegionsParameter.ActualName; IntegerVectorCreatorParameter.ValidValues.Add(op); } RealVectorCreatorParameter.Value = RealVectorCreatorParameter.ValidValues.FirstOrDefault(c => c.GetType() == typeof (ConstantValueRealVectorCreator)); IntegerVectorCreatorParameter.Value = IntegerVectorCreatorParameter.ValidValues.FirstOrDefault( c => c.GetType() == typeof (UniformRandomIntegerVectorCreator)); ((ConstantValueRealVectorCreator) RealVectorCreator).Value = 0.5; } public override IDeepCloneable Clone(Cloner cloner) { return new BioBoostSolutionCreator(this, cloner); } #endregion public override IOperation Apply() { var ops = new OperationCollection(base.Apply()); foreach (var n in ProblemData.TransportTargets.CheckedItems) { var op = (IIntegerVectorCreator)IntegerVectorCreator.Clone(); op.IntegerVectorParameter.ActualName = LayerDescriptor.TransportTargets.NameWithPrefix(n.Value.Value); ops.Add(ExecutionContext.CreateChildOperation(op)); } foreach (var n in ProblemData.Utilizations.CheckedItems) { var op = (IRealVectorCreator)RealVectorCreator.Clone(); op.RealVectorParameter.ActualName = LayerDescriptor.Utilizations.NameWithPrefix(n.Value.Value); ops.Add(ExecutionContext.CreateChildOperation(op)); } return ops; } } }