Changeset 12005 for stable/HeuristicLab.Optimization/3.3/BasicProblems
- Timestamp:
- 02/13/15 15:00:15 (10 years ago)
- Location:
- stable
- Files:
-
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 11939,11945,11956,11958-11961,11963,11967,11970-11971,11982-11984,11987-11988,11990,11993-11994,11996,11998-12004
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization/3.3/BasicProblems/BasicProblem.cs
r11949 r12005 67 67 Parameters.Add(new ValueParameter<TEncoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any.")); 68 68 oldEncoding = Encoding; 69 if(Encoding != null) Parameterize(); 69 70 RegisterEvents(); 70 71 } … … 86 87 private void RegisterEvents() { 87 88 EncodingParameter.ValueChanged += (o, e) => OnEncodingChanged(); 89 var multiEncoding = Encoding as MultiEncoding; 90 if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged; 88 91 } 89 92 90 93 protected virtual void OnEncodingChanged() { 91 if (oldEncoding != null) AdaptEncodingOperators(oldEncoding, Encoding); 94 Parameterize(); 95 96 OnOperatorsChanged(); 97 OnReset(); 98 } 99 100 private void Parameterize() { 101 if (oldEncoding != null) { 102 AdaptEncodingOperators(oldEncoding, Encoding); 103 var oldMultiEncoding = oldEncoding as MultiEncoding; 104 if (oldMultiEncoding != null) 105 oldMultiEncoding.EncodingsChanged -= MultiEncodingOnEncodingsChanged; 106 } 92 107 oldEncoding = Encoding; 93 108 … … 101 116 Parameters.Remove(SolutionCreatorParameter); 102 117 Parameters.Add(solutionCreatorParam); 118 ((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged; 103 119 104 //TODO register solution creator changed event, change access modifier to private 105 //((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged; 106 107 OnOperatorsChanged(); 108 OnReset(); 120 var multiEncoding = Encoding as MultiEncoding; 121 if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged; 109 122 } 110 123 … … 141 154 } 142 155 156 protected virtual void MultiEncodingOnEncodingsChanged(object sender, EventArgs e) { 157 OnOperatorsChanged(); 158 } 143 159 } 144 160 } -
stable/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveMoveOperator.cs
r11961 r12005 21 21 22 22 namespace HeuristicLab.Optimization { 23 public interface ISingleObjectiveMoveOperator : IMoveOperator {23 public interface ISingleObjectiveMoveOperator : IMoveOperator, ISingleObjectiveOperator { 24 24 } 25 25 } -
stable/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/internal/IMultiObjectiveAnalysisOperator.cs
r11949 r12005 24 24 25 25 namespace HeuristicLab.Optimization { 26 internal interface IMultiObjectiveAnalysisOperator : IEncodingOperator, IAnalyzer {26 internal interface IMultiObjectiveAnalysisOperator : IEncodingOperator, IAnalyzer, IMultiObjectiveOperator { 27 27 Action<Individual[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; } 28 28 } -
stable/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/internal/ISingleObjectiveAnalysisOperator.cs
r11961 r12005 24 24 25 25 namespace HeuristicLab.Optimization { 26 internal interface ISingleObjectiveAnalysisOperator : IEncodingOperator {26 internal interface ISingleObjectiveAnalysisOperator : IEncodingOperator, ISingleObjectiveOperator { 27 27 Action<Individual[], double[], ResultCollection, IRandom> AnalyzeAction { get; set; } 28 28 } -
stable/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs
r11949 r12005 41 41 protected MultiObjectiveBasicProblem() 42 42 : base() { 43 Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", new BoolArray()));43 Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly())); 44 44 45 45 Operators.Add(Evaluator); … … 58 58 public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { } 59 59 60 protected override void OnEncodingChanged() { 61 base.OnEncodingChanged(); 62 Parameters["Maximization"].ActualValue = new BoolArray(Maximization); 60 protected override void OnOperatorsChanged() { 61 base.OnOperatorsChanged(); 62 if (Encoding != null) { 63 PruneSingleObjectiveOperators(Encoding); 64 var multiEncoding = Encoding as MultiEncoding; 65 if (multiEncoding != null) { 66 foreach (var encoding in multiEncoding.Encodings.ToList()) { 67 PruneSingleObjectiveOperators(encoding); 68 } 69 } 70 } 71 } 72 73 private void PruneSingleObjectiveOperators(IEncoding encoding) { 74 if (encoding != null && encoding.Operators.Any(x => x is ISingleObjectiveOperator && !(x is IMultiObjectiveOperator))) 75 encoding.Operators = encoding.Operators.Where(x => !(x is ISingleObjectiveOperator) || x is IMultiObjectiveOperator).ToList(); 63 76 } 64 77 -
stable/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs
r11949 r12005 33 33 ISingleObjectiveProblemDefinition, ISingleObjectiveHeuristicOptimizationProblem 34 34 where TEncoding : class, IEncoding { 35 36 protected IValueParameter<DoubleValue> BestKnownQualityParameter { 37 get { return (IValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 38 } 39 40 public double BestKnownQuality { 41 get { 42 if (BestKnownQualityParameter.Value == null) return double.NaN; 43 return BestKnownQualityParameter.Value.Value; 44 } 45 set { 46 if (BestKnownQualityParameter.Value == null) BestKnownQualityParameter.Value = new DoubleValue(value); 47 else BestKnownQualityParameter.Value.Value = value; 48 } 49 } 50 35 51 [StorableConstructor] 36 52 protected SingleObjectiveBasicProblem(bool deserializing) : base(deserializing) { } … … 43 59 protected SingleObjectiveBasicProblem() 44 60 : base() { 45 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue()));61 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true }); 46 62 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.")); 47 63 … … 68 84 } 69 85 86 protected override void OnOperatorsChanged() { 87 base.OnOperatorsChanged(); 88 if (Encoding != null) { 89 PruneMultiObjectiveOperators(Encoding); 90 var multiEncoding = Encoding as MultiEncoding; 91 if (multiEncoding != null) { 92 foreach (var encoding in multiEncoding.Encodings.ToList()) { 93 PruneMultiObjectiveOperators(encoding); 94 } 95 } 96 } 97 } 70 98 71 protected override void OnEncodingChanged() { 72 base.OnEncodingChanged(); 73 var max = (BoolValue)Parameters["Maximization"].ActualValue; 74 max.Value = Maximization; 99 private void PruneMultiObjectiveOperators(IEncoding encoding) { 100 if (encoding.Operators.Any(x => x is IMultiObjectiveOperator && !(x is ISingleObjectiveOperator))) 101 encoding.Operators = encoding.Operators.Where(x => !(x is IMultiObjectiveOperator) || x is ISingleObjectiveOperator).ToList(); 75 102 } 76 103
Note: See TracChangeset
for help on using the changeset viewer.