Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3861


Ignore:
Timestamp:
05/27/10 09:14:49 (14 years ago)
Author:
abeham
Message:

#866

  • worked on external evaluation problem
Location:
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluationProblem.cs

    r3860 r3861  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Drawing;
     25using System.Linq;
     26using HeuristicLab.Collections;
    2227using HeuristicLab.Core;
     28using HeuristicLab.Data;
     29using HeuristicLab.Optimization;
     30using HeuristicLab.Parameters;
    2331using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    24 using HeuristicLab.Parameters;
    25 using System.Drawing;
    26 using HeuristicLab.Optimization;
    27 using HeuristicLab.Data;
    28 using HeuristicLab.Operators;
    2932
    3033namespace HeuristicLab.Problems.ExternalEvaluation {
     
    3538      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
    3639    }
     40    public new ParameterCollection Parameters {
     41      get { return base.Parameters; }
     42    }
     43    IKeyedItemCollection<string, IParameter> IParameterizedItem.Parameters {
     44      get { return Parameters; }
     45    }
    3746
    3847    #region Parameters
     
    4958      get { return MaximizationParameter; }
    5059    }
    51     public ValueParameter<IOperator> SolutionCreatorParameter {
    52       get { return (ValueParameter<IOperator>)Parameters["SolutionCreator"]; }
     60    public ValueParameter<ISolutionCreator> SolutionCreatorParameter {
     61      get { return (ValueParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
    5362    }
    5463    IParameter IProblem.SolutionCreatorParameter {
     
    6675    public OptionalValueParameter<IScope> BestKnownSolutionParameter {
    6776      get { return (OptionalValueParameter<IScope>)Parameters["BestKnownSolution"]; }
     77    }
     78    public ValueParameter<ItemList<IOperator>> OperatorsParameter {
     79      get { return (ValueParameter<ItemList<IOperator>>)Parameters["Operators"]; }
    6880    }
    6981    #endregion
     
    7486      set { MaximizationParameter.Value = value; }
    7587    }
    76     public IOperator SolutionCreator {
     88    public ISolutionCreator SolutionCreator {
    7789      get { return SolutionCreatorParameter.Value; }
    7890      set { SolutionCreatorParameter.Value = value; }
     
    8193      get { return SolutionCreatorParameter.Value; }
    8294    }
    83     public ISingleObjectiveTestFunctionProblemEvaluator Evaluator {
     95    public IExternalEvaluationProblemEvaluator Evaluator {
    8496      get { return EvaluatorParameter.Value; }
    8597      set { EvaluatorParameter.Value = value; }
     
    95107      set { BestKnownQualityParameter.Value = value; }
    96108    }
    97     private List<IOperator> operators;
    98109    public IEnumerable<IOperator> Operators {
    99       get { return operators; }
    100     }
    101     private BestSingleObjectiveTestFunctionSolutionAnalyzer BestSingleObjectiveTestFunctionSolutionAnalyzer {
    102       get { return operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); }
    103     }
    104     #endregion
    105 
     110      get { return OperatorsParameter.Value; }
     111    }
     112    private BestExternalEvaluationSolutionAnalyzer BestExternalEvaluationSolutionAnalyzer {
     113      get { return OperatorsParameter.Value.OfType<BestExternalEvaluationSolutionAnalyzer>().FirstOrDefault(); }
     114    }
     115    #endregion
     116
     117    [StorableConstructor]
     118    protected ExternalEvaluationProblem(bool deserializing) : base(deserializing) { }
    106119    public ExternalEvaluationProblem()
    107120      : base() {
    108121      ExternalEvaluator evaluator = new ExternalEvaluator();
    109       EmptyOperator solutionCreator = new EmptyOperator();
     122      ExternalEvaluationSolutionCreator solutionCreator = new ExternalEvaluationSolutionCreator();
    110123
    111124      Parameters.Add(new ValueParameter<IExternalEvaluationDriver>("Driver", "The communication driver that is used to exchange data with the external process."));
    112125      Parameters.Add(new ValueParameter<IExternalEvaluationProblemEvaluator>("Evaluator", "The evaluator that collects the values to exchange.", evaluator));
    113126      Parameters.Add(new ValueParameter<IOperator>("SolutionCreator", "An operator to create the solution components.", solutionCreator));
    114     }
     127      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as most test functions are minimization problems.", new BoolValue(false)));
     128      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
     129      Parameters.Add(new OptionalValueParameter<IScope>("BestKnownSolution", "The best known solution for this external evaluation problem."));
     130      Parameters.Add(new ValueParameter<ItemList<IOperator>>("Operators", "The operators that are passed to the algorithm.", new ItemList<IOperator>()));
     131
     132      InitializeOperators();
     133      AttachEventHandlers();
     134    }
     135
     136    #region Events
     137    public event EventHandler SolutionCreatorChanged;
     138    private void OnSolutionCreatorChanged() {
     139      EventHandler handler = SolutionCreatorChanged;
     140      if (handler != null) handler(this, EventArgs.Empty);
     141    }
     142    public event EventHandler EvaluatorChanged;
     143    private void OnEvaluatorChanged() {
     144      EventHandler handler = EvaluatorChanged;
     145      if (handler != null) handler(this, EventArgs.Empty);
     146    }
     147    public event EventHandler OperatorsChanged;
     148    private void OnOperatorsChanged() {
     149      EventHandler handler = OperatorsChanged;
     150      if (handler != null) handler(this, EventArgs.Empty);
     151    }
     152    public event EventHandler Reset;
     153    private void OnReset() {
     154      EventHandler handler = Reset;
     155      if (handler != null) handler(this, EventArgs.Empty);
     156    }
     157
     158    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
     159      OnSolutionCreatorChanged();
     160    }
     161    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
     162      OnEvaluatorChanged();
     163    }
     164    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     165      // TODO: Following code is not yet approved behavior, but it's the best effort I can make here regarding wiring
     166      string qualityName = Evaluator.QualityParameter.ActualName;
     167      foreach (IOperator op in OperatorsParameter.Value) {
     168        foreach (ILookupParameter<DoubleValue> param in op.Parameters.OfType<ILookupParameter<DoubleValue>>()) {
     169          if (param.Name.Equals("Quality")) param.ActualName = qualityName;
     170        }
     171        foreach (IScopeTreeLookupParameter<DoubleValue> param in op.Parameters.OfType<IScopeTreeLookupParameter<DoubleValue>>()) {
     172          if (param.Name.Equals("Quality")) param.ActualName = qualityName;
     173        }
     174      }
     175    }
     176    private void OperatorsParameter_ValueChanged(object sender, EventArgs e) {
     177      OnOperatorsChanged();
     178    }
     179    private void OperatorsParameter_Value_ItemsAdded(object sender, EventArgs e) {
     180      OnOperatorsChanged();
     181    }
     182    private void OperatorsParameter_Value_ItemsRemoved(object sender, EventArgs e) {
     183      OnOperatorsChanged();
     184    }
     185    private void OperatorsParameter_Value_CollectionReset(object sender, EventArgs e) {
     186      OnOperatorsChanged();
     187    }
     188    #endregion
     189
     190    #region Helpers
     191    private void InitializeOperators() {
     192      ItemList<IOperator> operators = OperatorsParameter.Value;
     193      operators.Add(new BestExternalEvaluationSolutionAnalyzer());
     194      ParameterizeAnalyzers();
     195    }
     196    [StorableHook(HookType.AfterDeserialization)]
     197    private void AttachEventHandlers() {
     198      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
     199      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
     200      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     201      OperatorsParameter.ValueChanged += new System.EventHandler(OperatorsParameter_ValueChanged);
     202      OperatorsParameter.Value.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(OperatorsParameter_Value_ItemsAdded);
     203      OperatorsParameter.Value.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(OperatorsParameter_Value_ItemsRemoved);
     204      OperatorsParameter.Value.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(OperatorsParameter_Value_CollectionReset);
     205    }
     206    private void ParameterizeAnalyzers() {
     207      BestExternalEvaluationSolutionAnalyzer.ResultsParameter.ActualName = "Results";
     208      BestExternalEvaluationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     209      BestExternalEvaluationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
     210      BestExternalEvaluationSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     211      BestExternalEvaluationSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     212    }
     213    private void ParameterizeEvaluator() {
     214      Evaluator.DriverParameter.ActualName = DriverParameter.Name;
     215    }
     216    #endregion
    115217  }
    116218}
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluationSolutionCreator.cs

    r3859 r3861  
    3333  [StorableClass]
    3434  public class ExternalEvaluationSolutionCreator : CheckedMultiOperator<IOperator>, ISolutionCreator {
     35    public override IOperation Apply() {
     36      OperationCollection result = new OperationCollection();
     37      foreach (IOperator op in Operators.CheckedItems.OrderBy(x => x.Index).Select(x => x.Value)) {
     38        result.Add(ExecutionContext.CreateOperation(op));
     39      }
     40      result.Add(base.Apply());
     41      return result;
     42    }
    3543  }
    3644}
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/HeuristicLab.Problems.ExternalEvaluation-3.3.csproj

    r3860 r3861  
    7979  </ItemGroup>
    8080  <ItemGroup>
     81    <Compile Include="Analyzers\BestExternalEvaluationSolutionAnalyzer.cs" />
    8182    <Compile Include="Drivers\ExternalEvaluationDriver.cs" />
    8283    <Compile Include="Drivers\ExternalEvaluationProcessDriver.cs" />
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Interfaces/IExternalEvaluationProblemEvaluator.cs

    r3859 r3861  
    2525using System.Text;
    2626using HeuristicLab.Optimization;
     27using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2729
    2830namespace HeuristicLab.Problems.ExternalEvaluation {
    2931  public interface IExternalEvaluationProblemEvaluator : ISingleObjectiveEvaluator {
     32    IValueLookupParameter<IExternalEvaluationDriver> DriverParameter { get; }
    3033  }
    3134}
Note: See TracChangeset for help on using the changeset viewer.