- Timestamp:
- 11/24/15 17:22:41 (9 years ago)
- 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 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 }
Note: See TracChangeset
for help on using the changeset viewer.