- Timestamp:
- 05/27/15 14:30:56 (9 years ago)
- Location:
- branches/TerminationCriteria
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/TerminationCriteria/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs
r12404 r12405 116 116 get { return (IFixedValueParameter<BoolValue>)Parameters["FillPopulationWithParents"]; } 117 117 } 118 private IValueParameter<MultiTerminator> Terminat orsParameter {119 get { return (IValueParameter<MultiTerminator>)Parameters["Terminat or"]; }118 private IValueParameter<MultiTerminator> TerminationParameter { 119 get { return (IValueParameter<MultiTerminator>)Parameters["Termination"]; } 120 120 } 121 121 #endregion … … 204 204 } 205 205 private MultiTerminator Terminators { 206 get { return Terminat orsParameter.Value; }206 get { return TerminationParameter.Value; } 207 207 } 208 208 private RandomCreator RandomCreator { … … 287 287 Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue))); 288 288 Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.", new BoolValue(false)) { Hidden = true }); 289 Parameters.Add(new ValueParameter<MultiTerminator>("Terminat or", "The termination criteria which sould be checked.", new MultiTerminator()));289 Parameters.Add(new ValueParameter<MultiTerminator>("Termination", "The termination criteria which sould be checked.", new MultiTerminator())); 290 290 291 291 RandomCreator randomCreator = new RandomCreator(); … … 351 351 UpdateAnalyzers(); 352 352 353 generationsTerminator = new ComparisonTerminator<IntValue>("Generations", new IntValue(50), ComparisonType.GreaterOrEqual) { Name = "Generations" };354 evaluatedSolutionsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", "MaximumEvaluatedSolutions", ComparisonType.GreaterOrEqual) { Name = "Evaluations" };355 selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", "MaximumSelectionPressure", ComparisonType.GreaterOrEqual) { Name = "Selection Pressure" };356 qualityTerminator = new ComparisonTerminator<DoubleValue>( ) { Name = "Quality" };357 executionTimeTerminator = new ExecutionTimeTerminator(this, TimeSpan.FromMinutes(5)) { Name = "Execution Time" };353 generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.GreaterOrEqual, new IntValue(50)) { Name = "Generations" }; 354 evaluatedSolutionsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.GreaterOrEqual, new IntValue(int.MaxValue)) { Name = "Evaluations" }; 355 selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.GreaterOrEqual, new DoubleValue(200)) { Name = "Selection Pressure" }; 356 qualityTerminator = new ComparisonTerminator<DoubleValue>(threshold: new DoubleValue()) { Name = "Quality" }; 357 executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))) { Name = "Execution Time" }; 358 358 ParameterizeTerminators(); 359 359 UpdateTerminators(); … … 508 508 if (maximizationParameter != null) { 509 509 bool maximization = maximizationParameter.Value.Value; 510 qualityTerminator.Comparison = new Comparison(maximization ? ComparisonType.GreaterOrEqual : ComparisonType.LessOrEqual);511 qualityTerminator.Threshold Parameter.Value = new DoubleValue(maximization ? double.MaxValue : double.MinValue);510 qualityTerminator.Comparison = maximization ? ComparisonType.GreaterOrEqual : ComparisonType.LessOrEqual; 511 qualityTerminator.Threshold.Value = maximization ? double.MaxValue : double.MinValue; 512 512 } 513 513 } 514 qualityTerminator. ValueParameter.ActualName = qualityAnalyzer.CurrentBestQualityParameter.Name;514 qualityTerminator.ComparisonValueParameter.ActualName = qualityAnalyzer.CurrentBestQualityParameter.Name; 515 515 } 516 516 private void ParameterizeComparisonFactorModifiers() { -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/ComparisonTerminator.cs
r12402 r12405 30 30 [Item("ComparisonTerminator", "An termination criterion which compares two values.")] 31 31 [StorableClass] 32 public class ComparisonTerminator<T> : ThresholdTerminator<T> where T : class, IItem, IComparable {33 public ILookupParameter<T> ValueParameter {34 get { return (ILookupParameter<T>)Parameters[" Value"]; }32 public class ComparisonTerminator<T> : ThresholdTerminator<T> where T : class, IItem, IComparable, new() { 33 public ILookupParameter<T> ComparisonValueParameter { 34 get { return (ILookupParameter<T>)Parameters["ComparisonValue"]; } 35 35 } 36 36 37 private ValueParameter<Comparison> ComparisonParameter {38 get { return ( ValueParameter<Comparison>)Parameters["Comparison"]; }37 private IFixedValueParameter<Comparison> ComparisonParameter { 38 get { return (IFixedValueParameter<Comparison>)Parameters["Comparison"]; } 39 39 } 40 40 41 public Comparison Comparison {42 get { return ComparisonParameter.Value ; }43 set { ComparisonParameter.Value = value; }41 public ComparisonType Comparison { 42 get { return ComparisonParameter.Value.Value; } 43 set { ComparisonParameter.Value.Value = value; } 44 44 } 45 45 46 46 [StorableConstructor] 47 47 protected ComparisonTerminator(bool deserializing) : base(deserializing) { } 48 [StorableHook(HookType.AfterDeserialization)] 49 private void AfterDeserialization() { 50 Initialize(); 51 } 48 52 protected ComparisonTerminator(ComparisonTerminator<T> original, Cloner cloner) 49 : base(original, cloner) { } 53 : base(original, cloner) { 54 Initialize(); 55 } 50 56 public override IDeepCloneable Clone(Cloner cloner) { 51 57 return new ComparisonTerminator<T>(this, cloner); 52 58 } 53 public ComparisonTerminator() 54 : base() { 55 Parameters.Add(new LookupParameter<T>("Value", "The left side value of the comparison.")); 56 Parameters.Add(new ValueParameter<Comparison>("Comparison", "The type of comparison.", new Comparison(ComparisonType.GreaterOrEqual)) { Hidden = true }); 59 public ComparisonTerminator(T threshold = default(T)) 60 : base(threshold) { 61 Parameters.Add(new LookupParameter<T>("ComparisonValue", "The left side value of the comparison.") { Hidden = false }); 62 Parameters.Add(new FixedValueParameter<Comparison>("Comparison", "The type of comparison.")); 63 Initialize(); 57 64 } 58 public ComparisonTerminator(string leftSideActualName, string rightSideActualName, ComparisonType comparison = ComparisonType.GreaterOrEqual) 59 : this() { 60 ValueParameter.ActualName = leftSideActualName; 61 ThresholdParameter.ActualName = rightSideActualName; 62 Comparison.Value = comparison; 65 public ComparisonTerminator(string comparisonValueActualName, ComparisonType comparison = default(ComparisonType), T threshold = default(T)) 66 : this(threshold) { 67 ComparisonValueParameter.ActualName = comparisonValueActualName; 68 Comparison = comparison; 63 69 } 64 public ComparisonTerminator(string leftSideActualName, T rightSideValue, ComparisonType comparison = ComparisonType.GreaterOrEqual) 65 : this() { 66 ValueParameter.ActualName = leftSideActualName; 67 ThresholdParameter.Value = rightSideValue; 68 Comparison.Value = comparison; 70 71 private void Initialize() { 72 ComparisonParameter.ToStringChanged += (s, a) => OnToStringChanged(); 69 73 } 70 74 71 75 protected override bool CheckTermination() { 72 IComparable lhs = ValueParameter.ActualValue;73 IComparable rhs = ThresholdParameter. ActualValue;76 IComparable lhs = ComparisonValueParameter.ActualValue; 77 IComparable rhs = ThresholdParameter.Value; 74 78 79 return Comparison.Compare(lhs, rhs); 80 } 81 82 public override string ToString() { 83 if (Threshold == null) return Name; 84 else return string.Format("{0} {1} {2}", Name, Comparison.ToSymbol(), ThresholdParameter.Value); 85 } 86 } 87 88 internal static class ComparisonTypeHelper { 89 public static bool Compare(this ComparisonType comparison, IComparable lhs, IComparable rhs) { 75 90 int i = lhs.CompareTo(rhs); 76 switch (Comparison.Value) { 77 case ComparisonType.Less: 78 return i < 0; 79 case ComparisonType.LessOrEqual: 80 return i <= 0; 81 case ComparisonType.Equal: 82 return i == 0; 83 case ComparisonType.GreaterOrEqual: 84 return i >= 0; 85 case ComparisonType.Greater: 86 return i > 0; 87 case ComparisonType.NotEqual: 88 return i != 0; 89 default: 90 throw new InvalidOperationException(Name + ": " + Comparison.Value + " is not supported."); 91 switch (comparison) { 92 case ComparisonType.Less: return i < 0; 93 case ComparisonType.LessOrEqual: return i <= 0; 94 case ComparisonType.Equal: return i == 0; 95 case ComparisonType.GreaterOrEqual: return i >= 0; 96 case ComparisonType.Greater: return i > 0; 97 case ComparisonType.NotEqual: return i != 0; 98 default: throw new InvalidOperationException(comparison + " is not supported."); 99 } 100 } 101 102 public static string ToSymbol(this ComparisonType comparison) { 103 switch (comparison) { 104 case ComparisonType.Less: return "<"; 105 case ComparisonType.LessOrEqual: return "<="; 106 case ComparisonType.Equal: return "="; 107 case ComparisonType.GreaterOrEqual: return ">="; 108 case ComparisonType.Greater: return ">"; 109 case ComparisonType.NotEqual: return "!="; 110 default: throw new InvalidOperationException(comparison + " is not supported."); 91 111 } 92 112 } -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/ExecutionTimeTerminator.cs
r12402 r12405 44 44 } 45 45 public ExecutionTimeTerminator(IExecutable executable) 46 : this(executable, new TimeSpan(0, 10, 0)) { } 47 public ExecutionTimeTerminator(IExecutable executable, TimeSpan maximumExecutionTime) { 46 : this(executable, new TimeSpanValue(new TimeSpan(0, 10, 0))) { } 47 public ExecutionTimeTerminator(IExecutable executable, TimeSpanValue maximumExecutionTime) 48 : base(maximumExecutionTime) { 48 49 this.executable = executable; 49 ThresholdParameter.Value = new TimeSpanValue(maximumExecutionTime);50 51 50 Name = "Execution Time"; 52 51 } … … 57 56 return executable.ExecutionTime > max; 58 57 } 58 59 public override string ToString() { 60 if (Threshold == null) return Name; 61 else return string.Format("{0} {1} {2}", Name, ">", ThresholdParameter.Value); 62 } 59 63 } 60 64 } -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/MultiTerminator.cs
r12402 r12405 35 35 public sealed class MultiTerminator : CheckedMultiOperator<ITerminator>, ITerminator { 36 36 public static new Image StaticItemImage { 37 get { return HeuristicLab.Common.Resources.VSImageLibrary. Object; }37 get { return HeuristicLab.Common.Resources.VSImageLibrary.FlagRed; } 38 38 } 39 39 public override Image ItemImage { -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/TerminationOperator.cs
r12404 r12405 31 31 [StorableClass] 32 32 public sealed class TerminationOperator : InstrumentedOperator { 33 public ILookupParameter<ITerminator> Terminat orParameter {34 get { return (ILookupParameter<ITerminator>)Parameters["Terminat or"]; }33 public ILookupParameter<ITerminator> TerminationParameter { 34 get { return (ILookupParameter<ITerminator>)Parameters["Termination"]; } 35 35 } 36 36 public ILookupParameter<BoolValue> TerminateParameter { … … 64 64 public TerminationOperator() 65 65 : base() { 66 Parameters.Add(new LookupParameter<ITerminator>("Terminat or", "The termination criteria which sould be checked."));66 Parameters.Add(new LookupParameter<ITerminator>("Termination", "The termination criteria which sould be checked.")); 67 67 Parameters.Add(new LookupParameter<BoolValue>("Terminate", "The parameter which will be set to determine if execution should be terminated or schould continue.")); 68 68 Parameters.Add(new OperatorParameter("ContinueBranch", "The operator which is executed if no termination criteria has met.")); … … 74 74 75 75 var placeholder = new Placeholder() { Name = "Check termination criteria (Placeholder)" }; 76 placeholder.OperatorParameter.ActualName = Terminat orParameter.Name;76 placeholder.OperatorParameter.ActualName = TerminationParameter.Name; 77 77 78 78 BeforeExecutionOperators.Add(assigner); -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/Terminator.cs
r12402 r12405 20 20 #endregion 21 21 22 using System.Drawing; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 31 32 [StorableClass] 32 33 public abstract class Terminator : InstrumentedOperator, ITerminator { 34 public static new Image StaticItemImage { 35 get { return HeuristicLab.Common.Resources.VSImageLibrary.FlagRed; } 36 } 37 33 38 public ILookupParameter<BoolValue> TerminateParameter { 34 39 get { return (ILookupParameter<BoolValue>)Parameters["Terminate"]; } -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/ThresholdTerminator.cs
r12402 r12405 29 29 [Item("ThresholdTerminator", "Base class for all termination criteria which specifies some threshold.")] 30 30 [StorableClass] 31 public abstract class ThresholdTerminator<T> : Terminator where T : class, IItem { 32 public IValueLookupParameter<T> ThresholdParameter { 33 get { return (IValueLookupParameter<T>)Parameters["Threshold"]; } 31 public abstract class ThresholdTerminator<T> : Terminator where T : class, IItem, new() { 32 public IFixedValueParameter<T> ThresholdParameter { 33 get { return (IFixedValueParameter<T>)Parameters["Threshold"]; } 34 } 35 36 public T Threshold { 37 get { return ThresholdParameter.Value; } 34 38 } 35 39 … … 44 48 Initialize(); 45 49 } 46 protected ThresholdTerminator( )50 protected ThresholdTerminator(T threshold = default(T)) 47 51 : base() { 48 Parameters.Add(new ValueLookupParameter<T>("Threshold", "The limit of the termiation criterion.")); 49 52 Parameters.Add(new FixedValueParameter<T>("Threshold", "The limit of the termiation criterion.", threshold)); 50 53 Initialize(); 51 54 } -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/Views/ThresholdTerminatorView.Designer.cs
r12404 r12405 20 20 #endregion 21 21 22 using System; 23 using HeuristicLab.Core; 24 22 25 namespace HeuristicLab.Termination.Views { 23 partial class ThresholdTerminatorView<T> {26 partial class ThresholdTerminatorView<T> where T : class, IItem, IComparable, new() { 24 27 /// <summary> 25 28 /// Required designer variable. -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/Views/ThresholdTerminatorView.cs
r12402 r12405 29 29 [View("ThresholdTerminator View")] 30 30 [Content(typeof(ThresholdTerminator<>), true)] 31 public partial class ThresholdTerminatorView<T> : ItemView where T : class, IItem, IComparable {31 public partial class ThresholdTerminatorView<T> : ItemView where T : class, IItem, IComparable, new() { 32 32 33 33 public new ThresholdTerminator<T> Content {
Note: See TracChangeset
for help on using the changeset viewer.