Changeset 8005
- Timestamp:
- 06/14/12 10:28:38 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/NKLandscape.cs
r8002 r8005 20 20 [Creatable("Problems")] 21 21 [StorableClass] 22 public sealed class NKLandscape : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent { 22 public sealed class NKLandscape : SingleObjectiveHeuristicOptimizationProblem<INKEvaluator, IBinaryVectorCreator>, IStorableContent { 23 23 24 public string Filename { get; set; } 24 25 25 public static new Image StaticItemImage { get { return VSImageLibrary.Type; } }26 27 26 #region Parameter Properties 28 public ValueParameter<BoolValue> MaximizationParameter {29 get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }30 }31 IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {32 get { return MaximizationParameter; }33 }34 27 public ValueParameter<IntValue> LengthParameter { 35 28 get { return (ValueParameter<IntValue>)Parameters["Length"]; } 36 }37 public ValueParameter<IBinaryVectorCreator> SolutionCreatorParameter {38 get { return (ValueParameter<IBinaryVectorCreator>)Parameters["SolutionCreator"]; }39 }40 IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter {41 get { return SolutionCreatorParameter; }42 }43 public ValueParameter<INKEvaluator> EvaluatorParameter {44 get { return (ValueParameter<INKEvaluator>)Parameters["Evaluator"]; }45 }46 IParameter IHeuristicOptimizationProblem.EvaluatorParameter {47 get { return EvaluatorParameter; }48 }49 public ValueParameter<DoubleValue> BestKnownQualityParameter {50 get { return (ValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }51 }52 IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {53 get { return BestKnownQualityParameter; }54 29 } 55 30 public ValueParameter<BoolMatrix> GeneInteractionsParameter { … … 81 56 set { LengthParameter.Value = value; } 82 57 } 83 public IBinaryVectorCreator SolutionCreator {84 get { return SolutionCreatorParameter.Value; }85 set { SolutionCreatorParameter.Value = value; }86 }87 ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator {88 get { return SolutionCreatorParameter.Value; }89 }90 public INKEvaluator Evaluator {91 get { return EvaluatorParameter.Value; }92 set { EvaluatorParameter.Value = value; }93 }94 ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {95 get { return EvaluatorParameter.Value; }96 }97 IEvaluator IHeuristicOptimizationProblem.Evaluator {98 get { return EvaluatorParameter.Value; }99 }100 public DoubleValue BestKnownQuality {101 get { return BestKnownQualityParameter.Value; }102 }103 public IEnumerable<IItem> Operators {104 get { return operators; }105 }106 58 public IInteractionInitializer InteractionInitializer { 107 59 get { return InteractionInitializerParameter.Value; } 108 60 } 109 //private BestOneMaxSolutionAnalyzer BestOneMaxSolutionAnalyzer { 110 //get { return operators.OfType<BestOneMaxSolutionAnalyzer>().FirstOrDefault(); } 111 //} 61 [Storable(AllowOneWay = true)] 62 private List<IOperator> operators { 63 set { 64 Operators.AddRange(value); 65 } 66 } 112 67 #endregion 113 68 114 69 private static MersenneTwister random = new MersenneTwister(); 115 116 [Storable]117 private List<IItem> operators;118 70 119 71 [StorableConstructor] … … 121 73 private NKLandscape(NKLandscape original, Cloner cloner) 122 74 : base(original, cloner) { 123 operators = original.operators.Select(x => (IItem)cloner.Clone(x)).ToList();124 75 AttachEventHandlers(); 125 76 } 126 77 public NKLandscape() 127 78 : base() { 128 RandomBinaryVectorCreator creator = new RandomBinaryVectorCreator();129 INKEvaluator evaluator = new NKEvaluator();130 131 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the OneMax Problem is a maximization problem.", new BoolValue(true)));132 79 Parameters.Add(new ValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(10))); 133 Parameters.Add(new ValueParameter<IBinaryVectorCreator>("SolutionCreator", "The operator which should be used to create new OneMax solutions.", creator));134 Parameters.Add(new ValueParameter<INKEvaluator>("Evaluator", "The operator which should be used to evaluate NK landscape solutions.", evaluator));135 Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this OneMax instance.", new DoubleValue(0)));136 80 Parameters.Add(new ValueParameter<BoolMatrix>("GeneInteractions", "Every column gives the participating genes for each fitness component")); 137 81 Parameters.Add(new ValueParameter<IntValue>("InteractionSeed", "The seed used for the hash function to generate interaction tables.", new IntValue(random.Next()))); … … 142 86 Parameters.Add(new OptionalConstrainedValueParameter<IWeightsInitializer>("WeightsInitializer", "Operator to initialize weights distribution")); 143 87 88 SolutionCreator = new RandomBinaryVectorCreator(); 89 Evaluator = new NKEvaluator(); 90 144 91 InitializeInteractionInitializerParameter(); 145 92 InitializeWeightsInitializerParameter(); … … 170 117 171 118 #region Events 172 public event EventHandler SolutionCreatorChanged; 173 private void OnSolutionCreatorChanged() { 174 EventHandler handler = SolutionCreatorChanged; 175 if (handler != null) handler(this, EventArgs.Empty); 176 } 177 public event EventHandler EvaluatorChanged; 178 private void OnEvaluatorChanged() { 179 EventHandler handler = EvaluatorChanged; 180 if (handler != null) handler(this, EventArgs.Empty); 181 } 182 public event EventHandler OperatorsChanged; 183 private void OnOperatorsChanged() { 184 EventHandler handler = OperatorsChanged; 185 if (handler != null) handler(this, EventArgs.Empty); 186 } 187 public event EventHandler Reset; 188 private void OnReset() { 189 EventHandler handler = Reset; 190 if (handler != null) handler(this, EventArgs.Empty); 191 } 192 193 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) { 194 SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_BinaryVectorParameter_ActualNameChanged); 119 protected override void OnSolutionCreatorChanged() { 120 SolutionCreator.BinaryVectorParameter.ActualNameChanged += SolutionCreator_BinaryVectorParameter_ActualNameChanged; 195 121 ParameterizeSolutionCreator(); 196 122 ParameterizeEvaluator(); 197 123 ParameterizeAnalyzer(); 198 124 ParameterizeOperators(); 199 OnSolutionCreatorChanged();125 base.OnSolutionCreatorChanged(); 200 126 } 201 127 private void SolutionCreator_BinaryVectorParameter_ActualNameChanged(object sender, EventArgs e) { … … 204 130 ParameterizeOperators(); 205 131 } 206 pr ivate void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {207 ParameterizeEvaluator(); 208 ParameterizeAnalyzer(); 209 OnEvaluatorChanged();132 protected override void OnEvaluatorChanged() { 133 ParameterizeEvaluator(); 134 ParameterizeAnalyzer(); 135 base.OnEvaluatorChanged(); 210 136 } 211 137 void LengthParameter_ValueChanged(object sender, EventArgs e) { … … 217 143 NrOfFitnessComponentsParameter.Value = new IntValue(Length.Value); 218 144 } 219 void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {220 //BestKnownQualityParameter.Value.Value = Length.Value;221 }222 145 void OneBitflipMoveParameter_ActualNameChanged(object sender, EventArgs e) { 223 146 string name = ((ILookupParameter<OneBitflipMove>)sender).ActualName; … … 226 149 } 227 150 } 228 229 151 #endregion 230 152 … … 244 166 245 167 private void AttachEventHandlers() { 246 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);247 168 SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_BinaryVectorParameter_ActualNameChanged); 248 BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);249 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);250 169 LengthParameter.ValueChanged += new EventHandler(LengthParameter_ValueChanged); 251 170 LengthParameter.Value.ValueChanged += new EventHandler(Length_ValueChanged); … … 286 205 287 206 private void InitializeOperators() { 288 operators = new List<IItem>();289 //operators.Add(new BestOneMaxSolutionAnalyzer());290 207 ParameterizeAnalyzer(); 291 208 foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) { 292 209 if (!(op is ISingleObjectiveMoveEvaluator) || (op is INKMoveEvaluator)) { 293 operators.Add(op);210 Operators.Add(op); 294 211 } 295 212 } … … 333 250 } 334 251 #endregion 252 335 253 } 336 254 }
Note: See TracChangeset
for help on using the changeset viewer.