Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/18/19 15:06:18 (4 years ago)
Author:
mkommend
Message:

#2521: Fixed single-objective evaluation results and scope contexts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SolutionContextScope.cs

    r17363 r17381  
    2727//TODO: don't derive from NamedItem, this has been done to have a fast working prototype
    2828namespace HeuristicLab.Optimization {
    29   internal class SolutionContextScope<TEncodedSolution> : SolutionContext<TEncodedSolution>, ISolutionScope
     29  internal abstract class SolutionContextScope<TEncodedSolution> : SolutionContext<TEncodedSolution>, ISolutionScope
    3030   where TEncodedSolution : class, IEncodedSolution {
    31     private readonly IScope scope;
     31    protected static string EVALUATION_RESULT_VARIABLE_NAME = "Evaluation Result";
     32
     33    protected IScope Scope { get; }
    3234
    3335    public SolutionContextScope(IScope scope, TEncodedSolution solution) : base(solution) {
    34       this.scope = scope;
     36      Scope = scope;
    3537    }
    3638
     
    4042
    4143    IScope IScope.Parent {
    42       get { return scope.Parent; }
     44      get { return Scope.Parent; }
    4345      set { throw new NotSupportedException(); }
    4446    }
    4547
    46     VariableCollection IScope.Variables => scope.Variables;
    47     ScopeList IScope.SubScopes => scope.SubScopes;
     48    VariableCollection IScope.Variables => Scope.Variables;
     49    ScopeList IScope.SubScopes => Scope.SubScopes;
    4850
    4951    void IScope.Clear() { throw new NotImplementedException(); }
    5052
    51 
    52 
    5353    #region INamedItem members
    54     string INamedItem.Name { get { return scope.Name; } set => throw new NotImplementedException(); }
     54    string INamedItem.Name { get { return Scope.Name; } set => throw new NotImplementedException(); }
    5555    bool INamedItem.CanChangeName => false;
    5656
    57     string INamedItem.Description { get { return scope.Description; } set => throw new NotImplementedException(); }
     57    string INamedItem.Description { get { return Scope.Description; } set => throw new NotImplementedException(); }
    5858    bool INamedItem.CanChangeDescription => false;
    5959
     
    7878    where TEncodedSolution : class, IEncodedSolution {
    7979
    80     public new ISingleObjectiveEvaluationResult EvaluationResult { get; set; }
     80    public new ISingleObjectiveEvaluationResult EvaluationResult {
     81      get {
     82        return (ISingleObjectiveEvaluationResult)Scope.Variables[EVALUATION_RESULT_VARIABLE_NAME].Value;
     83      }
     84      set {
     85        Scope.Variables.Remove(EVALUATION_RESULT_VARIABLE_NAME);
     86        Scope.Variables.Add(new Variable(EVALUATION_RESULT_VARIABLE_NAME, value));
     87      }
     88    }
     89
    8190    public SingleObjectiveSolutionContextScope(IScope scope, TEncodedSolution solution) : base(scope, solution) {
    8291    }
     
    8695  where TEncodedSolution : class, IEncodedSolution {
    8796
    88     public new IMultiObjectiveEvaluationResult EvaluationResult { get; set; }
     97    public new IMultiObjectiveEvaluationResult EvaluationResult {
     98      get {
     99        return (IMultiObjectiveEvaluationResult)Scope.Variables[EVALUATION_RESULT_VARIABLE_NAME].Value;
     100      }
     101      set {
     102        Scope.Variables.Remove(EVALUATION_RESULT_VARIABLE_NAME);
     103        Scope.Variables.Add(new Variable(EVALUATION_RESULT_VARIABLE_NAME, value));
     104      }
     105    }
    89106    public MultiObjectiveSolutionContextScope(IScope scope, TEncodedSolution solution) : base(scope, solution) {
    90107    }
Note: See TracChangeset for help on using the changeset viewer.