- Timestamp:
- 06/19/20 17:53:36 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs
r17226 r17614 381 381 } 382 382 private void UpdateCrossovers() { 383 ICrossover oldCrossover = CrossoverParameter.Value; 384 CrossoverParameter.ValidValues.Clear(); 385 ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault(); 386 387 foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name)) 388 CrossoverParameter.ValidValues.Add(crossover); 389 390 if (oldCrossover != null) { 391 ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType()); 392 if (crossover != null) CrossoverParameter.Value = crossover; 393 else oldCrossover = null; 394 } 395 if (oldCrossover == null && defaultCrossover != null) 396 CrossoverParameter.Value = defaultCrossover; 397 } 383 CrossoverParameter.Repopulate(Problem.Operators); 384 } 385 398 386 private void UpdateMutators() { 399 IManipulator oldMutator = MutatorParameter.Value; 400 MutatorParameter.ValidValues.Clear(); 401 IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault(); 402 403 foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) 404 MutatorParameter.ValidValues.Add(mutator); 405 406 if (oldMutator != null) { 407 IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); 408 if (mutator != null) MutatorParameter.Value = mutator; 409 else oldMutator = null; 410 } 411 412 if (oldMutator == null && defaultMutator != null) 413 MutatorParameter.Value = defaultMutator; 387 MutatorParameter.Repopulate(Problem.Operators); 414 388 } 415 389 private void UpdateAnalyzers() { -
branches/2521_ProblemRefactoring/HeuristicLab.Core/3.3/Interfaces/IConstrainedValueParameter.cs
r17461 r17614 29 29 30 30 void Populate(IEnumerable<IItem> items); 31 void Repopulate(IEnumerable<IItem> items); 31 32 } 32 33 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorEncoding.cs
r17587 r17614 46 46 public BinaryVectorEncoding(int length) : this("BinaryVector", length) { } 47 47 public BinaryVectorEncoding(string name, int length) 48 : base(name, length) { 49 SolutionCreator = new RandomBinaryVectorCreator(); 50 48 : base(name, length) { 51 49 DiscoverOperators(); 52 50 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEncoding.cs
r17587 r17614 78 78 Parameters.Add(BoundsParameter); 79 79 80 SolutionCreator = new UniformRandomIntegerVectorCreator();81 80 DiscoverOperators(); 82 81 RegisterEventHandlers(); … … 99 98 Parameters.Add(BoundsParameter); 100 99 101 SolutionCreator = new UniformRandomIntegerVectorCreator();102 100 DiscoverOperators(); 103 101 RegisterEventHandlers(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageEncoding.cs
r17587 r17614 49 49 public LinearLinkageEncoding(string name, int length) 50 50 : base(name, length) { 51 SolutionCreator = new RandomLinearLinkageCreator();52 51 DiscoverOperators(); 53 52 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationEncoding.cs
r17587 r17614 70 70 Parameters.Add(PermutationTypeParameter); 71 71 72 SolutionCreator = new RandomPermutationCreator();73 72 DiscoverOperators(); 74 73 RegisterParameterEvents(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorEncoding.cs
r17587 r17614 75 75 Parameters.Add(BoundsParameter); 76 76 77 SolutionCreator = new UniformRandomRealVectorCreator();78 77 RegisterParameterEvents(); 79 78 DiscoverOperators(); … … 94 93 Parameters.Add(BoundsParameter); 95 94 96 SolutionCreator = new UniformRandomRealVectorCreator();97 95 DiscoverOperators(); 98 96 RegisterParameterEvents(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/JSMRandomCreator.cs
r17461 r17614 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 25 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 using HEAL.Attic;28 28 29 29 namespace HeuristicLab.Encodings.ScheduleEncoding { 30 30 [Item("JobSequenceMatrixCreator", "Creator class used to create Job Sequence Matrix solutions for standard JobShop scheduling problems.")] 31 31 [StorableType("F8053C69-31C2-4E05-8FA0-5AED15FAF804")] 32 public class JSMRandomCreator : ScheduleCreator<JSM>, I StochasticOperator {32 public class JSMRandomCreator : ScheduleCreator<JSM>, IJSMOperator, IStochasticOperator { 33 33 34 34 public ILookupParameter<IRandom> RandomParameter { -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/JobSequenceMatrixEncoding.cs
r17461 r17614 43 43 public JobSequenceMatrixEncoding() 44 44 : base("JSM") { 45 SolutionCreator = new JSMRandomCreator();46 45 Decoder = new JSMDecoder(); 47 46 DiscoverOperators(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/PWRRandomCreator.cs
r17461 r17614 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Parameters; 26 using HEAL.Attic;27 27 28 28 namespace HeuristicLab.Encodings.ScheduleEncoding { 29 29 [Item("PermutationWithRepetitionRandomCreator", "Creates PWR-individuals at random.")] 30 30 [StorableType("6E753916-C0FD-4585-B6A6-47FD66ED098F")] 31 public class PWRRandomCreator : ScheduleCreator<PWR>, I StochasticOperator {31 public class PWRRandomCreator : ScheduleCreator<PWR>, IPWROperator, IStochasticOperator { 32 32 33 33 public ILookupParameter<IRandom> RandomParameter { -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/PermutationWithRepetitionEncoding.cs
r17461 r17614 42 42 public PermutationWithRepetitionEncoding() 43 43 : base("PWR") { 44 SolutionCreator = new PWRRandomCreator();45 44 Decoder = new PWRDecoder(); 46 45 DiscoverOperators(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/PriorityRulesVector/PRVRandomCreator.cs
r17461 r17614 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Parameters; 26 using HEAL.Attic;27 27 28 28 namespace HeuristicLab.Encodings.ScheduleEncoding { 29 29 [Item("PriorityRulesRandomCreator", "Creator class used to create PRV encoding objects for scheduling problems.")] 30 30 [StorableType("5FF2A11E-86F9-4A8B-8E1C-713D6801506C")] 31 public class PRVRandomCreator : ScheduleCreator<PRV>, I StochasticOperator {31 public class PRVRandomCreator : ScheduleCreator<PRV>, IPRVOperator, IStochasticOperator { 32 32 33 33 [Storable] -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/PriorityRulesVector/PriorityRulesVectorEncoding.cs
r17461 r17614 65 65 Parameters.Add(numberOfRulesParameter); 66 66 67 SolutionCreator = new PRVRandomCreator();68 67 Decoder = new PRVDecoder(); 69 68 DiscoverOperators(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding.cs
r17567 r17614 161 161 } 162 162 163 164 163 public override void ConfigureOperators(IEnumerable<IItem> operators) { 165 164 base.ConfigureOperators(operators); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/DirectScheduleEncoding.cs
r17461 r17614 43 43 public DirectScheduleEncoding() 44 44 : base("Schedule") { 45 SolutionCreator = new DirectScheduleRandomCreator();46 45 Decoder = new DirectScheduleDecoder(); 47 46 DiscoverOperators(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeEncoding.cs
r17570 r17614 177 177 Parameters.Add(functionArgumentsParameter); 178 178 179 SolutionCreator = new ProbabilisticTreeCreator();180 179 RegisterParameterEvents(); 181 180 DiscoverOperators(); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeMultiObjectiveProblem.cs
r17315 r17614 27 27 using HeuristicLab.Common; 28 28 using HeuristicLab.Core; 29 using HeuristicLab.Data; 29 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Parameters; 30 32 31 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 34 [StorableType("f4819c68-b6fc-469f-bcb5-cb5b2a9d8aff")] 33 35 public abstract class SymbolicExpressionTreeMultiObjectiveProblem : MultiObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { 36 [Storable] private ReferenceParameter<IntValue> TreeLengthRefParameter { get; set; } 37 [Storable] private ReferenceParameter<IntValue> TreeDepthRefParameter { get; set; } 38 [Storable] private ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; set; } 39 40 public int TreeLength { 41 get => TreeLengthRefParameter.Value.Value; 42 set => TreeLengthRefParameter.Value.Value = value; 43 } 44 45 public int TreeDepth { 46 get => TreeDepthRefParameter.Value.Value; 47 set => TreeDepthRefParameter.Value.Value = value; 48 } 49 50 public ISymbolicExpressionGrammar Grammar { 51 get => GrammarRefParameter.Value; 52 set => GrammarRefParameter.Value = value; 53 } 34 54 35 55 // persistence … … 37 57 protected SymbolicExpressionTreeMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { } 38 58 [StorableHook(HookType.AfterDeserialization)] 39 private void AfterDeserialization() { } 59 private void AfterDeserialization() { 60 RegisterEventHandlers(); 61 } 40 62 41 63 … … 43 65 protected SymbolicExpressionTreeMultiObjectiveProblem(SymbolicExpressionTreeMultiObjectiveProblem original, Cloner cloner) 44 66 : base(original, cloner) { 67 TreeLengthRefParameter = cloner.Clone(original.TreeLengthRefParameter); 68 TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter); 69 GrammarRefParameter = cloner.Clone(original.GrammarRefParameter); 70 RegisterEventHandlers(); 45 71 } 46 72 … … 48 74 : base(encoding) { 49 75 EncodingParameter.ReadOnly = true; 76 Parameters.Add(TreeLengthRefParameter = new ReferenceParameter<IntValue>("TreeLength", "The maximum amount of nodes.", Encoding.TreeLengthParameter)); 77 Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter)); 78 Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter)); 79 80 Parameterize(); 81 RegisterEventHandlers(); 50 82 } 51 83 … … 59 91 } 60 92 61 protected override void OnEncodingChanged() {62 base.OnEncodingChanged();63 Parameterize();64 }65 66 93 private void Parameterize() { 67 94 foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) { … … 70 97 } 71 98 } 99 100 private void RegisterEventHandlers() { 101 IntValueParameterChangeHandler.Create(TreeLengthRefParameter, TreeLengthOnChanged); 102 IntValueParameterChangeHandler.Create(TreeDepthRefParameter, TreeDepthOnChanged); 103 ParameterChangeHandler<ISymbolicExpressionGrammar>.Create(GrammarRefParameter, GrammarOnChanged); 104 } 105 106 protected virtual void TreeLengthOnChanged() { } 107 protected virtual void TreeDepthOnChanged() { } 108 protected virtual void GrammarOnChanged() { } 72 109 } 73 110 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs
r17520 r17614 29 29 using HeuristicLab.Data; 30 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Parameters; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 33 34 [StorableType("A1B9F4C8-5E29-493C-A483-2AC68453BC63")] 34 35 public abstract class SymbolicExpressionTreeProblem : SingleObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { 36 [Storable] private ReferenceParameter<IntValue> TreeLengthRefParameter { get; set; } 37 [Storable] private ReferenceParameter<IntValue> TreeDepthRefParameter { get; set; } 38 [Storable] private ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; set; } 39 40 public int TreeLength { 41 get => TreeLengthRefParameter.Value.Value; 42 set => TreeLengthRefParameter.Value.Value = value; 43 } 44 45 public int TreeDepth { 46 get => TreeDepthRefParameter.Value.Value; 47 set => TreeDepthRefParameter.Value.Value = value; 48 } 49 50 public ISymbolicExpressionGrammar Grammar { 51 get => GrammarRefParameter.Value; 52 set => GrammarRefParameter.Value = value; 53 } 35 54 36 55 // persistence … … 38 57 protected SymbolicExpressionTreeProblem(StorableConstructorFlag _) : base(_) { } 39 58 [StorableHook(HookType.AfterDeserialization)] 40 private void AfterDeserialization() { } 41 59 private void AfterDeserialization() { 60 RegisterEventHandlers(); 61 } 42 62 43 63 // cloning 44 64 protected SymbolicExpressionTreeProblem(SymbolicExpressionTreeProblem original, Cloner cloner) 45 65 : base(original, cloner) { 66 TreeLengthRefParameter = cloner.Clone(original.TreeLengthRefParameter); 67 TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter); 68 GrammarRefParameter = cloner.Clone(original.GrammarRefParameter); 69 RegisterEventHandlers(); 46 70 } 47 71 … … 50 74 : base(encoding) { 51 75 EncodingParameter.ReadOnly = true; 76 Parameters.Add(TreeLengthRefParameter = new ReferenceParameter<IntValue>("TreeLength", "The maximum amount of nodes.", Encoding.TreeLengthParameter)); 77 Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter)); 78 Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter)); 79 80 Parameterize(); 81 RegisterEventHandlers(); 52 82 } 53 83 … … 73 103 } 74 104 75 protected override void OnEncodingChanged() {76 base.OnEncodingChanged();77 Parameterize();78 }79 80 105 private void Parameterize() { 81 106 foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) { … … 84 109 } 85 110 } 111 private void RegisterEventHandlers() { 112 IntValueParameterChangeHandler.Create(TreeLengthRefParameter, TreeLengthOnChanged); 113 IntValueParameterChangeHandler.Create(TreeDepthRefParameter, TreeDepthOnChanged); 114 ParameterChangeHandler<ISymbolicExpressionGrammar>.Create(GrammarRefParameter, GrammarOnChanged); 115 } 116 117 protected virtual void TreeLengthOnChanged() { } 118 protected virtual void TreeDepthOnChanged() { } 119 protected virtual void GrammarOnChanged() { } 86 120 } 87 121 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/EngineAlgorithm.cs
r17517 r17614 185 185 protected override void DeregisterProblemEvents() { 186 186 Problem.Reset -= new EventHandler(Problem_Reset); 187 Problem.OperatorsChanged -= new EventHandler(Problem_OperatorsChanged); 187 188 } 188 189 protected override void RegisterProblemEvents() { 189 190 Problem.Reset += new EventHandler(Problem_Reset); 191 Problem.OperatorsChanged += new EventHandler(Problem_OperatorsChanged); 190 192 } 191 193 protected virtual void Problem_OperatorsChanged(object sender, EventArgs e) { } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/CombinedEncoding.cs
r17226 r17614 55 55 : base("CombinedEncoding") { 56 56 encodings = new ItemCollection<IEncoding>(); 57 SolutionCreator = new MultiEncodingCreator() { SolutionParameter = { ActualName = Name } };58 57 foreach (var @operator in ApplicationManager.Manager.GetInstances<IMultiEncodingOperator>()) { 59 58 @operator.SolutionParameter.ActualName = Name; -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Encoding.cs
r17571 r17614 52 52 encodingOperators.Clear(); 53 53 foreach (var op in value) encodingOperators.Add(op); 54 55 ISolutionCreator<TEncodedSolution> newSolutionCreator = (ISolutionCreator<TEncodedSolution>)encodingOperators.FirstOrDefault(o => o.GetType() == SolutionCreator.GetType()) ??56 encodingOperators.OfType<ISolutionCreator<TEncodedSolution>>().First();57 SolutionCreator = newSolutionCreator;58 54 OnOperatorsChanged(); 59 }60 }61 62 public IValueParameter SolutionCreatorParameter {63 get { return (IValueParameter)Parameters[Name + ".SolutionCreator"]; }64 }65 66 ISolutionCreator IEncoding.SolutionCreator {67 get { return SolutionCreator; }68 }69 public ISolutionCreator<TEncodedSolution> SolutionCreator {70 get { return (ISolutionCreator<TEncodedSolution>)SolutionCreatorParameter.Value; }71 set {72 if (value == null) throw new ArgumentNullException("SolutionCreator must not be null.");73 encodingOperators.Remove(SolutionCreator);74 encodingOperators.Add(value);75 SolutionCreatorParameter.Value = value;76 OnSolutionCreatorChanged();77 55 } 78 56 } … … 82 60 protected Encoding(StorableConstructorFlag _) : base(_) { } 83 61 [StorableHook(HookType.AfterDeserialization)] 84 private void AfterDeserialization() { 85 RegisterEventHandlers(); 86 } 62 private void AfterDeserialization() { } 87 63 88 64 protected Encoding(Encoding<TEncodedSolution> original, Cloner cloner) 89 65 : base(original, cloner) { 90 66 encodingOperators = cloner.Clone(original.encodingOperators); 91 92 RegisterEventHandlers();93 67 } 94 68 95 69 protected Encoding(string name) 96 70 : base(name) { 97 Parameters.Add(new ValueParameter<ISolutionCreator<TEncodedSolution>>(name + ".SolutionCreator", "The operator to create a solution.") {98 ReadOnly = true99 });100 71 Parameters.Add(new FixedValueParameter<ReadOnlyItemSet<IOperator>>(name + ".Operators", "The operators that the encoding specifies.", encodingOperators.AsReadOnly()) { 101 72 GetsCollected = false, ReadOnly = true 102 73 }); 103 104 RegisterEventHandlers();105 }106 107 private void RegisterEventHandlers() {108 SolutionCreatorParameter.ValueChanged += (o, e) => OnSolutionCreatorChanged();109 74 } 110 75 … … 137 102 } 138 103 139 public event EventHandler SolutionCreatorChanged;140 protected virtual void OnSolutionCreatorChanged() {141 ConfigureOperator(SolutionCreator);142 var handler = SolutionCreatorChanged;143 if (handler != null) handler(this, EventArgs.Empty);144 }145 146 104 public event EventHandler OperatorsChanged; 147 105 protected virtual void OnOperatorsChanged() { -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IEncoding.cs
r17226 r17614 28 28 [StorableType("d70b2675-246c-489c-a91b-b2e19a1616a3")] 29 29 public interface IEncoding : IParameterizedNamedItem { 30 IValueParameter SolutionCreatorParameter { get; }31 ISolutionCreator SolutionCreator { get; }32 33 30 IEnumerable<IOperator> Operators { get; set; } 34 31 … … 37 34 38 35 event EventHandler OperatorsChanged; 39 event EventHandler SolutionCreatorChanged;40 36 } 41 37 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IProblem.cs
r17612 r17614 40 40 //TODO Intermediate class for compatibility 41 41 //TODO move members to generic IProblem after every problem used the new architecture 42 //TODO ABE: We can maybe use it as non-generic interface that exports IEncoding Encoding { get; } 43 //TODO ABE: and which is explicitely implemented in some base class 42 44 public interface IEncodedProblem : IProblem { 43 45 IEnumerable<IItem> Operators { get; } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCreator.cs
r17226 r17614 20 20 #endregion 21 21 22 using System;23 using System.Linq;24 22 using HEAL.Attic; 25 23 using HeuristicLab.Common; … … 57 55 } 58 56 59 public override void AddEncoding(IEncoding encoding) {60 base.AddEncoding(encoding);61 var parameter = GetParameter(encoding);62 parameter.Value = encoding.SolutionCreator;63 encoding.SolutionCreatorChanged += Encoding_SolutionCreatorChanged;64 }65 66 public override bool RemoveEncoding(IEncoding encoding) {67 var success = base.RemoveEncoding(encoding);68 encoding.SolutionCreatorChanged -= Encoding_SolutionCreatorChanged;69 return success;70 }71 72 private void Encoding_SolutionCreatorChanged(object sender, EventArgs e) {73 var encoding = (IEncoding)sender;74 var parameter = GetParameter(encoding);75 76 var oldCreator = parameter.ValidValues.Single(creator => creator.GetType() == encoding.SolutionCreator.GetType());77 parameter.ValidValues.Remove(oldCreator);78 parameter.ValidValues.Add(encoding.SolutionCreator);79 parameter.Value = encoding.SolutionCreator;80 }81 82 57 83 58 public override IOperation InstrumentedApply() { -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs
r17612 r17614 37 37 where TEvaluator : class, IEvaluator { 38 38 39 [Storable] protected ConstrainedValueParameter<ISolutionCreator> SolutionCreatorParameter { get; private set; } 39 40 40 41 //TODO remove parameter for encoding? … … 52 53 } 53 54 54 55 ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator { 56 get { return Encoding.SolutionCreator; } 57 } 58 IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter { 59 get { return Encoding.SolutionCreatorParameter; } 60 } 55 ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator { get => SolutionCreatorParameter.Value; } 56 IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter { get => SolutionCreatorParameter; } 57 61 58 event EventHandler IHeuristicOptimizationProblem.SolutionCreatorChanged { 62 59 add { 63 if (Encoding != null) Encoding.SolutionCreatorChanged += value;60 SolutionCreatorParameter.ValueChanged += value; 64 61 } 65 62 remove { 66 if (Encoding != null) Encoding.SolutionCreatorChanged -= value;63 SolutionCreatorParameter.ValueChanged -= value; 67 64 } 68 65 } … … 106 103 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.", encoding) { Hidden = true }); 107 104 Parameters.Add(new ValueParameter<TEvaluator>("Evaluator", "The operator used to evaluate a solution.") { Hidden = true }); 105 Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "The operator used to create a solution.")); 108 106 109 107 oldEncoding = Encoding; … … 116 114 : base(original, cloner) { 117 115 oldEncoding = cloner.Clone(original.oldEncoding); 116 SolutionCreatorParameter = cloner.Clone(original.SolutionCreatorParameter); 118 117 RegisterEvents(); 119 118 } … … 124 123 private void AfterDeserialization() { 125 124 oldEncoding = Encoding; 125 // TODO: remove below 126 if (SolutionCreatorParameter == null) Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "The operator used to create a solution.")); 127 126 128 RegisterEvents(); 127 129 } … … 157 159 158 160 Encoding.ConfigureOperators(Operators); 161 162 SolutionCreatorParameter.Repopulate(GetOperators()); 159 163 //var multiEncoding = Encoding as MultiEncoding; 160 164 //if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged; -
branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/ConstrainedValueParameter.cs
r17226 r17614 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HEAL.Attic; … … 57 58 } 58 59 60 public override void Repopulate(IEnumerable<IItem> items) { 61 var itemsOfT = items.OfType<T>().ToList(); 62 T oldItem = Value; 63 ValidValues.Clear(); 64 T defaultItem = itemsOfT.FirstOrDefault(); 65 66 foreach (T i in itemsOfT.OrderBy(x => x is INamedItem ? ((INamedItem)x).Name : x.ItemName)) 67 ValidValues.Add(i); 68 69 if (oldItem != null) { 70 T item = ValidValues.FirstOrDefault(x => x.GetType() == oldItem.GetType()); 71 if (item != null) Value = item; 72 else oldItem = null; 73 } 74 if (oldItem == null && defaultItem != null) 75 Value = defaultItem; 76 } 77 59 78 protected override void ValidValues_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) { 60 79 if (Value == null) Value = ValidValues.First(); -
branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/OptionalConstrainedValueParameter.cs
r17461 r17614 175 175 } 176 176 177 public virtual void Repopulate(IEnumerable<IItem> items) { 178 var itemsOfT = items.OfType<T>().ToList(); 179 T oldItem = Value; 180 ValidValues.Clear(); 181 182 foreach (T i in itemsOfT.OrderBy(x => x is INamedItem ? ((INamedItem)x).Name : x.ItemName)) 183 ValidValues.Add(i); 184 185 if (oldItem != null) { 186 T item = ValidValues.FirstOrDefault(x => x.GetType() == oldItem.GetType()); 187 if (item != null) Value = item; 188 } 189 } 190 177 191 [StorableHook(HookType.AfterDeserialization)] 178 192 private void AfterDeserialization() { -
branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/ParameterChangeHandler.cs
r17587 r17614 25 25 26 26 namespace HeuristicLab.Parameters { 27 public abstractclass ParameterChangeHandler<TItem> where TItem : class, IItem {27 public class ParameterChangeHandler<TItem> where TItem : class, IItem { 28 28 protected Action handler; 29 29 … … 37 37 handler(); 38 38 } 39 40 public static ParameterChangeHandler<TItem> Create(IValueParameter<TItem> parameter, Action handler) { 41 return new ParameterChangeHandler<TItem>(parameter, handler); 42 } 39 43 } 40 44 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblemInstances.cs
r17570 r17614 41 41 [StorableType("4ea0ded8-4451-4011-b88e-4d0680721b01")] 42 42 public sealed class SingleObjectiveBinaryVectorExternalEvaluationProblem : ExternalEvaluationProblem<BinaryVectorEncoding, BinaryVector> { 43 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 44 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 43 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 45 44 46 45 public int Dimension { … … 72 71 [StorableType("46465e8c-11d8-4d02-8c45-de41a08db7fa")] 73 72 public sealed class SingleObjectiveIntegerVectorExternalEvaluationProblem : ExternalEvaluationProblem<IntegerVectorEncoding, IntegerVector> { 74 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 75 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 76 [Storable] private ReferenceParameter<IntMatrix> BoundsRefParameter; 77 public IValueParameter<IntMatrix> BoundsParameter => BoundsRefParameter; 73 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 74 [Storable] private ReferenceParameter<IntMatrix> BoundsRefParameter { get; set; } 78 75 79 76 public int Dimension { … … 112 109 [StorableType("637f091f-6601-494e-bafb-2a8ea474210c")] 113 110 public sealed class SingleObjectiveRealVectorExternalEvaluationProblem : ExternalEvaluationProblem<RealVectorEncoding, RealVector> { 114 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 115 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 116 [Storable] private ReferenceParameter<DoubleMatrix> BoundsRefParameter; 117 public IValueParameter<DoubleMatrix> BoundsParameter => BoundsRefParameter; 111 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 112 [Storable] private ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; set; } 118 113 119 114 public int Dimension { … … 152 147 [StorableType("ad9d45f8-b97e-49a7-b3d2-487d9a2cbdf9")] 153 148 public sealed class SingleObjectivePermutationExternalEvaluationProblem : ExternalEvaluationProblem<PermutationEncoding, Permutation> { 154 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 155 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 149 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 156 150 157 151 public int Dimension { … … 183 177 [StorableType("9b3ee4a8-7076-4edd-ae7e-4188bc49aaa3")] 184 178 public sealed class SingleObjectiveSymbolicExpressionTreeExternalEvaluationProblem : ExternalEvaluationProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { 179 [Storable] private ReferenceParameter<IntValue> TreeLengthRefParameter { get; set; } 180 [Storable] private ReferenceParameter<IntValue> TreeDepthRefParameter { get; set; } 181 [Storable] private ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; set; } 182 183 public int TreeLength { 184 get => TreeLengthRefParameter.Value.Value; 185 set => TreeLengthRefParameter.Value.Value = value; 186 } 187 188 public int TreeDepth { 189 get => TreeDepthRefParameter.Value.Value; 190 set => TreeDepthRefParameter.Value.Value = value; 191 } 192 193 public ISymbolicExpressionGrammar Grammar { 194 get => GrammarRefParameter.Value; 195 set => GrammarRefParameter.Value = value; 196 } 185 197 186 198 [StorableConstructor] 187 199 private SingleObjectiveSymbolicExpressionTreeExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { } 188 private SingleObjectiveSymbolicExpressionTreeExternalEvaluationProblem(SingleObjectiveSymbolicExpressionTreeExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { } 200 private SingleObjectiveSymbolicExpressionTreeExternalEvaluationProblem(SingleObjectiveSymbolicExpressionTreeExternalEvaluationProblem original, Cloner cloner) 201 : base(original, cloner) { 202 TreeLengthRefParameter = cloner.Clone(original.TreeLengthRefParameter); 203 TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter); 204 GrammarRefParameter = cloner.Clone(original.GrammarRefParameter); 205 } 189 206 190 207 public SingleObjectiveSymbolicExpressionTreeExternalEvaluationProblem() 191 208 : base(new SymbolicExpressionTreeEncoding()) { 192 // TODO: Change to ReferenceParameter 193 var lengthParameter = new FixedValueParameter<IntValue>("TreeLength", "The total amount of nodes.", new IntValue(50)); 194 Parameters.Add(lengthParameter); 195 Encoding.TreeLengthParameter = lengthParameter; 196 var depthParameter = new FixedValueParameter<IntValue>("TreeDepth", "The depth of the tree.", new IntValue(10)); 197 Parameters.Add(depthParameter); 198 Encoding.TreeDepthParameter = depthParameter; 209 Parameters.Add(TreeLengthRefParameter = new ReferenceParameter<IntValue>("TreeLength", "The maximum amount of nodes.", Encoding.TreeLengthParameter)); 210 Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter)); 211 Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter)); 199 212 // TODO: Add and parameterize additional operators, 200 213 } … … 210 223 [StorableType("945a35d9-89a8-4423-9ea0-21829ac68887")] 211 224 public sealed class SingleObjectiveLinearLinkageExternalEvaluationProblem : ExternalEvaluationProblem<LinearLinkageEncoding, LinearLinkage> { 212 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 213 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 225 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 214 226 215 227 public int Dimension { … … 258 270 [StorableType("f14c7e88-b74d-4cad-ae55-83daf7b4c288")] 259 271 public sealed class MultiObjectiveBinaryVectorExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<BinaryVectorEncoding, BinaryVector> { 260 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 261 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 272 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 262 273 263 274 public int Dimension { … … 289 300 [StorableType("90a82c2f-6c37-4ffd-8495-bee278c583d3")] 290 301 public sealed class MultiObjectiveIntegerVectorExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<IntegerVectorEncoding, IntegerVector> { 291 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 292 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 293 [Storable] private ReferenceParameter<IntMatrix> BoundsRefParameter; 294 public IValueParameter<IntMatrix> BoundsParameter => BoundsRefParameter; 302 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 303 [Storable] private ReferenceParameter<IntMatrix> BoundsRefParameter { get; set; } 295 304 296 305 public int Dimension { … … 329 338 [StorableType("38e1d068-d569-48c5-bad6-cbdd685b7c6b")] 330 339 public sealed class MultiObjectiveRealVectorExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<RealVectorEncoding, RealVector> { 331 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 332 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 333 [Storable] private ReferenceParameter<DoubleMatrix> BoundsRefParameter; 334 public IValueParameter<DoubleMatrix> BoundsParameter => BoundsRefParameter; 340 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 341 [Storable] private ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; set; } 335 342 336 343 public int Dimension { … … 369 376 [StorableType("f1b265b0-ac7c-4c36-b346-5b3f2c37694b")] 370 377 public sealed class MultiObjectivePermutationExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<PermutationEncoding, Permutation> { 371 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 372 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 378 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 373 379 374 380 public int Dimension { … … 400 406 [StorableType("fb6834e2-2d56-4711-a3f8-5e0ab55cd040")] 401 407 public sealed class MultiObjectiveSymbolicExpressionTreeExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { 408 [Storable] private ReferenceParameter<IntValue> TreeLengthRefParameter { get; set; } 409 [Storable] private ReferenceParameter<IntValue> TreeDepthRefParameter { get; set; } 410 [Storable] private ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; set; } 411 412 public int TreeLength { 413 get => TreeLengthRefParameter.Value.Value; 414 set => TreeLengthRefParameter.Value.Value = value; 415 } 416 417 public int TreeDepth { 418 get => TreeDepthRefParameter.Value.Value; 419 set => TreeDepthRefParameter.Value.Value = value; 420 } 421 422 public ISymbolicExpressionGrammar Grammar { 423 get => GrammarRefParameter.Value; 424 set => GrammarRefParameter.Value = value; 425 } 402 426 403 427 [StorableConstructor] 404 428 private MultiObjectiveSymbolicExpressionTreeExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { } 405 private MultiObjectiveSymbolicExpressionTreeExternalEvaluationProblem(MultiObjectiveSymbolicExpressionTreeExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { } 429 private MultiObjectiveSymbolicExpressionTreeExternalEvaluationProblem(MultiObjectiveSymbolicExpressionTreeExternalEvaluationProblem original, Cloner cloner) 430 : base(original, cloner) { 431 TreeLengthRefParameter = cloner.Clone(original.TreeLengthRefParameter); 432 TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter); 433 GrammarRefParameter = cloner.Clone(original.GrammarRefParameter); 434 } 406 435 407 436 public MultiObjectiveSymbolicExpressionTreeExternalEvaluationProblem() 408 437 : base(new SymbolicExpressionTreeEncoding()) { 409 // TODO: Change to ReferenceParameter 410 var lengthParameter = new FixedValueParameter<IntValue>("TreeLength", "The total amount of nodes.", new IntValue(50)); 411 Parameters.Add(lengthParameter); 412 Encoding.TreeLengthParameter = lengthParameter; 413 var depthParameter = new FixedValueParameter<IntValue>("TreeDepth", "The depth of the tree.", new IntValue(10)); 414 Parameters.Add(depthParameter); 415 Encoding.TreeDepthParameter = depthParameter; 438 Parameters.Add(TreeLengthRefParameter = new ReferenceParameter<IntValue>("TreeLength", "The maximum amount of nodes.", Encoding.TreeLengthParameter)); 439 Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter)); 440 Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter)); 416 441 // TODO: Add and parameterize additional operators, 417 442 } … … 427 452 [StorableType("ed0c1129-651d-465f-87b0-f412f3e3b3d1")] 428 453 public sealed class MultiObjectiveLinearLinkageExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<LinearLinkageEncoding, LinearLinkage> { 429 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter; 430 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter; 454 [Storable] private ReferenceParameter<IntValue> DimensionRefParameter { get; set; } 431 455 432 456 public int Dimension { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs
r17612 r17614 165 165 166 166 private void InitializeOperators() { 167 Encoding.SolutionCreator = new GreedyOrienteeringTourCreator() { 167 ISolutionCreator creator; 168 SolutionCreatorParameter.ValidValues.Add(creator = new GreedyOrienteeringTourCreator() { 168 169 OrienteeringProblemDataParameter = { ActualName = OrienteeringProblemDataParameter.Name } 169 }; 170 }); 171 SolutionCreatorParameter.Value = creator; 172 170 173 Operators.Add(new OrienteeringLocalImprovementOperator() { 171 174 OrienteeringProblemDataParameter = { ActualName = OrienteeringProblemDataParameter.Name } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r17587 r17614 186 186 foreach (var c in calcs) { 187 187 // TODO: unified encoding parameters 188 c.SolutionVariableName = ((IRealVectorSolutionOperator)Encoding.SolutionCreator).RealVectorParameter.ActualName;188 c.SolutionVariableName = Encoding.Name; 189 189 c.QualityVariableName = Evaluator.QualityParameter.ActualName; 190 190 op.SimilarityCalculatorParameter.ValidValues.Add(c); … … 200 200 foreach (var op in Operators.OfType<IRealVectorParticleCreator>()) { 201 201 // TODO: unified encoding parameters 202 op.RealVectorParameter.ActualName = ((IRealVectorSolutionOperator)Encoding.SolutionCreator).RealVectorParameter.ActualName;202 op.RealVectorParameter.ActualName = Encoding.Name; 203 203 op.RealVectorParameter.Hidden = true; 204 204 op.BoundsParameter.ActualName = BoundsRefParameter.Name; … … 207 207 foreach (var op in Operators.OfType<IRealVectorParticleUpdater>()) { 208 208 // TODO: unified encoding parameters 209 op.RealVectorParameter.ActualName = ((IRealVectorSolutionOperator)Encoding.SolutionCreator).RealVectorParameter.ActualName;209 op.RealVectorParameter.ActualName = Encoding.Name; 210 210 op.RealVectorParameter.Hidden = true; 211 211 op.BoundsParameter.ActualName = BoundsRefParameter.Name;
Note: See TracChangeset
for help on using the changeset viewer.