Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/03/19 15:37:38 (6 years ago)
Author:
mkommend
Message:

#2521: Renamed Solution to EncodedSolution.

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators
Files:
9 edited

Legend:

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

    r16723 r16751  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    2829using HeuristicLab.Operators;
    2930using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    3131
    3232namespace HeuristicLab.Optimization {
    3333  [Item("Multi-objective Analyzer", "Calls the Analyze method of the problem definition.")]
    3434  [StorableType("903FE3D1-3179-4EA5-A7E1-63DE26239F9B")]
    35   public class MultiObjectiveAnalyzer<TSolution> : SingleSuccessorOperator, IMultiObjectiveAnalysisOperator<TSolution>, IStochasticOperator
    36   where TSolution : class, ISolution {
     35  public class MultiObjectiveAnalyzer<TEncodedSolution> : SingleSuccessorOperator, IMultiObjectiveAnalysisOperator<TEncodedSolution>, IStochasticOperator
     36  where TEncodedSolution : class, IEncodedSolution {
    3737    public bool EnabledByDefault { get { return true; } }
    3838
    39     public ILookupParameter<IEncoding<TSolution>> EncodingParameter {
    40       get { return (ILookupParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     39    public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter {
     40      get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; }
    4141    }
    4242
     
    5353    }
    5454
    55     public Action<TSolution[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; }
     55    public Action<TEncodedSolution[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; }
    5656
    5757    [StorableConstructor]
    5858    protected MultiObjectiveAnalyzer(StorableConstructorFlag _) : base(_) { }
    59     protected MultiObjectiveAnalyzer(MultiObjectiveAnalyzer<TSolution> original, Cloner cloner) : base(original, cloner) { }
     59    protected MultiObjectiveAnalyzer(MultiObjectiveAnalyzer<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    6060    public MultiObjectiveAnalyzer() {
    6161      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    62       Parameters.Add(new LookupParameter<IEncoding<TSolution>>("Encoding", "An item that holds the problem's encoding."));
     62      Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding."));
    6363      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector."));
    6464      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to."));
     
    6666
    6767    public override IDeepCloneable Clone(Cloner cloner) {
    68       return new MultiObjectiveAnalyzer<TSolution>(this, cloner);
     68      return new MultiObjectiveAnalyzer<TEncodedSolution>(this, cloner);
    6969    }
    7070
     
    7878        scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b));
    7979
    80       var individuals = scopes.Select(s => ScopeUtil.GetSolution(s, encoding)).ToArray();
     80      var individuals = scopes.Select(s => ScopeUtil.GetEncodedSolution(s, encoding)).ToArray();
    8181      AnalyzeAction(individuals, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results, random);
    8282      return base.Apply();
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiObjectiveEvaluator.cs

    r16723 r16751  
    2121
    2222using System;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    2627using HeuristicLab.Operators;
    2728using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Optimization {
    3131  [Item("Multi-objective Evaluator", "Calls the Evaluate method of the problem definition and writes the return value into the scope.")]
    3232  [StorableType("C5605ED8-0ED2-4C7B-97A1-E7EB68A4FDBF")]
    33   public class MultiObjectiveEvaluator<TSolution> : InstrumentedOperator, IMultiObjectiveEvaluationOperator<TSolution>, IStochasticOperator
    34   where TSolution : class, ISolution {
     33  public class MultiObjectiveEvaluator<TEncodedSolution> : InstrumentedOperator, IMultiObjectiveEvaluationOperator<TEncodedSolution>, IStochasticOperator
     34  where TEncodedSolution : class, IEncodedSolution {
    3535
    3636    public ILookupParameter<IRandom> RandomParameter {
     
    3838    }
    3939
    40     public ILookupParameter<IEncoding<TSolution>> EncodingParameter {
    41       get { return (ILookupParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     40    public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter {
     41      get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; }
    4242    }
    4343
     
    4646    }
    4747
    48     public Func<TSolution, IRandom, double[]> EvaluateFunc { get; set; }
     48    public Func<TEncodedSolution, IRandom, double[]> EvaluateFunc { get; set; }
    4949
    5050    [StorableConstructor]
    5151    protected MultiObjectiveEvaluator(StorableConstructorFlag _) : base(_) { }
    52     protected MultiObjectiveEvaluator(MultiObjectiveEvaluator<TSolution> original, Cloner cloner) : base(original, cloner) { }
     52    protected MultiObjectiveEvaluator(MultiObjectiveEvaluator<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    5353    public MultiObjectiveEvaluator() {
    5454      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    55       Parameters.Add(new LookupParameter<IEncoding<TSolution>>("Encoding", "An item that holds the problem's encoding."));
     55      Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding."));
    5656      Parameters.Add(new LookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector."));
    5757    }
    5858
    5959    public override IDeepCloneable Clone(Cloner cloner) {
    60       return new MultiObjectiveEvaluator<TSolution>(this, cloner);
     60      return new MultiObjectiveEvaluator<TEncodedSolution>(this, cloner);
    6161    }
    6262
     
    6464      var random = RandomParameter.ActualValue;
    6565      var encoding = EncodingParameter.ActualValue;
    66       var solution = ScopeUtil.GetSolution(ExecutionContext.Scope, encoding);
     66      var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding);
    6767      QualitiesParameter.ActualValue = new DoubleArray(EvaluateFunc(solution, random));
    6868      return base.InstrumentedApply();
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/ScopeUtil.cs

    r13359 r16751  
    2929  public static class ScopeUtil {
    3030
    31     public static TSolution CopySolutionToScope<TSolution>(IScope scope, IEncoding<TSolution> encoding, TSolution solution)
    32       where TSolution : class,ISolution {
    33       return CopySolutionToScope(scope, encoding.Name, solution);
     31    public static TEncodedSolution CopyEncodedSolutionToScope<TEncodedSolution>(IScope scope, IEncoding<TEncodedSolution> encoding, TEncodedSolution solution)
     32      where TEncodedSolution : class, IEncodedSolution {
     33      return CopyEncodedSolutionToScope(scope, encoding.Name, solution);
    3434    }
    3535
    36     public static TSolution CopySolutionToScope<TSolution>(IScope scope, string name, TSolution solution)
    37       where TSolution : class,ISolution {
    38       var copy = (TSolution)solution.Clone();
     36    public static TEncodedSolution CopyEncodedSolutionToScope<TEncodedSolution>(IScope scope, string name, TEncodedSolution solution)
     37      where TEncodedSolution : class, IEncodedSolution {
     38      var copy = (TEncodedSolution)solution.Clone();
    3939      if (!scope.Variables.ContainsKey(name)) scope.Variables.Add(new Variable(name, copy));
    4040      else scope.Variables[name].Value = copy;
     
    4242    }
    4343
    44     public static TSolution GetSolution<TSolution>(IScope scope, IEncoding<TSolution> encoding)
    45       where TSolution : class,ISolution {
     44    public static TEncodedSolution GetEncodedSolution<TEncodedSolution>(IScope scope, IEncoding<TEncodedSolution> encoding)
     45      where TEncodedSolution : class, IEncodedSolution {
    4646      var name = encoding.Name;
    4747      if (!scope.Variables.ContainsKey(name)) throw new ArgumentException(string.Format(" {0} cannot be found in the provided scope.", name));
    48       var value = scope.Variables[name].Value as TSolution;
    49       if (value == null) throw new InvalidOperationException(string.Format("Value of {0} is null or not of type {1}.", name, typeof(TSolution).GetPrettyName()));
     48      var value = scope.Variables[name].Value as TEncodedSolution;
     49      if (value == null) throw new InvalidOperationException(string.Format("Value of {0} is null or not of type {1}.", name, typeof(TEncodedSolution).GetPrettyName()));
    5050      return value;
    5151    }
    5252
    53     public static ISolution GetSolution(IScope scope, IEncoding encoding) {
    54       return GetSolution(scope, encoding.Name);
     53    public static IEncodedSolution GetEncodedSolution(IScope scope, IEncoding encoding) {
     54      return GetEncodedSolution(scope, encoding.Name);
    5555    }
    5656
    57     public static ISolution GetSolution(IScope scope, string name) {
     57    public static IEncodedSolution GetEncodedSolution(IScope scope, string name) {
    5858      IVariable variable;
    5959      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;
     60      var solution = variable.Value as IEncodedSolution;
    6161      if (solution == null) throw new InvalidOperationException(string.Format("{0} is null or not of type ISolution.", name));
    6262      return solution;
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveAnalyzer.cs

    r16723 r16751  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    2829using HeuristicLab.Operators;
    2930using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    3131
    3232namespace HeuristicLab.Optimization {
    3333  [Item("Single-objective Analyzer", "Calls the script's Analyze method to be able to write into the results collection.")]
    3434  [StorableType("3D20F8E2-CE11-4021-A05B-CFCB02C0FD6F")]
    35   public sealed class SingleObjectiveAnalyzer<TSolution> : SingleSuccessorOperator, ISingleObjectiveAnalysisOperator<TSolution>, IAnalyzer, IStochasticOperator
    36   where TSolution : class, ISolution {
     35  public sealed class SingleObjectiveAnalyzer<TEncodedSolution> : SingleSuccessorOperator, ISingleObjectiveAnalysisOperator<TEncodedSolution>, IAnalyzer, IStochasticOperator
     36  where TEncodedSolution : class, IEncodedSolution {
    3737    public bool EnabledByDefault { get { return true; } }
    3838
    39     public ILookupParameter<IEncoding<TSolution>> EncodingParameter {
    40       get { return (ILookupParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     39    public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter {
     40      get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; }
    4141    }
    4242
     
    5353    }
    5454
    55     public Action<TSolution[], double[], ResultCollection, IRandom> AnalyzeAction { get; set; }
     55    public Action<TEncodedSolution[], double[], ResultCollection, IRandom> AnalyzeAction { get; set; }
    5656
    5757    [StorableConstructor]
    5858    private SingleObjectiveAnalyzer(StorableConstructorFlag _) : base(_) { }
    59     private SingleObjectiveAnalyzer(SingleObjectiveAnalyzer<TSolution> original, Cloner cloner) : base(original, cloner) { }
     59    private SingleObjectiveAnalyzer(SingleObjectiveAnalyzer<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    6060    public SingleObjectiveAnalyzer() {
    61       Parameters.Add(new LookupParameter<IEncoding<TSolution>>("Encoding", "An item that holds the problem's encoding."));
     61      Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding."));
    6262      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
    6363      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to."));
     
    6666
    6767    public override IDeepCloneable Clone(Cloner cloner) {
    68       return new SingleObjectiveAnalyzer<TSolution>(this, cloner);
     68      return new SingleObjectiveAnalyzer<TEncodedSolution>(this, cloner);
    6969    }
    7070
     
    7878        scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b));
    7979
    80       var individuals = scopes.Select(s => ScopeUtil.GetSolution(s, encoding)).ToArray();
     80      var individuals = scopes.Select(s => ScopeUtil.GetEncodedSolution(s, encoding)).ToArray();
    8181      AnalyzeAction(individuals, QualityParameter.ActualValue.Select(x => x.Value).ToArray(), results, random);
    8282      return base.Apply();
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveEvaluator.cs

    r16723 r16751  
    3131  [Item("Single-objective Evaluator", "Calls the script's Evaluate method to get the quality value of the parameter vector.")]
    3232  [StorableType("E8914B68-D0D7-407F-8D58-002FDF2F45CF")]
    33   public sealed class SingleObjectiveEvaluator<TSolution> : InstrumentedOperator, ISingleObjectiveEvaluationOperator<TSolution>, IStochasticOperator
    34   where TSolution : class, ISolution {
     33  public sealed class SingleObjectiveEvaluator<TEncodedSolution> : InstrumentedOperator, ISingleObjectiveEvaluationOperator<TEncodedSolution>, IStochasticOperator
     34  where TEncodedSolution : class, IEncodedSolution {
    3535
    3636    public ILookupParameter<IRandom> RandomParameter {
     
    3838    }
    3939
    40     public ILookupParameter<IEncoding<TSolution>> EncodingParameter {
    41       get { return (ILookupParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     40    public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter {
     41      get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; }
    4242    }
    4343
     
    4646    }
    4747
    48     public Func<TSolution, IRandom, double> EvaluateFunc { get; set; }
     48    public Func<TEncodedSolution, IRandom, double> EvaluateFunc { get; set; }
    4949
    5050    [StorableConstructor]
    5151    private SingleObjectiveEvaluator(StorableConstructorFlag _) : base(_) { }
    52     private SingleObjectiveEvaluator(SingleObjectiveEvaluator<TSolution> original, Cloner cloner) : base(original, cloner) { }
     52    private SingleObjectiveEvaluator(SingleObjectiveEvaluator<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    5353    public SingleObjectiveEvaluator() {
    5454      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    55       Parameters.Add(new LookupParameter<IEncoding<TSolution>>("Encoding", "An item that holds the problem's encoding."));
     55      Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding."));
    5656      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
    5757    }
    5858
    59     public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveEvaluator<TSolution>(this, cloner); }
     59    public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveEvaluator<TEncodedSolution>(this, cloner); }
    6060
    6161    public override IOperation InstrumentedApply() {
    6262      var random = RandomParameter.ActualValue;
    6363      var encoding = EncodingParameter.ActualValue;
    64       var solution = ScopeUtil.GetSolution(ExecutionContext.Scope, encoding);
     64      var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding);
    6565      QualityParameter.ActualValue = new DoubleValue(EvaluateFunc(solution, random));
    6666      return base.InstrumentedApply();
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveImprover.cs

    r16723 r16751  
    3333  [Item("Single-objective Improver", "Improves a solution by calling GetNeighbors and Evaluate of the corresponding problem definition.")]
    3434  [StorableType("7A917E09-920C-4B47-9599-67371101B35F")]
    35   public sealed class SingleObjectiveImprover<TSolution> : SingleSuccessorOperator, INeighborBasedOperator<TSolution>, IImprovementOperator, ISingleObjectiveEvaluationOperator<TSolution>, IStochasticOperator
    36     where TSolution : class, ISolution {
     35  public sealed class SingleObjectiveImprover<TEncodedSolution> : SingleSuccessorOperator, INeighborBasedOperator<TEncodedSolution>, IImprovementOperator, ISingleObjectiveEvaluationOperator<TEncodedSolution>, IStochasticOperator
     36    where TEncodedSolution : class, IEncodedSolution {
    3737    public ILookupParameter<IRandom> RandomParameter {
    3838      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    3939    }
    4040
    41     public ILookupParameter<IEncoding<TSolution>> EncodingParameter {
    42       get { return (ILookupParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     41    public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter {
     42      get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; }
    4343    }
    4444
     
    6363    }
    6464
    65     public Func<TSolution, IRandom, double> EvaluateFunc { get; set; }
    66     public Func<TSolution, IRandom, IEnumerable<TSolution>> GetNeighborsFunc { get; set; }
     65    public Func<TEncodedSolution, IRandom, double> EvaluateFunc { get; set; }
     66    public Func<TEncodedSolution, IRandom, IEnumerable<TEncodedSolution>> GetNeighborsFunc { get; set; }
    6767
    6868    [StorableConstructor]
    6969    private SingleObjectiveImprover(StorableConstructorFlag _) : base(_) { }
    70     private SingleObjectiveImprover(SingleObjectiveImprover<TSolution> original, Cloner cloner) : base(original, cloner) { }
     70    private SingleObjectiveImprover(SingleObjectiveImprover<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    7171    public SingleObjectiveImprover() {
    7272      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    73       Parameters.Add(new LookupParameter<IEncoding<TSolution>>("Encoding", "An item that holds the problem's encoding."));
     73      Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding."));
    7474      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
    7575      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Whether the problem should be minimized or maximized."));
     
    8080
    8181    public override IDeepCloneable Clone(Cloner cloner) {
    82       return new SingleObjectiveImprover<TSolution>(this, cloner);
     82      return new SingleObjectiveImprover<TEncodedSolution>(this, cloner);
    8383    }
    8484
     
    8989      var maxAttempts = ImprovementAttemptsParameter.ActualValue.Value;
    9090      var sampleSize = SampleSizeParameter.ActualValue.Value;
    91       var solution = ScopeUtil.GetSolution(ExecutionContext.Scope, encoding);
     91      var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding);
    9292      var quality = QualityParameter.ActualValue == null ? EvaluateFunc(solution, random) : QualityParameter.ActualValue.Value;
    9393
    9494      var count = 0;
    9595      for (var i = 0; i < maxAttempts; i++) {
    96         TSolution best = default(TSolution);
     96        TEncodedSolution best = default(TEncodedSolution);
    9797        var bestQuality = quality;
    9898        foreach (var neighbor in GetNeighborsFunc(solution, random).Take(sampleSize)) {
     
    111111      QualityParameter.ActualValue = new DoubleValue(quality);
    112112
    113       ScopeUtil.CopySolutionToScope(ExecutionContext.Scope, encoding, solution);
     113      ScopeUtil.CopyEncodedSolutionToScope(ExecutionContext.Scope, encoding, solution);
    114114      return base.Apply();
    115115    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveMoveEvaluator.cs

    r16723 r16751  
    2121
    2222using System;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    2627using HeuristicLab.Operators;
    2728using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Optimization {
    3131  [Item("Single-objective MoveEvaluator", "Evaluates a parameter vector that results from a move.")]
    3232  [StorableType("EE4B1EBA-50BF-40C7-B338-F4A9D9CC554E")]
    33   public class SingleObjectiveMoveEvaluator<TSolution> : SingleSuccessorOperator, ISingleObjectiveEvaluationOperator<TSolution>, ISingleObjectiveMoveEvaluator, IStochasticOperator, ISingleObjectiveMoveOperator
    34   where TSolution : class, ISolution {
     33  public class SingleObjectiveMoveEvaluator<TEncodedSolution> : SingleSuccessorOperator, ISingleObjectiveEvaluationOperator<TEncodedSolution>, ISingleObjectiveMoveEvaluator, IStochasticOperator, ISingleObjectiveMoveOperator
     34  where TEncodedSolution : class, IEncodedSolution {
    3535
    3636    public ILookupParameter<IRandom> RandomParameter {
     
    3838    }
    3939
    40     public ILookupParameter<IEncoding<TSolution>> EncodingParameter {
    41       get { return (ILookupParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     40    public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter {
     41      get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; }
    4242    }
    4343
     
    5050    }
    5151
    52     public Func<TSolution, IRandom, double> EvaluateFunc { get; set; }
     52    public Func<TEncodedSolution, IRandom, double> EvaluateFunc { get; set; }
    5353
    5454    [StorableConstructor]
    5555    protected SingleObjectiveMoveEvaluator(StorableConstructorFlag _) : base(_) { }
    56     protected SingleObjectiveMoveEvaluator(SingleObjectiveMoveEvaluator<TSolution> original, Cloner cloner) : base(original, cloner) { }
     56    protected SingleObjectiveMoveEvaluator(SingleObjectiveMoveEvaluator<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    5757    public SingleObjectiveMoveEvaluator() {
    5858      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    59       Parameters.Add(new LookupParameter<IEncoding<TSolution>>("Encoding", "An item that holds the problem's encoding."));
     59      Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding."));
    6060      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
    6161      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move."));
     
    6363
    6464    public override IDeepCloneable Clone(Cloner cloner) {
    65       return new SingleObjectiveMoveEvaluator<TSolution>(this, cloner);
     65      return new SingleObjectiveMoveEvaluator<TEncodedSolution>(this, cloner);
    6666    }
    6767
     
    6969      var random = RandomParameter.ActualValue;
    7070      var encoding = EncodingParameter.ActualValue;
    71       var individual = ScopeUtil.GetSolution(ExecutionContext.Scope, encoding);
     71      var individual = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding);
    7272      MoveQualityParameter.ActualValue = new DoubleValue(EvaluateFunc(individual, random));
    7373      return base.Apply();
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveMoveGenerator.cs

    r16723 r16751  
    3434  [Item("Single-objective MoveGenerator", "Calls the GetNeighbors method of the problem definition to obtain the moves.")]
    3535  [StorableType("CB37E7D8-EAC3-4061-9D39-20538CD1064D")]
    36   public class SingleObjectiveMoveGenerator<TSolution> : SingleSuccessorOperator, INeighborBasedOperator<TSolution>, IMultiMoveGenerator, IStochasticOperator, ISingleObjectiveMoveOperator
    37   where TSolution : class, ISolution {
     36  public class SingleObjectiveMoveGenerator<TEncodedSolution> : SingleSuccessorOperator, INeighborBasedOperator<TEncodedSolution>, IMultiMoveGenerator, IStochasticOperator, ISingleObjectiveMoveOperator
     37  where TEncodedSolution : class, IEncodedSolution {
    3838    public ILookupParameter<IRandom> RandomParameter {
    3939      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     
    4444    }
    4545
    46     public ILookupParameter<IEncoding<TSolution>> EncodingParameter {
    47       get { return (ILookupParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     46    public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter {
     47      get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; }
    4848    }
    4949
    50     public Func<TSolution, IRandom, IEnumerable<TSolution>> GetNeighborsFunc { get; set; }
     50    public Func<TEncodedSolution, IRandom, IEnumerable<TEncodedSolution>> GetNeighborsFunc { get; set; }
    5151
    5252    [StorableConstructor]
    5353    protected SingleObjectiveMoveGenerator(StorableConstructorFlag _) : base(_) { }
    54     protected SingleObjectiveMoveGenerator(SingleObjectiveMoveGenerator<TSolution> original, Cloner cloner)
     54    protected SingleObjectiveMoveGenerator(SingleObjectiveMoveGenerator<TEncodedSolution> original, Cloner cloner)
    5555      : base(original, cloner) { }
    5656    public SingleObjectiveMoveGenerator() {
    5757      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    5858      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to sample."));
    59       Parameters.Add(new LookupParameter<IEncoding<TSolution>>("Encoding", "An item that holds the problem's encoding."));
     59      Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding."));
    6060    }
    6161
    6262    public override IDeepCloneable Clone(Cloner cloner) {
    63       return new SingleObjectiveMoveGenerator<TSolution>(this, cloner);
     63      return new SingleObjectiveMoveGenerator<TEncodedSolution>(this, cloner);
    6464    }
    6565
     
    6868      var sampleSize = SampleSizeParameter.ActualValue.Value;
    6969      var encoding = EncodingParameter.ActualValue;
    70       var solution = ScopeUtil.GetSolution(ExecutionContext.Scope, encoding);
     70      var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding);
    7171      var nbhood = GetNeighborsFunc(solution, random).Take(sampleSize).ToList();
    7272
     
    7474      for (int i = 0; i < moveScopes.Length; i++) {
    7575        moveScopes[i] = new Scope(i.ToString(CultureInfo.InvariantCulture.NumberFormat));
    76         ScopeUtil.CopySolutionToScope(moveScopes[i], encoding, nbhood[i]);
     76        ScopeUtil.CopyEncodedSolutionToScope(moveScopes[i], encoding, nbhood[i]);
    7777      }
    7878      ExecutionContext.Scope.SubScopes.AddRange(moveScopes);
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveMoveMaker.cs

    r16723 r16751  
    2121
    2222using System;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    2627using HeuristicLab.Operators;
    2728using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Optimization {
    3131  [Item("Single-objective MoveMaker", "Applies a move.")]
    3232  [StorableType("C0ABF392-C825-4B98-8FB9-5749A9091FD6")]
    33   public class SingleObjectiveMoveMaker<TSolution> : InstrumentedOperator, IMoveMaker, ISingleObjectiveMoveOperator
    34   where TSolution : class, ISolution {
    35     public ILookupParameter<IEncoding<TSolution>> EncodingParameter {
    36       get { return (ILookupParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     33  public class SingleObjectiveMoveMaker<TEncodedSolution> : InstrumentedOperator, IMoveMaker, ISingleObjectiveMoveOperator
     34  where TEncodedSolution : class, IEncodedSolution {
     35    public ILookupParameter<IEncoding<TEncodedSolution>> EncodingParameter {
     36      get { return (ILookupParameter<IEncoding<TEncodedSolution>>)Parameters["Encoding"]; }
    3737    }
    3838
     
    4747    [StorableConstructor]
    4848    protected SingleObjectiveMoveMaker(StorableConstructorFlag _) : base(_) { }
    49     protected SingleObjectiveMoveMaker(SingleObjectiveMoveMaker<TSolution> original, Cloner cloner) : base(original, cloner) { }
     49    protected SingleObjectiveMoveMaker(SingleObjectiveMoveMaker<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    5050    public SingleObjectiveMoveMaker() {
    51       Parameters.Add(new LookupParameter<IEncoding<TSolution>>("Encoding", "An item that holds the problem's encoding."));
     51      Parameters.Add(new LookupParameter<IEncoding<TEncodedSolution>>("Encoding", "An item that holds the problem's encoding."));
    5252      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
    5353      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move."));
     
    5555
    5656    public override IDeepCloneable Clone(Cloner cloner) {
    57       return new SingleObjectiveMoveMaker<TSolution>(this, cloner);
     57      return new SingleObjectiveMoveMaker<TEncodedSolution>(this, cloner);
    5858    }
    5959
     
    6262
    6363      var encoding = EncodingParameter.ActualValue;
    64       var solution = ScopeUtil.GetSolution(ExecutionContext.Scope, encoding);
    65       ScopeUtil.CopySolutionToScope(ExecutionContext.Scope.Parent.Parent, encoding, solution);
     64      var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding);
     65      ScopeUtil.CopyEncodedSolutionToScope(ExecutionContext.Scope.Parent.Parent, encoding, solution);
    6666
    6767      if (QualityParameter.ActualValue == null) QualityParameter.ActualValue = new DoubleValue(MoveQualityParameter.ActualValue.Value);
Note: See TracChangeset for help on using the changeset viewer.