Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8005


Ignore:
Timestamp:
06/14/12 10:28:38 (13 years ago)
Author:
epitzer
Message:

#1696 derive NK Landscape from SingleObjectiveHeuristicOptimizationProblem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/NKLandscape.cs

    r8002 r8005  
    2020  [Creatable("Problems")]
    2121  [StorableClass]
    22   public sealed class NKLandscape : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent {
     22  public sealed class NKLandscape : SingleObjectiveHeuristicOptimizationProblem<INKEvaluator, IBinaryVectorCreator>, IStorableContent {
     23
    2324    public string Filename { get; set; }
    2425
    25     public static new Image StaticItemImage { get { return VSImageLibrary.Type; } }
    26 
    2726    #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     }
    3427    public ValueParameter<IntValue> LengthParameter {
    3528      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; }
    5429    }
    5530    public ValueParameter<BoolMatrix> GeneInteractionsParameter {
     
    8156      set { LengthParameter.Value = value; }
    8257    }
    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     }
    10658    public IInteractionInitializer InteractionInitializer {
    10759      get { return InteractionInitializerParameter.Value; }
    10860    }
    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    }
    11267    #endregion
    11368
    11469    private static MersenneTwister random = new MersenneTwister();
    115 
    116     [Storable]
    117     private List<IItem> operators;
    11870
    11971    [StorableConstructor]
     
    12173    private NKLandscape(NKLandscape original, Cloner cloner)
    12274      : base(original, cloner) {
    123       operators = original.operators.Select(x => (IItem)cloner.Clone(x)).ToList();
    12475      AttachEventHandlers();
    12576    }
    12677    public NKLandscape()
    12778      : 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)));
    13279      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)));
    13680      Parameters.Add(new ValueParameter<BoolMatrix>("GeneInteractions", "Every column gives the participating genes for each fitness component"));
    13781      Parameters.Add(new ValueParameter<IntValue>("InteractionSeed", "The seed used for the hash function to generate interaction tables.", new IntValue(random.Next())));
     
    14286      Parameters.Add(new OptionalConstrainedValueParameter<IWeightsInitializer>("WeightsInitializer", "Operator to initialize weights distribution"));
    14387
     88      SolutionCreator = new RandomBinaryVectorCreator();
     89      Evaluator = new NKEvaluator();
     90
    14491      InitializeInteractionInitializerParameter();
    14592      InitializeWeightsInitializerParameter();
     
    170117
    171118    #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;
    195121      ParameterizeSolutionCreator();
    196122      ParameterizeEvaluator();
    197123      ParameterizeAnalyzer();
    198124      ParameterizeOperators();
    199       OnSolutionCreatorChanged();
     125      base.OnSolutionCreatorChanged();
    200126    }
    201127    private void SolutionCreator_BinaryVectorParameter_ActualNameChanged(object sender, EventArgs e) {
     
    204130      ParameterizeOperators();
    205131    }
    206     private 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();
    210136    }
    211137    void LengthParameter_ValueChanged(object sender, EventArgs e) {
     
    217143      NrOfFitnessComponentsParameter.Value = new IntValue(Length.Value);
    218144    }
    219     void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
    220       //BestKnownQualityParameter.Value.Value = Length.Value;
    221     }
    222145    void OneBitflipMoveParameter_ActualNameChanged(object sender, EventArgs e) {
    223146      string name = ((ILookupParameter<OneBitflipMove>)sender).ActualName;
     
    226149      }
    227150    }
    228 
    229151    #endregion
    230152
     
    244166
    245167    private void AttachEventHandlers() {
    246       SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    247168      SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_BinaryVectorParameter_ActualNameChanged);
    248       BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
    249       EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    250169      LengthParameter.ValueChanged += new EventHandler(LengthParameter_ValueChanged);
    251170      LengthParameter.Value.ValueChanged += new EventHandler(Length_ValueChanged);
     
    286205
    287206    private void InitializeOperators() {
    288       operators = new List<IItem>();
    289       //operators.Add(new BestOneMaxSolutionAnalyzer());
    290207      ParameterizeAnalyzer();
    291208      foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
    292209        if (!(op is ISingleObjectiveMoveEvaluator) || (op is INKMoveEvaluator)) {
    293           operators.Add(op);
     210          Operators.Add(op);
    294211        }
    295212      }
     
    333250    }
    334251    #endregion
     252
    335253  }
    336254}
Note: See TracChangeset for help on using the changeset viewer.