Changeset 15572 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Algorithms/ContextAlgorithm.cs
- Timestamp:
- 01/03/18 00:28:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Algorithms/ContextAlgorithm.cs
r15562 r15572 33 33 [Item("Context-based Algorithm", "Algorithms that make use of contexts to facilitate applying operators.")] 34 34 [StorableClass] 35 public abstract class ContextAlgorithm<TContext> : BasicAlgorithm 36 where TContext : class, IContext, new() { 35 public abstract class ContextAlgorithm<TContext, TEncoding> : BasicAlgorithm 36 where TContext : class, IContext, new() 37 where TEncoding : class, IEncoding { 38 39 public override Type ProblemType { 40 get { return typeof(SingleObjectiveBasicProblem<TEncoding>); } 41 } 42 43 public new SingleObjectiveBasicProblem<TEncoding> Problem { 44 get { return (SingleObjectiveBasicProblem<TEncoding>)base.Problem; } 45 set { base.Problem = value; } 46 } 37 47 38 48 [Storable] … … 62 72 get { return maximumRuntimeParameter; } 63 73 } 74 [Storable] 75 private FixedValueParameter<BoolValue> stopAtBestKnownQualityParameter; 76 public IFixedValueParameter<BoolValue> StopAtBestKnownQualityParameter { 77 get { return stopAtBestKnownQualityParameter; } 78 } 64 79 65 80 public IAnalyzer Analyzer { … … 79 94 set { maximumRuntimeParameter.Value.Value = value; } 80 95 } 96 public bool StopAtBestKnownQuality { 97 get { return stopAtBestKnownQualityParameter.Value.Value; } 98 set { stopAtBestKnownQualityParameter.Value.Value = value; } 99 } 81 100 82 101 [StorableConstructor] 83 102 protected ContextAlgorithm(bool deserializing) : base(deserializing) { } 84 protected ContextAlgorithm(ContextAlgorithm<TContext > original, Cloner cloner)103 protected ContextAlgorithm(ContextAlgorithm<TContext, TEncoding> original, Cloner cloner) 85 104 : base(original, cloner) { 86 105 context = cloner.Clone(original.context); … … 89 108 maximumEvaluationsParameter = cloner.Clone(original.maximumEvaluationsParameter); 90 109 maximumRuntimeParameter = cloner.Clone(original.maximumRuntimeParameter); 110 stopAtBestKnownQualityParameter = cloner.Clone(original.stopAtBestKnownQualityParameter); 91 111 } 92 112 protected ContextAlgorithm() … … 96 116 Parameters.Add(maximumEvaluationsParameter = new FixedValueParameter<IntValue>("MaximumEvaluations", "The number of evaluated solutions that the algorithm should perform or < 1 to ignore.", new IntValue(0))); 97 117 Parameters.Add(maximumRuntimeParameter = new FixedValueParameter<TimeSpanValue>("MaximumRuntime", "The timespan that the algorithm is allowed to run.", new TimeSpanValue(TimeSpan.FromMinutes(1)))); 118 Parameters.Add(stopAtBestKnownQualityParameter = new FixedValueParameter<BoolValue>("StopAtBestKnownQuality", "Whether the algorithm should terminate if the best known quality has been found.", new BoolValue(true))); 98 119 } 99 120 … … 121 142 return MaximumIterations > 0 && Context.Iterations > MaximumIterations 122 143 || MaximumEvaluations > 0 && Context.EvaluatedSolutions > MaximumEvaluations 123 || MaximumRuntime > TimeSpan.Zero && ExecutionTime > MaximumRuntime; 144 || MaximumRuntime > TimeSpan.Zero && ExecutionTime > MaximumRuntime 145 || StopAtBestKnownQuality && !double.IsNaN(Problem.BestKnownQuality) 146 && Context.BestQuality.IsAlmost(Problem.BestKnownQuality); 124 147 } 125 148 }
Note: See TracChangeset
for help on using the changeset viewer.