#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
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;
using DiscreteIntegerVectorCrossover = HeuristicLab.Encodings.IntegerVectorEncoding.DiscreteCrossover;
using DiscreteRealVectorCrossover = HeuristicLab.Encodings.RealVectorEncoding.DiscreteCrossover;
using SinglePointRealVectorCrossover = HeuristicLab.Encodings.RealVectorEncoding.SinglePointCrossover;
using SinglePointInteverVectorCrossover = HeuristicLab.Encodings.IntegerVectorEncoding.SinglePointCrossover;
namespace HeuristicLab.BioBoost.Operators.Crossover {
[StorableClass]
public class CompoundCrossover : SingleSuccessorOperator, ICrossover {
#region Parameters
public ValueLookupParameter RegionBoundsParameter {
get { return (ValueLookupParameter) Parameters["RegionBounds"]; }
}
public LookupParameter ProblemDataParameter {
get { return (LookupParameter) Parameters["ProblemData"]; }
}
public ConstrainedValueParameter TransportTargetCrossoverParameter {
get { return (ConstrainedValueParameter) Parameters["TransportTargetCrossover"]; }
}
public ConstrainedValueParameter FeedstockUtilizationCrossoverParameter {
get { return (ConstrainedValueParameter) Parameters["FeedstockUtilizationCrossover"]; }
}
#endregion
#region Parameter Values
public BioBoostProblemData ProblemData {
get { return ProblemDataParameter.ActualValue; }
}
#endregion
#region Construction & Cloning
[StorableConstructor]
protected CompoundCrossover(bool isDeserializing) : base(isDeserializing) {}
protected CompoundCrossover(CompoundCrossover orig, Cloner cloner) : base(orig, cloner) { }
public CompoundCrossover() {
Parameters.Add(new LookupParameter("ProblemData", "The data store of the detailed problem description."));
Parameters.Add(new ValueLookupParameter("RegionBounds", "The limits of valid region ids."));
Parameters.Add(new ConstrainedValueParameter("TransportTargetCrossover", "The manipulator to apply to the transport target vectors."));
Parameters.Add(new ConstrainedValueParameter("FeedstockUtilizationCrossover", "The manipulator for the feedstock utilization vectors."));
foreach (var op in ApplicationManager.Manager.GetInstances()) {
var bop = op as IBoundedIntegerVectorOperator;
if (bop != null)
bop.BoundsParameter.ActualName = RegionBoundsParameter.ActualName;
TransportTargetCrossoverParameter.ValidValues.Add(op);
}
foreach (var op in ApplicationManager.Manager.GetInstances()) {
op.BoundsParameter.Value = new DoubleMatrix(new double[,]{{0, 1}});
FeedstockUtilizationCrossoverParameter.ValidValues.Add(op);
}
TransportTargetCrossoverParameter.Value =
TransportTargetCrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == typeof (MultiIntegerVectorCrossover));
FeedstockUtilizationCrossoverParameter.Value =
FeedstockUtilizationCrossoverParameter.ValidValues.FirstOrDefault(
c => c.GetType() == typeof (MultiRealVectorCrossover));
var tc = (MultiIntegerVectorCrossover) TransportTargetCrossoverParameter.Value;
foreach (var op in tc.Operators) {
if (op is DiscreteIntegerVectorCrossover ||
op is SinglePointInteverVectorCrossover) {
// accept
} else {
tc.Operators.SetItemCheckedState(op, false);
}
}
var uc = (MultiRealVectorCrossover) FeedstockUtilizationCrossoverParameter.Value;
foreach (var op in uc.Operators) {
if (op is BlendAlphaCrossover ||
op is DiscreteRealVectorCrossover ||
op is HeuristicCrossover ||
op is LocalCrossover ||
op is RandomConvexCrossover ||
op is SinglePointRealVectorCrossover ||
op is UniformAllPositionsArithmeticCrossover ||
op is UniformSomePositionsArithmeticCrossover) {
// accept
} else {
uc.Operators.SetItemCheckedState(op, false);
}
}
}
public override IDeepCloneable Clone(Cloner cloner) {
return new CompoundCrossover(this, cloner);
}
#endregion
public override IOperation Apply() {
var ops = new OperationCollection(base.Apply());
foreach (var n in ProblemData.TransportTargets.CheckedItems) {
if (TransportTargetCrossoverParameter.ActualValue != null) {
var t = (IIntegerVectorCrossover) TransportTargetCrossoverParameter.ActualValue.Clone();
t.ParentsParameter.ActualName = LayerDescriptor.TransportTargets.NameWithPrefix(n.Value.Value);
t.ChildParameter.ActualName = LayerDescriptor.TransportTargets.NameWithPrefix(n.Value.Value);
ops.Add(ExecutionContext.CreateChildOperation(t));
}
}
foreach (var n in ProblemData.Utilizations.CheckedItems) {
if (FeedstockUtilizationCrossoverParameter.ActualValue != null) {
var u = (IRealVectorCrossover) FeedstockUtilizationCrossoverParameter.ActualValue.Clone();
u.ParentsParameter.ActualName = LayerDescriptor.Utilizations.NameWithPrefix(n.Value.Value);
u.ChildParameter.ActualName = LayerDescriptor.Utilizations.NameWithPrefix(n.Value.Value);
ops.Add(ExecutionContext.CreateChildOperation(u));
}
}
return ops;
}
}
}