Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13372 for branches


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

#2521: Fixed all problems.

Location:
branches/ProblemRefactoring
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageCreator.cs

    r12285 r13372  
    2525
    2626namespace HeuristicLab.Encodings.LinearLinkageEncoding {
    27   public interface ILinearLinkageCreator : ISolutionCreator, ILinearLinkageOperator {
     27  public interface ILinearLinkageCreator : ISolutionCreator<LinearLinkage>, ILinearLinkageOperator {
    2828    IValueLookupParameter<IntValue> LengthParameter { get; }
    2929    ILookupParameter<LinearLinkage> LLEParameter { get; }
  • branches/ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkage.cs

    r12701 r13372  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Optimization;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930
     
    3132  [Item("LinearLinkage", "Represents an LLE grouping of items.")]
    3233  [StorableClass]
    33   public sealed class LinearLinkage : IntArray {
     34  public sealed class LinearLinkage : IntArray, ISolution {
    3435
    3536    [StorableConstructor]
  • branches/ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkageEncoding.cs

    r12650 r13372  
    3434  [Item("Linear Linkage Encoding", "Describes a linear linkage (LLE) encoding.")]
    3535  [StorableClass]
    36   public sealed class LinearLinkageEncoding : Encoding<ILinearLinkageCreator> {
     36  public sealed class LinearLinkageEncoding : Encoding<LinearLinkage> {
    3737    #region encoding parameters
    3838    [Storable]
     
    166166    }
    167167    #endregion
    168   }
    169168
    170   public static class IndividualExtensionMethods {
    171     public static LinearLinkage LinearLinkage(this Individual individual) {
    172       var encoding = individual.GetEncoding<LinearLinkageEncoding>();
    173       return individual.LinearLinkage(encoding.Name);
    174     }
    175     public static LinearLinkage LinearLinkage(this Individual individual, string name) {
    176       return (LinearLinkage)individual[name];
    177     }
    178169  }
    179170}
  • branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTree.cs

    r12012 r13372  
    2323using System.Collections.Generic;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Optimization;
     26
    2527namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    26   public interface ISymbolicExpressionTree : IItem {
     28  public interface ISymbolicExpressionTree : IItem, ISolution {
    2729    ISymbolicExpressionTreeNode Root { get; set; }
    2830    int Length { get; }
  • branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCreator.cs

    r12422 r13372  
    2727  /// Interface for operators that create symbolic expression trees.
    2828  /// </summary>
    29   public interface ISymbolicExpressionTreeCreator : ISolutionCreator, ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator {
     29  public interface ISymbolicExpressionTreeCreator : ISolutionCreator<ISymbolicExpressionTree>, ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator {
    3030    ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
    3131  }
  • branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeEncoding.cs

    r12422 r13372  
    3636  [Item("SymbolicExpressionTreeEncoding", "Describes a symbolic expression tree encoding.")]
    3737  [StorableClass]
    38   public sealed class SymbolicExpressionTreeEncoding : Encoding<ISymbolicExpressionTreeCreator> {
     38  public sealed class SymbolicExpressionTreeEncoding : Encoding<ISymbolicExpressionTree> {
    3939    #region Encoding Parameters
    4040    [Storable]
     
    355355    #endregion
    356356  }
    357 
    358   public static class IndividualExtensionMethods {
    359     public static ISymbolicExpressionTree SymbolicExpressionTree(this Individual individual) {
    360       var encoding = individual.GetEncoding<SymbolicExpressionTreeEncoding>();
    361       return individual.SymbolicExpressionTree(encoding.Name);
    362     }
    363 
    364     public static ISymbolicExpressionTree SymbolicExpressionTree(this Individual individual, string name) {
    365       return (ISymbolicExpressionTree)individual[name];
    366     }
    367   }
    368357}
  • branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs

    r13336 r13372  
    3232namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    3333  [StorableClass]
    34   public abstract class SymbolicExpressionTreeProblem : SingleObjectiveProblem<SymbolicExpressionTreeEncoding> {
     34  public abstract class SymbolicExpressionTreeProblem : SingleObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> {
    3535
    3636    // persistence
     
    4848    protected SymbolicExpressionTreeProblem() : base() { }
    4949
    50     public virtual bool IsBetter(double quality, double bestQuality) {
    51       return (Maximization && quality > bestQuality || !Maximization && quality < bestQuality);
    52     }
    53 
    54     public abstract double Evaluate(ISymbolicExpressionTree tree, IRandom random);
    55     public sealed override double Evaluate(Individual individual, IRandom random) {
    56       return Evaluate(individual.SymbolicExpressionTree(), random);
    57     }
    58 
    59     public virtual void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results,
     50    public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results,
    6051      IRandom random) {
    6152      if (!results.ContainsKey("Best Solution Quality")) {
     
    7667      }
    7768    }
    78 
    79     public sealed override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    80       Analyze(individuals.Select(ind => ind.SymbolicExpressionTree()).ToArray(), qualities, results, random);
    81     }
    8269  }
    8370}
  • branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/HeuristicLab.Problems.ExternalEvaluation.GP-3.5.csproj

    r11961 r13372  
    169169      <Private>False</Private>
    170170    </ProjectReference>
     171    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
     172      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
     173      <Name>HeuristicLab.Optimization-3.3</Name>
     174      <Private>False</Private>
     175    </ProjectReference>
    171176    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
    172177      <Project>{102bc7d3-0ef9-439c-8f6d-96ff0fdb8e1b}</Project>
  • 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    }
  • branches/ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming.Views/3.3/HeuristicLab.Problems.GeneticProgramming.Views-3.3.csproj

    r13210 r13372  
    220220      <Private>False</Private>
    221221    </ProjectReference>
     222    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
     223      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
     224      <Name>HeuristicLab.Optimization-3.3</Name>
     225      <Private>False</Private>
     226    </ProjectReference>
    222227    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    223228      <Project>{94186a6a-5176-4402-ae83-886557b53cca}</Project>
  • branches/ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs

    r13336 r13372  
    3838  [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 170)]
    3939  [StorableClass]
    40   public sealed class GEArtificialAntProblem : SingleObjectiveProblem<IntegerVectorEncoding>, IStorableContent {
    41     public string Filename { get; set; }
     40  public sealed class GEArtificialAntProblem : SingleObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
    4241
    4342    #region Parameter Properties
     
    9998
    10099    private readonly object syncRoot = new object();
    101     public override double Evaluate(Individual individual, IRandom random) {
    102       var vector = individual.IntegerVector();
    103 
     100    public override double Evaluate(IntegerVector solution, IRandom random) {
    104101      var bounds = Encoding.Bounds;
    105102      var len = Encoding.Length;
     
    113110        fastRand = new FastRandom(random.Next());
    114111      }
    115       var tree = mapper.Map(fastRand, bounds, len, grammar, vector);
     112      var tree = mapper.Map(fastRand, bounds, len, grammar, solution);
    116113
    117114      Interpreter interpreter = new Interpreter(tree, World, MaxTimeSteps);
     
    121118    }
    122119
    123     public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     120    public override void Analyze(IntegerVector[] solutions, double[] qualities, ResultCollection results, IRandom random) {
    124121      var bounds = Encoding.Bounds;
    125122      var len = Encoding.Length;
     
    127124      var mapper = GenotypeToPhenotypeMapperParameter.Value;
    128125
    129       var trees = individuals
    130         .Select(ind => mapper.Map(random, bounds, len, grammar, ind.IntegerVector()))
     126      var trees = solutions
     127        .Select(ind => mapper.Map(random, bounds, len, grammar, ind))
    131128        .ToArray();
    132129
  • branches/ProblemRefactoring/HeuristicLab.Problems.LinearAssignment.Views/3.3/HeuristicLab.Problems.LinearAssignment.Views-3.3.csproj

    r11623 r13372  
    181181      <Private>False</Private>
    182182    </ProjectReference>
     183    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
     184      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
     185      <Name>HeuristicLab.Optimization-3.3</Name>
     186      <Private>False</Private>
     187    </ProjectReference>
    183188    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    184189      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
Note: See TracChangeset for help on using the changeset viewer.