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/Individuals/MultiSolution.cs

    r13356 r13359  
    3535    protected IScope Scope { get; private set; }
    3636
    37     private readonly Dictionary<string, ISolution> solutions;
    38 
    3937    [StorableConstructor]
    4038    private CombinedSolution(bool deserializing) : base(deserializing) { }
     
    4442      Encoding = cloner.Clone(original.Encoding);
    4543      Scope = cloner.Clone(original.Scope);
    46       solutions = original.solutions.ToDictionary(x => x.Key, x => cloner.Clone(x.Value));
    4744    }
    4845    public CombinedSolution(IScope scope, MultiEncoding encoding) {
    4946      Encoding = encoding;
    5047      Scope = scope;
    51       solutions = encoding.Encodings.Select(e => new { Name = e.Name, Solution = ScopeUtil.GetSolution(scope, e) })
    52                                     .ToDictionary(x => x.Name, x => x.Solution);
    5348    }
    5449
     
    5853
    5954    public ISolution this[string name] {
    60       get {
    61         ISolution result;
    62         if (!solutions.TryGetValue(name, out result)) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name));
    63         return result;
    64       }
    65       set {
    66         if (!solutions.ContainsKey(name)) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name));
    67         solutions[name] = value;
    68       }
     55      get { return ScopeUtil.GetSolution(Scope, name); }
     56      set { ScopeUtil.CopySolutionToScope(Scope, name, value); }
    6957    }
    7058
     
    8068    }
    8169
    82     public TSolution GetSolution<TSolution>() where TSolution : class, ISolution {
    83       TSolution solution;
    84       try {
    85         solution = (TSolution)solutions.SingleOrDefault(s => s.Value is TSolution).Value;
    86       } catch (InvalidOperationException) {
    87         throw new InvalidOperationException(string.Format("The solution uses multiple {0} .", typeof(TSolution).GetPrettyName()));
    88       }
    89       if (solution == null) throw new InvalidOperationException(string.Format("The solution does not use a {0}.", typeof(TSolution).GetPrettyName()));
    90       return solution;
     70    public TSolution GetSolution<TSolution>(string name) where TSolution : class, ISolution {
     71      return (TSolution)ScopeUtil.GetSolution(Scope, name);
    9172    }
    9273  }
Note: See TracChangeset for help on using the changeset viewer.