using HeuristicLab.BioBoost.Operators; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using System; namespace HeuristicLab.BioBoost.Evaluators { [StorableClass] public abstract class BioBoostEvaluator : BioBoostOperator { #region Parameter public ILookupParameter CostsParameter { get { return (ILookupParameter) Parameters["Costs"]; } } public ILookupParameter IntermediateResultsParameter { get { return (ILookupParameter) Parameters["IntermediateResults"]; } } #endregion #region Parameter Values public ResultCollection Costs { get { return CostsParameter.ActualValue; } } public ResultCollection IntermediateResults { get { return IntermediateResultsParameter.ActualValue; } } #endregion #region Construction & Cloning [StorableConstructor] protected BioBoostEvaluator(bool isDeserializing) : base(isDeserializing) {} protected BioBoostEvaluator(BioBoostEvaluator original, Cloner cloner) : base(original, cloner) {} protected BioBoostEvaluator() { Parameters.Add(new LookupParameter("Costs", "Collection of all costs.")); Parameters.Add(new LookupParameter("Emissions", "Collection of all emissions.")); Parameters.Add(new LookupParameter("IntermediateResults", "Collection of all intermeditate results.")); } #endregion protected void PutInScope(string label, IItem value, bool isIntermediateVariable) { var vars = ExecutionContext.Scope.Variables; var var = new Variable(label, value); if (vars.ContainsKey(label)) vars.Remove(label); vars.Add(var); if (isIntermediateVariable) IntermediateResults.Add(new Result(var.Name, value.GetType())); } protected void AddInScope(string label, DoubleArray values, bool isIntermediateValue) { var oldValues = GetFromScope(label); if (oldValues != null) { if (oldValues.Length != values.Length) throw new ArgumentException("DoubleArray lentgh differs from new length, cannot add " + label); for (int i = 0; i