- Timestamp:
- 11/21/19 17:58:32 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs
r17320 r17363 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using System.Threading; 25 26 using HeuristicLab.Core; … … 64 65 } 65 66 public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 66 public abstract void Analyze(TEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random); 67 public abstract IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random); 67 68 public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { 69 Evaluate(solutionContext, random, CancellationToken.None); 70 } 71 public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) { 72 double quality = Evaluate(solutionContext.EncodedSolution, random, cancellationToken); 73 solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality); 74 } 75 76 public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { } 77 public virtual void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) { 78 var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray(); 79 var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray(); 80 Analyze(solutions, qualities, results, random); 81 } 82 83 public virtual IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solutions, IRandom random) { 84 return Enumerable.Empty<TEncodedSolution>(); 85 } 86 public virtual IEnumerable<ISingleObjectiveSolutionContext<TEncodedSolution>> GetNeighbors(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { 87 return GetNeighbors(solutionContext.EncodedSolution, random).Select(n => new SingleObjectiveSolutionContext<TEncodedSolution>(n)); 88 } 68 89 69 90 public bool IsBetter(double quality, double bestQuality) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
r17320 r17363 59 59 } 60 60 61 void ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { 62 CompiledProblemDefinition.Evaluate(solutionContext, random, CancellationToken.None); 63 } 64 void ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) { 65 double quality = CompiledProblemDefinition.Evaluate(solutionContext.EncodedSolution, random, cancellationToken); 66 solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality); 67 } 68 61 69 void ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Analyze(TEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) { 62 70 CompiledProblemDefinition.Analyze(individuals, qualities, results, random); 63 71 } 72 void ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) { 73 CompiledProblemDefinition.Analyze(solutionContexts, results, random); 74 } 75 76 64 77 IEnumerable<TEncodedSolution> ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.GetNeighbors(TEncodedSolution individual, IRandom random) { 65 78 return CompiledProblemDefinition.GetNeighbors(individual, random); 79 } 80 IEnumerable<ISingleObjectiveSolutionContext<TEncodedSolution>> ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.GetNeighbors(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { 81 return CompiledProblemDefinition.GetNeighbors(solutionContext, random); 66 82 } 67 83 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r17320 r17363 108 108 } 109 109 110 public override void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) { 111 ProblemDefinition.Evaluate(solutionContext, random, cancellationToken); 112 } 110 113 public override double Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) { 111 114 return ProblemDefinition.Evaluate(individual, random, cancellationToken); 112 115 } 113 116 117 public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) { 118 ProblemDefinition.Analyze(solutionContexts, results, random); 119 } 114 120 public override void Analyze(TEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) { 115 121 ProblemDefinition.Analyze(individuals, qualities, results, random); 122 } 123 124 public override IEnumerable<ISingleObjectiveSolutionContext<TEncodedSolution>> GetNeighbors(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { 125 return ProblemDefinition.GetNeighbors(solutionContext, random); 116 126 } 117 127 public override IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random) {
Note: See TracChangeset
for help on using the changeset viewer.