Changeset 13372
- Timestamp:
- 11/24/15 17:22:41 (9 years ago)
- Location:
- branches/ProblemRefactoring
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageCreator.cs
r12285 r13372 25 25 26 26 namespace HeuristicLab.Encodings.LinearLinkageEncoding { 27 public interface ILinearLinkageCreator : ISolutionCreator , ILinearLinkageOperator {27 public interface ILinearLinkageCreator : ISolutionCreator<LinearLinkage>, ILinearLinkageOperator { 28 28 IValueLookupParameter<IntValue> LengthParameter { get; } 29 29 ILookupParameter<LinearLinkage> LLEParameter { get; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkage.cs
r12701 r13372 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 … … 31 32 [Item("LinearLinkage", "Represents an LLE grouping of items.")] 32 33 [StorableClass] 33 public sealed class LinearLinkage : IntArray {34 public sealed class LinearLinkage : IntArray, ISolution { 34 35 35 36 [StorableConstructor] -
branches/ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkageEncoding.cs
r12650 r13372 34 34 [Item("Linear Linkage Encoding", "Describes a linear linkage (LLE) encoding.")] 35 35 [StorableClass] 36 public sealed class LinearLinkageEncoding : Encoding< ILinearLinkageCreator> {36 public sealed class LinearLinkageEncoding : Encoding<LinearLinkage> { 37 37 #region encoding parameters 38 38 [Storable] … … 166 166 } 167 167 #endregion 168 }169 168 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 }178 169 } 179 170 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTree.cs
r12012 r13372 23 23 using System.Collections.Generic; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Optimization; 26 25 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 public interface ISymbolicExpressionTree : IItem {28 public interface ISymbolicExpressionTree : IItem, ISolution { 27 29 ISymbolicExpressionTreeNode Root { get; set; } 28 30 int Length { get; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCreator.cs
r12422 r13372 27 27 /// Interface for operators that create symbolic expression trees. 28 28 /// </summary> 29 public interface ISymbolicExpressionTreeCreator : ISolutionCreator , ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator {29 public interface ISymbolicExpressionTreeCreator : ISolutionCreator<ISymbolicExpressionTree>, ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator { 30 30 ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth); 31 31 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeEncoding.cs
r12422 r13372 36 36 [Item("SymbolicExpressionTreeEncoding", "Describes a symbolic expression tree encoding.")] 37 37 [StorableClass] 38 public sealed class SymbolicExpressionTreeEncoding : Encoding<ISymbolicExpressionTree Creator> {38 public sealed class SymbolicExpressionTreeEncoding : Encoding<ISymbolicExpressionTree> { 39 39 #region Encoding Parameters 40 40 [Storable] … … 355 355 #endregion 356 356 } 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 }368 357 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs
r13336 r13372 32 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 33 33 [StorableClass] 34 public abstract class SymbolicExpressionTreeProblem : SingleObjectiveProblem<SymbolicExpressionTreeEncoding > {34 public abstract class SymbolicExpressionTreeProblem : SingleObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { 35 35 36 36 // persistence … … 48 48 protected SymbolicExpressionTreeProblem() : base() { } 49 49 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, 60 51 IRandom random) { 61 52 if (!results.ContainsKey("Best Solution Quality")) { … … 76 67 } 77 68 } 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 }82 69 } 83 70 } -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/HeuristicLab.Problems.ExternalEvaluation.GP-3.5.csproj
r11961 r13372 169 169 <Private>False</Private> 170 170 </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> 171 176 <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj"> 172 177 <Project>{102bc7d3-0ef9-439c-8f6d-96ff0fdb8e1b}</Project> -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblem.cs
r13336 r13372 40 40 // BackwardsCompatibility3.3 41 41 // Rename class to SingleObjectiveExternalEvaluationProblem 42 public class ExternalEvaluationProblem : SingleObjectiveProblem<IEncoding >, IExternalEvaluationProblem {42 public class ExternalEvaluationProblem : SingleObjectiveProblem<IEncoding<ISolution>, ISolution>, IExternalEvaluationProblem { 43 43 44 44 public static new Image StaticItemImage { … … 102 102 } 103 103 104 public override double Evaluate(I ndividualindividual, IRandom random) {104 public override double Evaluate(ISolution individual, IRandom random) { 105 105 var qualityMessage = Evaluate(BuildSolutionMessage(individual)); 106 106 if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_)) … … 114 114 } 115 115 116 public override void Analyze(I ndividual[] individuals, double[] qualities, ResultCollection results, IRandom random) {116 public override void Analyze(ISolution[] individuals, double[] qualities, ResultCollection results, IRandom random) { 117 117 OptimizationSupport.Analyze(individuals, qualities, results, random); 118 118 } 119 119 120 public override IEnumerable<I ndividual> GetNeighbors(Individualindividual, IRandom random) {120 public override IEnumerable<ISolution> GetNeighbors(ISolution individual, IRandom random) { 121 121 return OptimizationSupport.GetNeighbors(individual, random); 122 122 } … … 146 146 try { 147 147 return client.Evaluate(message, GetQualityMessageExtensions()); 148 } finally { 148 } 149 finally { 149 150 lock (clientLock) { 150 151 activeClients.Remove(client); … … 154 155 } 155 156 156 private SolutionMessage BuildSolutionMessage(I ndividual individual, int solutionId = 0) {157 private SolutionMessage BuildSolutionMessage(ISolution solution, int solutionId = 0) { 157 158 lock (clientLock) { 158 159 SolutionMessage.Builder protobufBuilder = SolutionMessage.CreateBuilder(); 159 160 protobufBuilder.SolutionId = solutionId; 160 161 var scope = new Scope(); 161 individual.CopyToScope(scope);162 ScopeUtil.CopySolutionToScope(scope, Encoding, solution); 162 163 foreach (var variable in scope.Variables) { 163 164 try { 164 165 MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder); 165 } catch (ArgumentException ex) { 166 } 167 catch (ArgumentException ex) { 166 168 throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex); 167 169 } -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/IMultiObjectiveOptimizationSupport.cs
r13183 r13372 25 25 namespace HeuristicLab.Problems.ExternalEvaluation { 26 26 public interface IMultiObjectiveOptimizationSupport { 27 void Analyze(I ndividual[] individuals, double[][] qualities, ResultCollection results, IRandom random);27 void Analyze(ISolution[] individuals, double[][] qualities, ResultCollection results, IRandom random); 28 28 } 29 29 } -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/ISingleObjectiveOptimizationSupport.cs
r11961 r13372 26 26 namespace HeuristicLab.Problems.ExternalEvaluation { 27 27 public interface ISingleObjectiveOptimizationSupport { 28 void Analyze(I ndividual[] individuals, double[] qualities, ResultCollection results, IRandom random);29 IEnumerable<I ndividual> GetNeighbors(Individualindividual, IRandom random);28 void Analyze(ISolution[] individuals, double[] qualities, ResultCollection results, IRandom random); 29 IEnumerable<ISolution> GetNeighbors(ISolution individual, IRandom random); 30 30 } 31 31 } -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/MultiObjectiveExternalEvaluationProblem.cs
r13336 r13372 37 37 [Creatable(CreatableAttribute.Categories.ExternalEvaluationProblems, Priority = 200)] 38 38 [StorableClass] 39 public class MultiObjectiveExternalEvaluationProblem : MultiObjectiveProblem<IEncoding >, IExternalEvaluationProblem {39 public class MultiObjectiveExternalEvaluationProblem : MultiObjectiveProblem<IEncoding<ISolution>, ISolution>, IExternalEvaluationProblem { 40 40 41 41 public static new Image StaticItemImage { … … 99 99 } 100 100 101 public override double[] Evaluate(I ndividualindividual, IRandom random) {101 public override double[] Evaluate(ISolution individual, IRandom random) { 102 102 var qualityMessage = Evaluate(BuildSolutionMessage(individual)); 103 103 if (!qualityMessage.HasExtension(MultiObjectiveQualityMessage.QualityMessage_)) … … 111 111 } 112 112 113 public override void Analyze(I ndividual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {113 public override void Analyze(ISolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 114 114 OptimizationSupport.Analyze(individuals, qualities, results, random); 115 115 } … … 140 140 try { 141 141 return client.Evaluate(message, GetQualityMessageExtensions()); 142 } finally { 142 } 143 finally { 143 144 lock (clientLock) { 144 145 activeClients.Remove(client); … … 148 149 } 149 150 150 private SolutionMessage BuildSolutionMessage(I ndividual individual, int solutionId = 0) {151 private SolutionMessage BuildSolutionMessage(ISolution solution, int solutionId = 0) { 151 152 lock (clientLock) { 152 153 SolutionMessage.Builder protobufBuilder = SolutionMessage.CreateBuilder(); 153 154 protobufBuilder.SolutionId = solutionId; 154 155 var scope = new Scope(); 155 individual.CopyToScope(scope);156 ScopeUtil.CopySolutionToScope(scope, Encoding, solution); 156 157 foreach (var variable in scope.Variables) { 157 158 try { 158 159 MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder); 159 } catch (ArgumentException ex) { 160 } 161 catch (ArgumentException ex) { 160 162 throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex); 161 163 } -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledMultiObjectiveOptimizationSupport.cs
r13257 r13372 5 5 public class CompiledMultiObjectiveOptimizationSupport : CompiledOptimizationSupport, IMultiObjectiveOptimizationSupport { 6 6 7 public void Analyze(I ndividual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {7 public void Analyze(ISolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 8 8 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 9 9 // Write or update results given the range of vectors and resulting qualities -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledSingleObjectiveOptimizationSupport.cs
r13257 r13372 6 6 public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport { 7 7 8 public void Analyze(I ndividual[] individuals, double[] qualities, ResultCollection results, IRandom random) {8 public void Analyze(ISolution[] individuals, double[] qualities, ResultCollection results, IRandom random) { 9 9 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 10 10 // Write or update results given the range of vectors and resulting qualities … … 17 17 } 18 18 19 public IEnumerable<I ndividual> GetNeighbors(Individualindividual, IRandom random) {19 public IEnumerable<ISolution> GetNeighbors(ISolution individual, IRandom random) { 20 20 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 21 21 // Create new vectors, based on the given one that represent small changes … … 24 24 // Algorithm will draw only a finite amount of samples 25 25 // Change to a for-loop to return a concrete amount of neighbors 26 var neighbor = individual.Copy();26 var neighbor = (ISolution)individual.Clone(); 27 27 // For instance, perform a single bit-flip in a binary parameter 28 28 //var bIndex = random.Next(neighbor.BinaryVector("b").Length); -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs
r13218 r13372 39 39 } 40 40 41 void IMultiObjectiveOptimizationSupport.Analyze(I ndividual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {41 void IMultiObjectiveOptimizationSupport.Analyze(ISolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 42 42 CompiledInstance.Analyze(individuals, qualities, results, random); 43 43 } -
branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs
r13218 r13372 40 40 } 41 41 42 void ISingleObjectiveOptimizationSupport.Analyze(I ndividual[] individuals, double[] qualities, ResultCollection results, IRandom random) {42 void ISingleObjectiveOptimizationSupport.Analyze(ISolution[] individuals, double[] qualities, ResultCollection results, IRandom random) { 43 43 CompiledInstance.Analyze(individuals, qualities, results, random); 44 44 } 45 45 46 IEnumerable<I ndividual> ISingleObjectiveOptimizationSupport.GetNeighbors(Individualindividual, IRandom random) {46 IEnumerable<ISolution> ISingleObjectiveOptimizationSupport.GetNeighbors(ISolution individual, IRandom random) { 47 47 return CompiledInstance.GetNeighbors(individual, random); 48 48 } -
branches/ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming.Views/3.3/HeuristicLab.Problems.GeneticProgramming.Views-3.3.csproj
r13210 r13372 220 220 <Private>False</Private> 221 221 </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> 222 227 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 223 228 <Project>{94186a6a-5176-4402-ae83-886557b53cca}</Project> -
branches/ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs
r13336 r13372 38 38 [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 170)] 39 39 [StorableClass] 40 public sealed class GEArtificialAntProblem : SingleObjectiveProblem<IntegerVectorEncoding>, IStorableContent { 41 public string Filename { get; set; } 40 public sealed class GEArtificialAntProblem : SingleObjectiveProblem<IntegerVectorEncoding, IntegerVector> { 42 41 43 42 #region Parameter Properties … … 99 98 100 99 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) { 104 101 var bounds = Encoding.Bounds; 105 102 var len = Encoding.Length; … … 113 110 fastRand = new FastRandom(random.Next()); 114 111 } 115 var tree = mapper.Map(fastRand, bounds, len, grammar, vector);112 var tree = mapper.Map(fastRand, bounds, len, grammar, solution); 116 113 117 114 Interpreter interpreter = new Interpreter(tree, World, MaxTimeSteps); … … 121 118 } 122 119 123 public override void Analyze(In dividual[] individuals, double[] qualities, ResultCollection results, IRandom random) {120 public override void Analyze(IntegerVector[] solutions, double[] qualities, ResultCollection results, IRandom random) { 124 121 var bounds = Encoding.Bounds; 125 122 var len = Encoding.Length; … … 127 124 var mapper = GenotypeToPhenotypeMapperParameter.Value; 128 125 129 var trees = individuals130 .Select(ind => mapper.Map(random, bounds, len, grammar, ind .IntegerVector()))126 var trees = solutions 127 .Select(ind => mapper.Map(random, bounds, len, grammar, ind)) 131 128 .ToArray(); 132 129 -
branches/ProblemRefactoring/HeuristicLab.Problems.LinearAssignment.Views/3.3/HeuristicLab.Problems.LinearAssignment.Views-3.3.csproj
r11623 r13372 181 181 <Private>False</Private> 182 182 </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> 183 188 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 184 189 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
Note: See TracChangeset
for help on using the changeset viewer.