using HeuristicLab.BioBoost.ProblemDescription; using HeuristicLab.BioBoost.Representation; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.BioBoost.Operators { public abstract class BioBoostOperator : SingleSuccessorOperator { #region Parameters public ILookupParameter ProblemDataParameter { get { return (ILookupParameter) Parameters["ProblemData"]; } } #endregion #region Parameter Values public BioBoostProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } } #endregion #region Construction & Cloning [StorableConstructor] protected BioBoostOperator(bool isDeserializing) : base(isDeserializing) {} protected BioBoostOperator(BioBoostOperator original, Cloner cloner) : base(original, cloner) { } protected BioBoostOperator() { Parameters.Add(new LookupParameter("ProblemData", "Contains fixed values describing the problem.")); } #endregion protected T GetFromProblemData(string label) where T : class, IItem { IParameter param; if(LayerDescriptor.PotentialsFromProblemData.IsSuffixOf(label)) { ProblemData.FeedstockPotentials.TryGetValue(label, out param); } else { ProblemData.Parameters.TryGetValue(label, out param); } var valueParam = param as IValueParameter; if (valueParam != null) return valueParam.Value as T; if (param != null) return param.ActualValue as T; return null; } protected T GetFromScope(string label) where T : class, IItem { IVariable var = null; ExecutionContext.Scope.Variables.TryGetValue(label, out var); if (var != null) return var.Value as T; return null; } protected void RemoveFromScope(string label) { ExecutionContext.Scope.Variables.Remove(label); } protected void RenameInScope(string oldLabel, string newLabel) { var vars = ExecutionContext.Scope.Variables; IVariable var; if (!vars.TryGetValue(oldLabel, out var)) return; vars.Remove(oldLabel); if (vars.ContainsKey(newLabel)) vars.Remove(newLabel); vars.Add(new Variable(newLabel, var.Value)); } } }