Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/15 15:24:12 (9 years ago)
Author:
abeham
Message:

#2521: worked on multi-encoding (it works again). Some issues are still present:

  • The programmable template needs to be slightly updated for multi-encoding
  • The encoding is recreated every time it is compiled making it impossible to configure operators
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/ScopeUtil.cs

    r13351 r13359  
    2323
    2424using System;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627
     
    3031    public static TSolution CopySolutionToScope<TSolution>(IScope scope, IEncoding<TSolution> encoding, TSolution solution)
    3132      where TSolution : class,ISolution {
    32       var name = encoding.Name;
     33      return CopySolutionToScope(scope, encoding.Name, solution);
     34    }
     35
     36    public static TSolution CopySolutionToScope<TSolution>(IScope scope, string name, TSolution solution)
     37      where TSolution : class,ISolution {
    3338      var copy = (TSolution)solution.Clone();
    3439      if (!scope.Variables.ContainsKey(name)) scope.Variables.Add(new Variable(name, copy));
     
    4247      if (!scope.Variables.ContainsKey(name)) throw new ArgumentException(string.Format(" {0} cannot be found in the provided scope.", name));
    4348      var value = scope.Variables[name].Value as TSolution;
    44       if (value == null) throw new InvalidOperationException(string.Format("Value of {0} is null.", name));
     49      if (value == null) throw new InvalidOperationException(string.Format("Value of {0} is null or not of type {1}.", name, typeof(TSolution).GetPrettyName()));
    4550      return value;
    4651    }
    4752
    4853    public static ISolution GetSolution(IScope scope, IEncoding encoding) {
    49       var name = encoding.Name;
    50       if (!scope.Variables.ContainsKey(name)) throw new ArgumentException(string.Format(" {0} cannot be found in the provided scope.", name));
    51       var value = scope.Variables[name].Value as ISolution;
    52       if (value == null) throw new InvalidOperationException(string.Format("Value of {0} is null.", name));
    53       return value;
     54      return GetSolution(scope, encoding.Name);
     55    }
     56
     57    public static ISolution GetSolution(IScope scope, string name) {
     58      IVariable variable;
     59      if (!scope.Variables.TryGetValue(name, out variable)) throw new ArgumentException(string.Format("{0} cannot be found in the provided scope.", name));
     60      var solution = variable.Value as ISolution;
     61      if (solution == null) throw new InvalidOperationException(string.Format("{0} is null or not of type ISolution.", name));
     62      return solution;
    5463    }
    5564
Note: See TracChangeset for help on using the changeset viewer.