Changeset 17320
- Timestamp:
- 10/04/19 17:31:54 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 39 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessCovarianceOptimizationProblem.cs
r17270 r17320 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; … … 197 198 private readonly object syncRoot = new object(); 198 199 // Does not produce the same result for the same seed when using parallel engine (see below)! 199 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random ) {200 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 200 201 var meanFunction = new MeanConst(); 201 202 var problemData = ProblemData; -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r17226 r17320 23 23 using System; 24 24 using System.Collections.Generic; 25 using System.Threading; 26 using HEAL.Attic; 25 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Core; 27 29 using HeuristicLab.Encodings.BinaryVectorEncoding; 28 30 using HeuristicLab.Optimization; 29 using HEAL.Attic;30 31 31 32 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { … … 93 94 } 94 95 96 public double Evaluate(BinaryVector vector, IRandom random) { 97 return Evaluate(vector, random, CancellationToken.None); 98 } 95 99 96 97 public double Evaluate(BinaryVector vector, IRandom random) { 100 public double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) { 98 101 if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached"); 99 102 Evaluations++; -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IMultiObjectiveProblem.cs
r17317 r17320 33 33 where TEncoding : class, IEncoding<TEncodedSolution> 34 34 where TEncodedSolution : class, IEncodedSolution { } 35 36 //TODO derive IMutliObjectiveProblem from IMultiObjectiveProblemDefinition? 35 37 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IMultiObjectiveProblemDefinition.cs
r17315 r17320 21 21 22 22 using System.Collections.Generic; 23 using System.Threading; 23 24 using HEAL.Attic; 24 25 using HeuristicLab.Core; … … 38 39 where TEncodedSolution : class, IEncodedSolution { 39 40 double[] Evaluate(TEncodedSolution solution, IRandom random); 41 double[] Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 40 42 void Analyze(TEncodedSolution[] solutions, double[][] qualities, ResultCollection results, IRandom random); 41 43 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblem.cs
r17317 r17320 33 33 where TEncoding : class, IEncoding<TEncodedSolution> 34 34 where TEncodedSolution : class, IEncodedSolution { } 35 //TODO derive ISingleObjectiveProblem from ISingleObjectiveProblemDefinition? 35 36 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblemDefinition.cs
r17257 r17320 21 21 22 22 using System.Collections.Generic; 23 using System.Threading; 23 24 using HEAL.Attic; 24 25 using HeuristicLab.Core; … … 35 36 where TEncoding : class, IEncoding<TEncodedSolution> 36 37 where TEncodedSolution : class, IEncodedSolution { 38 37 39 double Evaluate(TEncodedSolution solution, IRandom random); 40 double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 41 38 42 void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random); 39 43 IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solution, IRandom random); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs
r17317 r17320 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; … … 133 134 } 134 135 135 public abstract double[] Evaluate(TEncodedSolution solution, IRandom random); 136 public virtual double[] Evaluate(TEncodedSolution solution, IRandom random) { 137 return Evaluate(solution, random, CancellationToken.None); 138 } 139 140 public abstract double[] Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 136 141 public virtual void Analyze(TEncodedSolution[] solutions, double[][] qualities, ResultCollection results, IRandom random) { } 137 142 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
r17317 r17320 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; … … 112 113 } 113 114 114 public abstract double Evaluate(TEncodedSolution solution, IRandom random); 115 public virtual double Evaluate(TEncodedSolution solution, IRandom random) { 116 return Evaluate(solution, random, CancellationToken.None); 117 } 118 public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 115 119 public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { } 116 120 public virtual IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solution, IRandom random) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs
r17270 r17320 23 23 24 24 using System; 25 using System.Threading; 25 26 using HEAL.Attic; 26 27 using HeuristicLab.Common; … … 80 81 } 81 82 82 public override double Evaluate(BinaryVector individual, IRandom random ) {83 public override double Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) { 83 84 if (individual.Length != Length) throw new ArgumentException("The individual has not the correct length."); 84 85 int total = 0; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs
r17270 r17320 23 23 24 24 using System; 25 using System.Threading; 25 26 using HEAL.Attic; 26 27 using HeuristicLab.Common; … … 47 48 } 48 49 // In the GECCO paper, Section 4.1 49 public override double Evaluate(BinaryVector individual, IRandom random ) {50 public override double Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) { 50 51 int[] level = new int[individual.Length]; 51 52 int levelLength = individual.Length; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs
r17270 r17320 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; … … 47 48 } 48 49 49 public override double Evaluate(BinaryVector vector, IRandom random ) {50 public override double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) { 50 51 return vector.Count(b => b); 51 52 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/EvaluationCache.cs
r17226 r17320 31 31 using System.Threading; 32 32 using Google.ProtocolBuffers; 33 using HEAL.Attic; 33 34 using HeuristicLab.Common; 34 35 using HeuristicLab.Common.Resources; … … 36 37 using HeuristicLab.Data; 37 38 using HeuristicLab.Parameters; 38 using HEAL.Attic;39 39 40 40 namespace HeuristicLab.Problems.ExternalEvaluation { … … 50 50 private byte[] rawMessage; 51 51 52 private object lockObject = new object();52 private readonly object lockObject = new object(); 53 53 54 54 public byte[] RawMessage { … … 116 116 } 117 117 118 public delegate QualityMessage Evaluator(SolutionMessage message );118 public delegate QualityMessage Evaluator(SolutionMessage message, CancellationToken cancellationToken); 119 119 #endregion 120 120 … … 124 124 125 125 private HashSet<string> activeEvaluations = new HashSet<string>(); 126 private object cacheLock = new object();126 private readonly object cacheLock = new object(); 127 127 #endregion 128 128 … … 221 221 } 222 222 223 void CapacityChanged(object sender, EventArgs e) {223 private void CapacityChanged(object sender, EventArgs e) { 224 224 if (Capacity < 0) 225 225 throw new ArgumentOutOfRangeException("Cache capacity cannot be less than zero"); … … 240 240 } 241 241 242 public QualityMessage GetValue(SolutionMessage message, Evaluator evaluate, ExtensionRegistry extensions ) {242 public QualityMessage GetValue(SolutionMessage message, Evaluator evaluate, ExtensionRegistry extensions, CancellationToken cancellationToken) { 243 243 var entry = new CacheEntry(message.ToString()); 244 244 bool lockTaken = false; … … 267 267 OnChanged(); 268 268 try { 269 entry.SetMessage(evaluate(message ));269 entry.SetMessage(evaluate(message, cancellationToken)); 270 270 Monitor.Enter(cacheLock, ref lockTaken); 271 271 index[entry] = list.AddLast(entry); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/IExternalEvaluationProblem.cs
r17226 r17320 20 20 #endregion 21 21 22 using System.Threading; 22 23 using Google.ProtocolBuffers; 24 using HEAL.Attic; 23 25 using HeuristicLab.Core; 24 26 using HeuristicLab.Optimization; 25 using HEAL.Attic;26 27 27 28 namespace HeuristicLab.Problems.ExternalEvaluation { … … 32 33 CheckedItemCollection<IEvaluationServiceClient> Clients { get; } 33 34 34 QualityMessage Evaluate(SolutionMessage solutionMessage );35 QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken); 35 36 ExtensionRegistry GetQualityMessageExtensions(); 36 37 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/MultiObjectiveExternalEvaluationProblem.cs
r17317 r17320 106 106 } 107 107 108 public override double[] Evaluate(TEncodedSolution individual, IRandom random ) {109 var qualityMessage = Evaluate(BuildSolutionMessage(individual) );108 public override double[] Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) { 109 var qualityMessage = Evaluate(BuildSolutionMessage(individual), cancellationToken); 110 110 if (!qualityMessage.HasExtension(MultiObjectiveQualityMessage.QualityMessage_)) 111 111 throw new InvalidOperationException("The received message is not a MultiObjectiveQualityMessage."); 112 112 return qualityMessage.GetExtension(MultiObjectiveQualityMessage.QualityMessage_).QualitiesList.ToArray(); 113 113 } 114 public virtual QualityMessage Evaluate(SolutionMessage solutionMessage ) {114 public virtual QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken) { 115 115 return Cache == null 116 ? EvaluateOnNextAvailableClient(solutionMessage )117 : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions() );116 ? EvaluateOnNextAvailableClient(solutionMessage, cancellationToken) 117 : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions(), cancellationToken); 118 118 } 119 119 … … 132 132 #region Evaluation 133 133 private HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>(); 134 private object clientLock = new object();134 private readonly object clientLock = new object(); 135 135 136 private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message ) {136 private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message, CancellationToken cancellationToken) { 137 137 IEvaluationServiceClient client = null; 138 138 lock (clientLock) { … … 147 147 try { 148 148 return client.Evaluate(message, GetQualityMessageExtensions()); 149 } 150 finally { 149 } finally { 151 150 lock (clientLock) { 152 151 activeClients.Remove(client); … … 165 164 try { 166 165 MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder); 167 } 168 catch (ArgumentException ex) { 166 } catch (ArgumentException ex) { 169 167 throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex); 170 168 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs
r17279 r17320 103 103 104 104 #region Single Objective Problem Overrides 105 public override double Evaluate(TEncodedSolution solution, IRandom random ) {106 var qualityMessage = Evaluate(BuildSolutionMessage(solution) );105 public override double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) { 106 var qualityMessage = Evaluate(BuildSolutionMessage(solution), cancellationToken); 107 107 if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_)) 108 108 throw new InvalidOperationException("The received message is not a SingleObjectiveQualityMessage."); 109 109 return qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality; 110 110 } 111 public virtual QualityMessage Evaluate(SolutionMessage solutionMessage ) {111 public virtual QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken) { 112 112 return Cache == null 113 ? EvaluateOnNextAvailableClient(solutionMessage )114 : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions() );113 ? EvaluateOnNextAvailableClient(solutionMessage,cancellationToken) 114 : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions(), cancellationToken); 115 115 } 116 116 … … 132 132 #region Evaluation 133 133 private HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>(); 134 private object clientLock = new object();134 private readonly object clientLock = new object(); 135 135 136 private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message ) {136 private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message, CancellationToken cancellationToken) { 137 137 IEvaluationServiceClient client = null; 138 138 lock (clientLock) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs
r17270 r17320 23 23 using System.Diagnostics.Contracts; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HEAL.Attic; 26 27 using HeuristicLab.Common; … … 134 135 135 136 136 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random ) {137 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 137 138 var interpreter = new Interpreter(tree, World, MaxTimeSteps); 138 139 interpreter.Run(); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs
r17270 r17320 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; … … 89 90 90 91 91 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random ) {92 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 92 93 // Doesn't use classes from HeuristicLab.Problems.DataAnalysis.Symbolic to make sure that the implementation can be fully understood easily. 93 94 // HeuristicLab.Problems.DataAnalysis.Symbolic would already provide all the necessary functionality (esp. interpreter) but at a much higher complexity. -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs
r17270 r17320 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; … … 103 104 104 105 105 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random ) {106 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 106 107 if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero."); 107 108 if (NumberOfBits > 10) throw new NotSupportedException("Even parity does not support problems with number of bits > 10."); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs
r17270 r17320 24 24 using System.Diagnostics.Contracts; 25 25 using System.Linq; 26 using System.Threading; 26 27 using HEAL.Attic; 27 28 using HeuristicLab.Common; … … 117 118 118 119 119 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random ) {120 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 120 121 if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero."); 121 122 if (NumberOfBits > 37) throw new NotSupportedException("Multiplexer does not support problems with number of bits > 37."); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs
r17270 r17320 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; … … 92 93 } 93 94 94 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random ) {95 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 95 96 var length = LawnLengthParameter.Value.Value; 96 97 var width = LawnWidthParameter.Value.Value; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Problem.cs
r17270 r17320 20 20 #endregion 21 21 22 using System.Threading; 22 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; … … 98 99 private void AfterDeserialization() { RegisterEventHandlers(); } 99 100 100 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random ) {101 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 101 102 return Interpreter.EvaluateTankProgram(tree, RobocodePath, Enemies, null, false, NrOfRounds); 102 103 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs
r17270 r17320 23 23 24 24 using System.Linq; 25 using System.Threading; 25 26 using HEAL.Attic; 26 27 using HeuristicLab.Common; … … 95 96 96 97 private readonly object syncRoot = new object(); 97 public override double Evaluate(IntegerVector solution, IRandom random ) {98 public override double Evaluate(IntegerVector solution, IRandom random, CancellationToken cancellationToken) { 98 99 var bounds = Encoding.Bounds; 99 100 var len = Encoding.Length; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs
r17270 r17320 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Analysis; … … 128 129 } 129 130 130 public override double Evaluate(LinearLinkage lle, IRandom random ) {131 public override double Evaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) { 131 132 var adjList = adjacencyListParameter.Value; 132 133 var llee = lle.ToEndLinks(); // LLE-e encoding uses the highest indexed member as group number -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r17270 r17320 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HEAL.Attic; 26 27 using HeuristicLab.Analysis; … … 96 97 } 97 98 98 public override double Evaluate(BinaryVector solution, IRandom random ) {99 public override double Evaluate(BinaryVector solution, IRandom random, CancellationToken cancellationToken) { 99 100 var totalWeight = 0.0; 100 101 var totalValue = 0.0; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.NK/3.3/NKLandscape.cs
r17270 r17320 23 23 using System.Linq; 24 24 using System.Security.Cryptography; 25 using System.Threading; 25 26 using HEAL.Attic; 26 27 using HeuristicLab.Common; … … 334 335 } 335 336 336 public override double Evaluate(BinaryVector vector, IRandom random ) {337 public override double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) { 337 338 double[] f_i; //useful for debugging 338 339 double quality = Evaluate(vector, GeneInteractions, Weights, InteractionSeed.Value, out f_i, Q, P); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/HeuristicLab.Problems.PTSP.Views-3.3.csproj
r17264 r17320 73 73 <Private>False</Private> 74 74 </ProjectReference> 75 <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj"> 76 <Project>{0e27a536-1c4a-4624-a65e-dc4f4f23e3e1}</Project> 77 <Name>HeuristicLab.Common.Resources-3.3</Name> 78 </ProjectReference> 75 79 <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj"> 76 80 <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project> … … 157 161 <Private>False</Private> 158 162 </ProjectReference> 159 <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />160 163 <Reference Include="System" /> 161 164 <Reference Include="System.Core" /> -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/AnalyticalPTSP.cs
r17264 r17320 20 20 #endregion 21 21 22 using System.Threading; 22 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; … … 59 60 } 60 61 61 public override double Evaluate(Permutation tour, IRandom random ) {62 return Evaluate(tour, ProbabilisticTSPData );62 public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 63 return Evaluate(tour, ProbabilisticTSPData, cancellationToken); 63 64 } 64 65 65 public static double Evaluate(Permutation tour, IProbabilisticTSPData data ) {66 public static double Evaluate(Permutation tour, IProbabilisticTSPData data, CancellationToken cancellationToken) { 66 67 // Analytical evaluation 67 68 var firstSum = 0.0; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/EstimatedPTSP.cs
r17264 r17320 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; … … 101 102 } 102 103 103 public override double Evaluate(Permutation tour, IRandom random ) {104 return Evaluate(tour, ProbabilisticTSPData, RealizationData );104 public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 105 return Evaluate(tour, ProbabilisticTSPData, RealizationData, cancellationToken); 105 106 } 106 107 … … 110 111 } 111 112 112 public static double Evaluate(Permutation tour, IProbabilisticTSPData data, IEnumerable<BoolArray> realizations ) {113 public static double Evaluate(Permutation tour, IProbabilisticTSPData data, IEnumerable<BoolArray> realizations, CancellationToken cancellationToken) { 113 114 // Estimation-based evaluation, here without calculating variance for faster evaluation 114 115 var estimatedSum = 0.0; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/OneShift/PTSPAnalyticalInsertionMoveEvaluator.cs
r17253 r17320 20 20 #endregion 21 21 22 using System.Threading; 22 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; … … 50 51 var afterMove = (Permutation)tour.Clone(); 51 52 TranslocationManipulator.Apply(afterMove, move.Index1, move.Index1, move.Index3); 52 return AnalyticalPTSP.Evaluate(afterMove, data );53 return AnalyticalPTSP.Evaluate(afterMove, data, CancellationToken.None); 53 54 } 54 55 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/TwoOpt/PTSPAnalyticalInversionMoveEvaluator.cs
r17253 r17320 20 20 #endregion 21 21 22 using System.Threading; 22 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; … … 50 51 var afterMove = (Permutation)tour.Clone(); 51 52 InversionManipulator.Apply(afterMove, move.Index1, move.Index2); 52 return AnalyticalPTSP.Evaluate(afterMove, data );53 return AnalyticalPTSP.Evaluate(afterMove, data, CancellationToken.None); 53 54 } 54 55 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs
r17315 r17320 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Threading; 24 25 using HeuristicLab.Core; 25 using HeuristicLab.Data;26 26 using HeuristicLab.Optimization; 27 27 … … 59 59 #region ISingleObjectiveProblemDefinition<TEncoding,TEncodedSolution> Members 60 60 public abstract bool Maximization { get; } 61 public abstract double Evaluate(TEncodedSolution individual, IRandom random); 61 62 public virtual double Evaluate(TEncodedSolution solution, IRandom random) { 63 return Evaluate(solution, random, CancellationToken.None); 64 } 65 public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 62 66 public abstract void Analyze(TEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random); 63 67 public abstract IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random); … … 82 86 public abstract IReadOnlyList<double[]> BestKnownFront { get; } 83 87 public abstract double[] ReferencePoint { get; } 84 public abstract double[] Evaluate(TEncodedSolution individual, IRandom random); 88 89 public virtual double[] Evaluate(TEncodedSolution solution, IRandom random) { 90 return Evaluate(solution, random, CancellationToken.None); 91 } 92 public abstract double[] Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 85 93 public abstract void Analyze(TEncodedSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random); 86 94 public abstract IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinitionScript.cs
r17315 r17320 21 21 22 22 using System.Collections.Generic; 23 using System.Threading; 23 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 using HeuristicLab.Data;27 27 using HeuristicLab.Optimization; 28 28 … … 59 59 } 60 60 61 double[] IMultiObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) { 62 return CompiledProblemDefinition.Evaluate(individual, random, cancellationToken); 63 } 64 61 65 void IMultiObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Analyze(TEncodedSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 62 66 CompiledProblemDefinition.Analyze(individuals, qualities, results, random); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs
r17317 r17320 22 22 using System.Collections.Generic; 23 23 using System.Drawing; 24 using System.Threading; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; … … 118 119 return ProblemDefinition.Evaluate(individual, random); 119 120 } 121 public override double[] Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) { 122 return ProblemDefinition.Evaluate(individual, random, cancellationToken); 123 } 120 124 121 125 public override void Analyze(TEncodedSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
r17226 r17320 21 21 22 22 using System.Collections.Generic; 23 using System.Threading; 23 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; … … 50 51 public bool Maximization => CompiledProblemDefinition.Maximization; 51 52 52 double ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution individual, IRandom random) { 53 return CompiledProblemDefinition.Evaluate(individual, random); 53 double ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random) { 54 return CompiledProblemDefinition.Evaluate(solution, random); 55 } 56 57 double ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) { 58 return CompiledProblemDefinition.Evaluate(solution, random, cancellationToken); 54 59 } 55 60 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r17270 r17320 22 22 using System.Collections.Generic; 23 23 using System.Drawing; 24 using System.Threading; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Analysis; … … 107 108 } 108 109 109 public override double Evaluate(TEncodedSolution individual, IRandom random ) {110 return ProblemDefinition.Evaluate(individual, random );110 public override double Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) { 111 return ProblemDefinition.Evaluate(individual, random, cancellationToken); 111 112 } 112 113 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r17270 r17320 24 24 using System.Drawing; 25 25 using System.Linq; 26 using System.Threading; 26 27 using HEAL.Attic; 27 28 using HeuristicLab.Common; … … 135 136 } 136 137 137 public override double Evaluate(Permutation assignment, IRandom random ) {138 return Evaluate(assignment );139 } 140 141 public double Evaluate(Permutation assignment ) {138 public override double Evaluate(Permutation assignment, IRandom random, CancellationToken cancellationToken) { 139 return Evaluate(assignment, cancellationToken); 140 } 141 142 public double Evaluate(Permutation assignment, CancellationToken cancellationToken) { 142 143 double quality = 0; 143 144 for (int i = 0; i < assignment.Length; i++) { … … 283 284 // calculate the optimum of a LAP relaxation and use it as lower bound of our QAP 284 285 LowerBound = new DoubleValue(GilmoreLawlerBoundCalculator.CalculateLowerBound(Weights, Distances, out lbSolution)); 285 // evalu te the LAP optimal solution as if it was a QAP solution286 var lbSolutionQuality = Evaluate(lbSolution );286 // evaluate the LAP optimal solution as if it was a QAP solution 287 var lbSolutionQuality = Evaluate(lbSolution, CancellationToken.None); 287 288 // in case both qualities are the same it means that the LAP optimum is also a QAP optimum 288 289 if (LowerBound.Value.IsAlmost(lbSolutionQuality)) { … … 312 313 313 314 public void Load(QAPData data) { 314 if (data.Dimension > ProblemSizeLimit) throw new System.IO.InvalidDataException("The problem is limited to instance of size " + ProblemSizeLimit + ". You can change this limit by modifying " + nameof(QuadraticAssignmentProblem) + "." + nameof(ProblemSizeLimit) + "!");315 if (data.Dimension > ProblemSizeLimit) throw new System.IO.InvalidDataException("The problem is limited to instance of size " + ProblemSizeLimit + ". You can change this limit by modifying " + nameof(QuadraticAssignmentProblem) + "." + nameof(ProblemSizeLimit) + "!"); 315 316 var weights = new DoubleMatrix(data.Weights, @readonly: true); 316 317 var distances = new DoubleMatrix(data.Distances, @readonly: true); … … 363 364 if (assignment == null || assignment.Length == 0) return; 364 365 var vector = new Permutation(PermutationTypes.Absolute, assignment); 365 var result = Evaluate(vector );366 var result = Evaluate(vector, CancellationToken.None); 366 367 BestKnownQuality = result; 367 368 BestKnownSolution = vector; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs
r17317 r17320 20 20 #endregion 21 21 using System; 22 using System.Threading; 22 23 using HEAL.Attic; 23 24 using HeuristicLab.Analysis; … … 121 122 } 122 123 123 public override double[] Evaluate(RealVector solution, IRandom random ) {124 public override double[] Evaluate(RealVector solution, IRandom random, CancellationToken cancellationToken) { 124 125 return TestFunction.Evaluate(solution, Objectives); 125 126 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r17270 r17320 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HEAL.Attic; 26 27 using HeuristicLab.Analysis; … … 108 109 } 109 110 110 public override double Evaluate(RealVector individual, IRandom random ) {111 public override double Evaluate(RealVector individual, IRandom random, CancellationToken cancellationToken) { 111 112 return TestFunction.Evaluate(individual); 112 113 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs
r17270 r17320 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; … … 82 83 } 83 84 84 public override double Evaluate(Permutation tour, IRandom random ) {85 public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 85 86 return Evaluate(tour); 86 87 }
Note: See TracChangeset
for help on using the changeset viewer.