Changeset 17366 for branches/2521_ProblemRefactoring
- Timestamp:
- 11/22/19 15:54:31 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/internal/ISingleObjectiveEvaluationOperator.cs
r17363 r17366 21 21 22 22 using System; 23 using System.Threading; 23 24 using HEAL.Attic; 24 25 using HeuristicLab.Core; … … 28 29 internal interface ISingleObjectiveEvaluationOperator<TEncodedSolution> : ISingleObjectiveEvaluator, IEncodingOperator<TEncodedSolution> 29 30 where TEncodedSolution : class, IEncodedSolution { 30 Action<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom > Evaluate { get; set; }31 Action<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom, CancellationToken> Evaluate { get; set; } 31 32 } 32 33 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveEvaluator.cs
r17363 r17366 21 21 22 22 using System; 23 using System.Threading; 23 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; … … 46 47 } 47 48 48 public Action<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom > Evaluate { get; set; }49 public Action<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom, CancellationToken> Evaluate { get; set; } 49 50 50 51 [StorableConstructor] … … 65 66 var solutionContext = new SingleObjectiveSolutionContextScope<TEncodedSolution>(ExecutionContext.Scope, solution); 66 67 67 Evaluate(solutionContext, random );68 Evaluate(solutionContext, random, CancellationToken.None); 68 69 var qualityValue = solutionContext.EvaluationResult.Quality; 69 70 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveImprover.cs
r17363 r17366 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HEAL.Attic; 26 27 using HeuristicLab.Common; … … 63 64 } 64 65 65 public Action<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom > Evaluate { get; set; }66 public Action<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom, CancellationToken> Evaluate { get; set; } 66 67 public Func<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom, IEnumerable<ISingleObjectiveSolutionContext<TEncodedSolution>>> GetNeighbors { get; set; } 67 68 … … 94 95 double quality; 95 96 if (QualityParameter.ActualValue == null) { 96 if (!solutionContext.IsEvaluated) Evaluate(solutionContext, random );97 if (!solutionContext.IsEvaluated) Evaluate(solutionContext, random, CancellationToken.None); 97 98 98 99 quality = solutionContext.EvaluationResult.Quality; … … 104 105 var bestQuality = quality; 105 106 foreach (var neighbor in GetNeighbors(solutionContext, random).Take(sampleSize)) { 106 Evaluate(neighbor, random );107 Evaluate(neighbor, random, CancellationToken); 107 108 var q = neighbor.EvaluationResult.Quality; 108 109 count++; -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveMoveEvaluator.cs
r17363 r17366 21 21 22 22 using System; 23 using System.Threading; 23 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; … … 50 51 } 51 52 52 public Action<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom > Evaluate { get; set; }53 public Action<ISingleObjectiveSolutionContext<TEncodedSolution>, IRandom, CancellationToken> Evaluate { get; set; } 53 54 54 55 [StorableConstructor] … … 72 73 var solutionContext = new SingleObjectiveSolutionContextScope<TEncodedSolution>(ExecutionContext.Scope, solution); 73 74 74 Evaluate(solutionContext, random );75 Evaluate(solutionContext, random, CancellationToken.None); 75 76 var qualityValue = solutionContext.EvaluationResult.Quality; 76 77 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
r17363 r17366 113 113 } 114 114 115 public virtualdouble Evaluate(TEncodedSolution solution, IRandom random) {115 public double Evaluate(TEncodedSolution solution, IRandom random) { 116 116 return Evaluate(solution, random, CancellationToken.None); 117 117 } 118 118 public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 119 119 120 public v irtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) {120 public void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { 121 121 Evaluate(solutionContext, random, CancellationToken.None); 122 122 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SolutionContext.cs
r17363 r17366 63 63 } 64 64 65 public v oid SetAdditionalData(string identifier, object o) {65 public virtual void SetAdditionalData(string identifier, object o) { 66 66 data[identifier] = o; 67 67 } 68 public object GetAdditionalData(string identifier) {68 public virtual object GetAdditionalData(string identifier) { 69 69 return data[identifier]; 70 70 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
r17363 r17366 63 63 } 64 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); 65 CompiledProblemDefinition.Evaluate(solutionContext, random, cancellationToken); 67 66 } 68 67 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/SingleObjectiveCombinedEncodingProblem_Template.cs
r16801 r17366 2 2 using System.Linq; 3 3 using System.Collections.Generic; 4 using System.Threading; 4 5 using HeuristicLab.Common; 5 6 using HeuristicLab.Core; … … 28 29 } 29 30 30 public override double Evaluate(CombinedSolution solution, IRandom random ) {31 public override double Evaluate(CombinedSolution solution, IRandom random, CancellationToken cancellationToken) { 31 32 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 32 33 var quality = 0.0; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/SingleObjectiveProblem_Template.cs
r13373 r17366 2 2 using System.Linq; 3 3 using System.Collections.Generic; 4 using System.Threading; 4 5 using HeuristicLab.Common; 5 6 using HeuristicLab.Core; … … 20 21 } 21 22 22 public override double Evaluate(SOLUTION_CLASS solution, IRandom random ) {23 public override double Evaluate(SOLUTION_CLASS solution, IRandom random, CancellationToken cancellationToken) { 23 24 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 24 25 var quality = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.