Changeset 11996 for trunk/sources
- Timestamp:
- 02/12/15 21:49:06 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/BasicProblem.cs
r11982 r11996 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 Parameterize(); 69 70 RegisterEvents(); 70 71 } … … 91 92 92 93 protected virtual void OnEncodingChanged() { 94 Parameterize(); 95 96 OnOperatorsChanged(); 97 OnReset(); 98 } 99 100 private void Parameterize() { 93 101 if (oldEncoding != null) { 94 102 AdaptEncodingOperators(oldEncoding, Encoding); … … 107 115 Encoding.SolutionCreator); 108 116 Parameters.Remove(SolutionCreatorParameter); 109 Parameters.Add(solutionCreatorParam); 110 ((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged; 117 Parameters.Add(solutionCreatorParam); 118 ((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged; 111 119 112 120 var multiEncoding = Encoding as MultiEncoding; 113 121 if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged; 114 115 OnOperatorsChanged();116 OnReset();117 122 } 118 123 -
trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs
r11970 r11996 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); … … 57 57 public abstract double[] Evaluate(Individual individual, IRandom random); 58 58 public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { } 59 60 protected override void OnEncodingChanged() {61 base.OnEncodingChanged();62 Parameters["Maximization"].ActualValue = new BoolArray(Maximization);63 }64 59 65 60 protected override void OnOperatorsChanged() { -
trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs
r11990 r11996 59 59 protected SingleObjectiveBasicProblem() 60 60 : base() { 61 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 }); 62 62 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.")); 63 63 … … 82 82 public virtual IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) { 83 83 return Enumerable.Empty<Individual>(); 84 }85 86 87 protected override void OnEncodingChanged() {88 base.OnEncodingChanged();89 var max = (BoolValue)Parameters["Maximization"].ActualValue;90 max.Value = Maximization;91 84 } 92 85 -
trunk/sources/HeuristicLab.Problems.Binary/3.3/BinaryProblem.cs
r11990 r11996 23 23 24 24 using System; 25 using System.Linq; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 67 68 } 68 69 70 public abstract double Evaluate(BinaryVector vector, IRandom random); 69 71 public sealed override double Evaluate(Individual individual, IRandom random) { 70 72 return Evaluate(individual.BinaryVector(), random); 71 73 } 72 74 73 public abstract double Evaluate(BinaryVector vector, IRandom random); 75 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { 76 base.Analyze(individuals, qualities, results, random); 77 var best = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderByDescending(z => z.Quality).First(); 78 if (!results.ContainsKey("Best Solution")) { 79 results.Add(new Result("Best Solution", typeof(BinaryVector))); 80 } 81 results["Best Solution"].Value = best.Individual.BinaryVector(); 82 } 74 83 75 84 protected override void OnEncodingChanged() { -
trunk/sources/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs
r11987 r11996 66 66 : base() { 67 67 Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(7))); 68 Length = 49;68 Encoding.Length = 49; 69 69 } 70 70 -
trunk/sources/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs
r11987 r11996 48 48 public HIFFProblem() 49 49 : base() { 50 Length = 64;50 Encoding.Length = 64; 51 51 } 52 52 // In the GECCO paper, Section 4.1 -
trunk/sources/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs
r11990 r11996 39 39 public OneMaxProblem() 40 40 : base() { 41 Encoding = new BinaryVectorEncoding("BinaryVector", 10);42 BestKnownQuality = Length;41 Encoding.Length = 10; 42 BestKnownQuality = Encoding.Length; 43 43 } 44 44 … … 49 49 public override IDeepCloneable Clone(Cloner cloner) { 50 50 return new OneMaxProblem(this, cloner); 51 }52 53 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {54 base.Analyze(individuals, qualities, results, random);55 var best = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderByDescending(z => z.Quality).First();56 if (!results.ContainsKey("Best Solution")) {57 results.Add(new Result("Best Solution", typeof(BinaryVector)));58 }59 results["Best Solution"].Value = best.Individual.BinaryVector();60 51 } 61 52 -
trunk/sources/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs
r11961 r11996 24 24 using HeuristicLab.Common.Resources; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Parameters; … … 73 74 74 75 private void OnProblemDefinitionChanged() { 76 if (Parameters.ContainsKey("Maximization")) Parameters.Remove("Maximization"); 77 Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly())); 78 75 79 Encoding = ProblemDefinition.Encoding; 76 80 OnOperatorsChanged(); -
trunk/sources/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r11984 r11996 26 26 using HeuristicLab.Common.Resources; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 28 29 using HeuristicLab.Optimization; 29 30 using HeuristicLab.Parameters; … … 76 77 77 78 private void OnProblemDefinitionChanged() { 79 if (Parameters.ContainsKey("Maximization")) Parameters.Remove("Maximization"); 80 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true }); 81 78 82 Encoding = ProblemDefinition.Encoding; 83 OnOperatorsChanged(); 84 OnReset(); 79 85 } 80 86
Note: See TracChangeset
for help on using the changeset viewer.