Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/15 17:22:41 (9 years ago)
Author:
mkommend
Message:

#2521: Fixed all problems.

Location:
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblem.cs

    r13336 r13372  
    4040  // BackwardsCompatibility3.3
    4141  // Rename class to SingleObjectiveExternalEvaluationProblem
    42   public class ExternalEvaluationProblem : SingleObjectiveProblem<IEncoding>, IExternalEvaluationProblem {
     42  public class ExternalEvaluationProblem : SingleObjectiveProblem<IEncoding<ISolution>, ISolution>, IExternalEvaluationProblem {
    4343
    4444    public static new Image StaticItemImage {
     
    102102    }
    103103
    104     public override double Evaluate(Individual individual, IRandom random) {
     104    public override double Evaluate(ISolution individual, IRandom random) {
    105105      var qualityMessage = Evaluate(BuildSolutionMessage(individual));
    106106      if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_))
     
    114114    }
    115115
    116     public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     116    public override void Analyze(ISolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    117117      OptimizationSupport.Analyze(individuals, qualities, results, random);
    118118    }
    119119
    120     public override IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
     120    public override IEnumerable<ISolution> GetNeighbors(ISolution individual, IRandom random) {
    121121      return OptimizationSupport.GetNeighbors(individual, random);
    122122    }
     
    146146      try {
    147147        return client.Evaluate(message, GetQualityMessageExtensions());
    148       } finally {
     148      }
     149      finally {
    149150        lock (clientLock) {
    150151          activeClients.Remove(client);
     
    154155    }
    155156
    156     private SolutionMessage BuildSolutionMessage(Individual individual, int solutionId = 0) {
     157    private SolutionMessage BuildSolutionMessage(ISolution solution, int solutionId = 0) {
    157158      lock (clientLock) {
    158159        SolutionMessage.Builder protobufBuilder = SolutionMessage.CreateBuilder();
    159160        protobufBuilder.SolutionId = solutionId;
    160161        var scope = new Scope();
    161         individual.CopyToScope(scope);
     162        ScopeUtil.CopySolutionToScope(scope, Encoding, solution);
    162163        foreach (var variable in scope.Variables) {
    163164          try {
    164165            MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder);
    165           } catch (ArgumentException ex) {
     166          }
     167          catch (ArgumentException ex) {
    166168            throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex);
    167169          }
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/IMultiObjectiveOptimizationSupport.cs

    r13183 r13372  
    2525namespace HeuristicLab.Problems.ExternalEvaluation {
    2626  public interface IMultiObjectiveOptimizationSupport {
    27     void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random);
     27    void Analyze(ISolution[] individuals, double[][] qualities, ResultCollection results, IRandom random);
    2828  }
    2929}
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/ISingleObjectiveOptimizationSupport.cs

    r11961 r13372  
    2626namespace HeuristicLab.Problems.ExternalEvaluation {
    2727  public interface ISingleObjectiveOptimizationSupport {
    28     void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random);
    29     IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random);
     28    void Analyze(ISolution[] individuals, double[] qualities, ResultCollection results, IRandom random);
     29    IEnumerable<ISolution> GetNeighbors(ISolution individual, IRandom random);
    3030  }
    3131}
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/MultiObjectiveExternalEvaluationProblem.cs

    r13336 r13372  
    3737  [Creatable(CreatableAttribute.Categories.ExternalEvaluationProblems, Priority = 200)]
    3838  [StorableClass]
    39   public class MultiObjectiveExternalEvaluationProblem : MultiObjectiveProblem<IEncoding>, IExternalEvaluationProblem {
     39  public class MultiObjectiveExternalEvaluationProblem : MultiObjectiveProblem<IEncoding<ISolution>, ISolution>, IExternalEvaluationProblem {
    4040
    4141    public static new Image StaticItemImage {
     
    9999    }
    100100
    101     public override double[] Evaluate(Individual individual, IRandom random) {
     101    public override double[] Evaluate(ISolution individual, IRandom random) {
    102102      var qualityMessage = Evaluate(BuildSolutionMessage(individual));
    103103      if (!qualityMessage.HasExtension(MultiObjectiveQualityMessage.QualityMessage_))
     
    111111    }
    112112
    113     public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
     113    public override void Analyze(ISolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
    114114      OptimizationSupport.Analyze(individuals, qualities, results, random);
    115115    }
     
    140140      try {
    141141        return client.Evaluate(message, GetQualityMessageExtensions());
    142       } finally {
     142      }
     143      finally {
    143144        lock (clientLock) {
    144145          activeClients.Remove(client);
     
    148149    }
    149150
    150     private SolutionMessage BuildSolutionMessage(Individual individual, int solutionId = 0) {
     151    private SolutionMessage BuildSolutionMessage(ISolution solution, int solutionId = 0) {
    151152      lock (clientLock) {
    152153        SolutionMessage.Builder protobufBuilder = SolutionMessage.CreateBuilder();
    153154        protobufBuilder.SolutionId = solutionId;
    154155        var scope = new Scope();
    155         individual.CopyToScope(scope);
     156        ScopeUtil.CopySolutionToScope(scope, Encoding, solution);
    156157        foreach (var variable in scope.Variables) {
    157158          try {
    158159            MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder);
    159           } catch (ArgumentException ex) {
     160          }
     161          catch (ArgumentException ex) {
    160162            throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex);
    161163          }
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledMultiObjectiveOptimizationSupport.cs

    r13257 r13372  
    55  public class CompiledMultiObjectiveOptimizationSupport : CompiledOptimizationSupport, IMultiObjectiveOptimizationSupport {
    66
    7     public void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
     7    public void Analyze(ISolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
    88      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    99      // Write or update results given the range of vectors and resulting qualities
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledSingleObjectiveOptimizationSupport.cs

    r13257 r13372  
    66  public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport {
    77
    8     public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     8    public void Analyze(ISolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    99      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    1010      // Write or update results given the range of vectors and resulting qualities
     
    1717    }
    1818
    19     public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
     19    public IEnumerable<ISolution> GetNeighbors(ISolution individual, IRandom random) {
    2020      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    2121      // Create new vectors, based on the given one that represent small changes
     
    2424        // Algorithm will draw only a finite amount of samples
    2525        // Change to a for-loop to return a concrete amount of neighbors
    26         var neighbor = individual.Copy();
     26        var neighbor = (ISolution)individual.Clone();
    2727        // For instance, perform a single bit-flip in a binary parameter
    2828        //var bIndex = random.Next(neighbor.BinaryVector("b").Length);
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs

    r13218 r13372  
    3939    }
    4040
    41     void IMultiObjectiveOptimizationSupport.Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
     41    void IMultiObjectiveOptimizationSupport.Analyze(ISolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
    4242      CompiledInstance.Analyze(individuals, qualities, results, random);
    4343    }
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs

    r13218 r13372  
    4040    }
    4141
    42     void ISingleObjectiveOptimizationSupport.Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     42    void ISingleObjectiveOptimizationSupport.Analyze(ISolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    4343      CompiledInstance.Analyze(individuals, qualities, results, random);
    4444    }
    4545
    46     IEnumerable<Individual> ISingleObjectiveOptimizationSupport.GetNeighbors(Individual individual, IRandom random) {
     46    IEnumerable<ISolution> ISingleObjectiveOptimizationSupport.GetNeighbors(ISolution individual, IRandom random) {
    4747      return CompiledInstance.GetNeighbors(individual, random);
    4848    }
Note: See TracChangeset for help on using the changeset viewer.