Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3667


Ignore:
Timestamp:
05/06/10 12:49:05 (15 years ago)
Author:
svonolfe
Message:
  • Updated OneMax analyzer
  • Updated Knapsack analyzer
  • Fixed bug in OneMax and TF analyzer views

(#999)

Location:
trunk/sources
Files:
6 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs

    r3658 r3667  
    3838  [Item("BestKnapsackSolutionAnalyzer", "An operator for analyzing the best solution for a knapsack problem.")]
    3939  [StorableClass]
    40   class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IBestKnapsackSolutionAnalyzer, IAnalyzer {
     40  class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    4141
    42     public ILookupParameter<BinaryVector> BinaryVectorParameter {
    43       get { return (ILookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
     42    public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter {
     43      get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
    4444    }
    45     ILookupParameter IBestKnapsackSolutionAnalyzer.BinaryVectorParameter {
    46       get { return BinaryVectorParameter; }
     45    public LookupParameter<IntValue> KnapsackCapacityParameter {
     46      get { return (LookupParameter<IntValue>)Parameters["KnapsackCapacity"]; }
    4747    }
    48     public ILookupParameter<IntValue> KnapsackCapacityParameter {
    49       get { return (ILookupParameter<IntValue>)Parameters["KnapsackCapacity"]; }
     48    public LookupParameter<IntArray> WeightsParameter {
     49      get { return (LookupParameter<IntArray>)Parameters["Weights"]; }
    5050    }
    51     public ILookupParameter<IntArray> WeightsParameter {
    52       get { return (ILookupParameter<IntArray>)Parameters["Weights"]; }
     51    public LookupParameter<IntArray> ValuesParameter {
     52      get { return (LookupParameter<IntArray>)Parameters["Values"]; }
    5353    }
    54     public ILookupParameter<IntArray> ValuesParameter {
    55       get { return (ILookupParameter<IntArray>)Parameters["Values"]; }
     54    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
     55      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    5656    }
    57     public ILookupParameter<DoubleValue> QualityParameter {
    58       get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
     57    public LookupParameter<KnapsackSolution> BestSolutionParameter {
     58      get { return (LookupParameter<KnapsackSolution>)Parameters["BestSolution"]; }
    5959    }
    60     ILookupParameter IBestKnapsackSolutionAnalyzer.QualityParameter {
    61       get { return QualityParameter; }
    62     }
    63     public ILookupParameter<KnapsackSolution> BestSolutionParameter {
    64       get { return (ILookupParameter<KnapsackSolution>)Parameters["BestSolution"]; }
    65     }
    66     public IValueLookupParameter<ResultCollection> ResultsParameter {
    67       get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     60    public ValueLookupParameter<ResultCollection> ResultsParameter {
     61      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    6862    }
    6963
    7064    public BestKnapsackSolutionAnalyzer()
    7165      : base() {
    72       Parameters.Add(new LookupParameter<BinaryVector>("BinaryVector", "The knapsack solutions from which the best solution should be visualized."));
     66      Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The knapsack solutions from which the best solution should be visualized."));
    7367      Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack."));
    7468      Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items."));
    7569      Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items."));
    7670
    77       Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The qualities of the knapsack solutions which should be visualized."));
     71      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the knapsack solutions which should be visualized."));
    7872      Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best knapsack solution."));
    7973      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored."));
     
    8175
    8276    public override IOperation Apply() {
    83       BinaryVector binaryVector = BinaryVectorParameter.ActualValue;
    84       DoubleValue quality = QualityParameter.ActualValue;
     77      ItemArray<BinaryVector> binaryVectors = BinaryVectorParameter.ActualValue;
     78      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    8579      ResultCollection results = ResultsParameter.ActualValue;
     80
     81      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    8682
    8783      KnapsackSolution solution = BestSolutionParameter.ActualValue;
    8884      if (solution == null) {
    89         solution = new KnapsackSolution(binaryVector, QualityParameter.ActualValue,
     85        solution = new KnapsackSolution(binaryVectors[i], qualities[i],
    9086          KnapsackCapacityParameter.ActualValue, WeightsParameter.ActualValue, ValuesParameter.ActualValue);
    9187        BestSolutionParameter.ActualValue = solution;
    9288        results.Add(new Result("Best Knapsack Solution", solution));
    9389      }  else {
    94         solution.BinaryVector = binaryVector;
    95         solution.Quality = QualityParameter.ActualValue;
     90        solution.BinaryVector = binaryVectors[i];
     91        solution.Quality = qualities[i];
    9692        solution.Capacity = KnapsackCapacityParameter.ActualValue;
    9793        solution.Weights = WeightsParameter.ActualValue;
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/HeuristicLab.Problems.Knapsack-3.3.csproj

    r3641 r3667  
    8181  </ItemGroup>
    8282  <ItemGroup>
    83     <Compile Include="Analyzers\MultiPopulationBestKnapsackSolutionAnalyzer.cs" />
    84     <Compile Include="Analyzers\PopulationBestKnapsackSolutionAnalyzer.cs" />
    8583    <Compile Include="Evaluators\KnapsackEvaluator.cs" />
    8684    <Compile Include="HeuristicLabProblemsKnapsackPlugin.cs" />
    87     <Compile Include="Interfaces\IBestKnapsackSolutionAnalyzer.cs" />
    8885    <Compile Include="Interfaces\IKnapsackEvaluator.cs" />
    8986    <Compile Include="Interfaces\IKnapsackMoveEvaluator.cs" />
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r3641 r3667  
    124124      get { return operators.Cast<IOperator>(); }
    125125    }
    126     private IEnumerable<IBestKnapsackSolutionAnalyzer> BestKnapsackSolutionAnalyzers {
    127       get { return operators.OfType<IBestKnapsackSolutionAnalyzer>(); }
     126    private BestKnapsackSolutionAnalyzer BestKnapsackSolutionAnalyzer {
     127      get { return operators.OfType<BestKnapsackSolutionAnalyzer>().FirstOrDefault(); }
    128128    }
    129129    #endregion
     
    206206      ParameterizeSolutionCreator();
    207207      ParameterizeEvaluator();
    208       ParameterizeAnalyzers();
     208      ParameterizeAnalyzer();
    209209      ParameterizeOperators();
    210210      OnSolutionCreatorChanged();
     
    212212    private void SolutionCreator_BinaryVectorParameter_ActualNameChanged(object sender, EventArgs e) {
    213213      ParameterizeEvaluator();
    214       ParameterizeAnalyzers();
     214      ParameterizeAnalyzer();
    215215      ParameterizeOperators();
    216216    }
    217217    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    218218      ParameterizeEvaluator();
    219       ParameterizeAnalyzers();
     219      ParameterizeAnalyzer();
    220220      OnEvaluatorChanged();
    221221    }
    222222    void KnapsackCapacityParameter_ValueChanged(object sender, EventArgs e) {
    223223      ParameterizeEvaluator();
    224       ParameterizeAnalyzers();
     224      ParameterizeAnalyzer();
    225225    }
    226226    void WeightsParameter_ValueChanged(object sender, EventArgs e) {
    227227      ParameterizeEvaluator();
    228       ParameterizeAnalyzers();
     228      ParameterizeAnalyzer();
    229229      ParameterizeSolutionCreator();
    230230
     
    239239    void ValuesParameter_ValueChanged(object sender, EventArgs e) {
    240240      ParameterizeEvaluator();
    241       ParameterizeAnalyzers();
     241      ParameterizeAnalyzer();
    242242      ParameterizeSolutionCreator();
    243243
     
    291291      }
    292292    }
    293     private void ParameterizeAnalyzers() {
    294       foreach (IBestKnapsackSolutionAnalyzer analyzer in BestKnapsackSolutionAnalyzers) {
    295         analyzer.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    296         analyzer.KnapsackCapacityParameter.ActualName = KnapsackCapacityParameter.Name;
    297         analyzer.WeightsParameter.ActualName = WeightsParameter.Name;
    298         analyzer.ValuesParameter.ActualName = ValuesParameter.Name;
    299         analyzer.ResultsParameter.ActualName = "Results";
    300       }
     293    private void ParameterizeAnalyzer() {
     294      BestKnapsackSolutionAnalyzer.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
     295      BestKnapsackSolutionAnalyzer.KnapsackCapacityParameter.ActualName = KnapsackCapacityParameter.Name;
     296      BestKnapsackSolutionAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name;
     297      BestKnapsackSolutionAnalyzer.ValuesParameter.ActualName = ValuesParameter.Name;
     298      BestKnapsackSolutionAnalyzer.ResultsParameter.ActualName = "Results";
    301299    }
    302300    private void InitializeOperators() {
    303301      operators = new List<IOperator>();
    304302      operators.Add(new BestKnapsackSolutionAnalyzer());
    305       operators.Add(new PopulationBestKnapsackSolutionAnalyzer());
    306       operators.Add(new MultiPopulationBestKnapsackSolutionAnalyzer());
    307       ParameterizeAnalyzers();
     303      ParameterizeAnalyzer();
    308304      foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
    309305        if (!(op is ISingleObjectiveMoveEvaluator) || (op is IKnapsackMoveEvaluator)) {
  • trunk/sources/HeuristicLab.Problems.OneMax.Views/3.3/OneMaxSolutionView.cs

    r3649 r3667  
    6363        Invoke(new EventHandler(Content_QualityChanged), sender, e);
    6464      else {
    65         qualityView.ViewType = null;
    6665        qualityView.Content = Content.Quality;
    6766      }
     
    7069    void Content_BinaryVectorChanged(object sender, EventArgs e) {
    7170      if (InvokeRequired)
    72         Invoke(new EventHandler(Content_QualityChanged), sender, e);
     71        Invoke(new EventHandler(Content_BinaryVectorChanged), sender, e);
    7372      else {
    74         binaryVectorView.ViewType = null;
    7573        binaryVectorView.Content = Content.BinaryVector;
    7674      }
     
    8482        binaryVectorView.Content = null;
    8583      } else {
    86         qualityView.ViewType = null;
    8784        qualityView.Content = Content.Quality;
    88 
    89         binaryVectorView.ViewType = null;
    9085        binaryVectorView.Content = Content.BinaryVector;
    9186      }
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/Analyzers/BestOneMaxSolutionAnalyzer.cs

    r3658 r3667  
    3838  [Item("BestOneMaxSolutionAnalyzer", "An operator for analyzing the best solution for a OneMax problem.")]
    3939  [StorableClass]
    40   class BestOneMaxSolutionAnalyzer : SingleSuccessorOperator, IBestOneMaxSolutionAnalyzer, IAnalyzer {
     40  class BestOneMaxSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    4141
    42     public ILookupParameter<BinaryVector> BinaryVectorParameter {
    43       get { return (ILookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
     42    public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter {
     43      get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
    4444    }
    45     ILookupParameter IBestOneMaxSolutionAnalyzer.BinaryVectorParameter {
    46       get { return BinaryVectorParameter; }
     45    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
     46      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    4747    }
    48     public ILookupParameter<DoubleValue> QualityParameter {
    49       get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
     48    public LookupParameter<OneMaxSolution> BestSolutionParameter {
     49      get { return (LookupParameter<OneMaxSolution>)Parameters["BestSolution"]; }
    5050    }
    51     ILookupParameter IBestOneMaxSolutionAnalyzer.QualityParameter {
    52       get { return QualityParameter; }
    53     }
    54     public ILookupParameter<OneMaxSolution> BestSolutionParameter {
    55       get { return (ILookupParameter<OneMaxSolution>)Parameters["BestSolution"]; }
    56     }
    57     public IValueLookupParameter<ResultCollection> ResultsParameter {
    58       get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     51    public ValueLookupParameter<ResultCollection> ResultsParameter {
     52      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    5953    }
    6054
    6155    public BestOneMaxSolutionAnalyzer()
    6256      : base() {
    63       Parameters.Add(new LookupParameter<BinaryVector>("BinaryVector", "The Onemax solutions from which the best solution should be visualized."));
     57      Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The Onemax solutions from which the best solution should be visualized."));
    6458
    65       Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The qualities of the Onemax solutions which should be visualized."));
     59      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the Onemax solutions which should be visualized."));
    6660      Parameters.Add(new LookupParameter<OneMaxSolution>("BestSolution", "The best Onemax solution."));
    6761      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the Onemax solution should be stored."));
     
    6963
    7064    public override IOperation Apply() {
    71       BinaryVector binaryVector = BinaryVectorParameter.ActualValue;
    72       DoubleValue quality = QualityParameter.ActualValue;
     65      ItemArray<BinaryVector> binaryVectors = BinaryVectorParameter.ActualValue;
     66      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    7367      ResultCollection results = ResultsParameter.ActualValue;
     68
     69      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    7470
    7571      OneMaxSolution solution = BestSolutionParameter.ActualValue;
    7672      if (solution == null) {
    77         solution = new OneMaxSolution(binaryVector, QualityParameter.ActualValue);
     73        solution = new OneMaxSolution(binaryVectors[i], QualityParameter.ActualValue[i]);
    7874        BestSolutionParameter.ActualValue = solution;
    7975        results.Add(new Result("Best OneMax Solution", solution));
    8076      }  else {
    81         solution.BinaryVector = binaryVector;
    82         solution.Quality = QualityParameter.ActualValue;
     77        solution.BinaryVector = binaryVectors[i];
     78        solution.Quality = QualityParameter.ActualValue[i];
    8379
    8480        results["Best OneMax Solution"].Value = solution;
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/HeuristicLab.Problems.OneMax-3.3.csproj

    r3642 r3667  
    8787  <ItemGroup>
    8888    <Compile Include="Analyzers\BestOneMaxSolutionAnalyzer.cs" />
    89     <Compile Include="Analyzers\MultiPopulationBestOneMaxSolutionAnalyzer.cs" />
    90     <Compile Include="Analyzers\PopulationBestOneMaxSolutionAnalyzer.cs" />
    91     <Compile Include="Interfaces\IBestOneMaxSolutionAnalyzer.cs" />
    9289    <Compile Include="Interfaces\IOneMaxSolutionsVisualizer.cs" />
    9390    <Compile Include="Interfaces\IOneMaxMoveEvaluator.cs" />
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/OnemaxProblem.cs

    r3642 r3667  
    102102      get { return operators.Cast<IOperator>(); }
    103103    }
    104     private IEnumerable<IBestOneMaxSolutionAnalyzer> BestOneMaxSolutionAnalyzers {
    105       get { return operators.OfType<IBestOneMaxSolutionAnalyzer>(); }
     104    private BestOneMaxSolutionAnalyzer BestOneMaxSolutionAnalyzer {
     105      get { return operators.OfType<BestOneMaxSolutionAnalyzer>().FirstOrDefault(); }
    106106    }
    107107    #endregion
     
    157157      ParameterizeSolutionCreator();
    158158      ParameterizeEvaluator();
    159       ParameterizeAnalyzers();
     159      ParameterizeAnalyzer();
    160160      ParameterizeOperators();
    161161      OnSolutionCreatorChanged();
     
    163163    private void SolutionCreator_BinaryVectorParameter_ActualNameChanged(object sender, EventArgs e) {
    164164      ParameterizeEvaluator();
    165       ParameterizeAnalyzers();
     165      ParameterizeAnalyzer();
    166166      ParameterizeOperators();
    167167    }
    168168    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    169169      ParameterizeEvaluator();
    170       ParameterizeAnalyzers();
     170      ParameterizeAnalyzer();
    171171      OnEvaluatorChanged();
    172172    }
     
    209209        ((OneMaxEvaluator)Evaluator).BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    210210    }
    211     private void ParameterizeAnalyzers() {
    212       foreach (IBestOneMaxSolutionAnalyzer analyzer in BestOneMaxSolutionAnalyzers) {
    213         analyzer.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    214         analyzer.ResultsParameter.ActualName = "Results";
    215       }
     211    private void ParameterizeAnalyzer() {
     212      BestOneMaxSolutionAnalyzer.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
     213      BestOneMaxSolutionAnalyzer.ResultsParameter.ActualName = "Results";
    216214    }
    217215    private void InitializeOperators() {
    218216      operators = new List<IOperator>();
    219217      operators.Add(new BestOneMaxSolutionAnalyzer());
    220       operators.Add(new PopulationBestOneMaxSolutionAnalyzer());
    221       operators.Add(new MultiPopulationBestOneMaxSolutionAnalyzer());
    222       ParameterizeAnalyzers();
     218      ParameterizeAnalyzer();
    223219      foreach(IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
    224220        if (!(op is ISingleObjectiveMoveEvaluator) || (op is IOneMaxMoveEvaluator)) {
  • trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/SingleObjectiveTestFunctionSolutionView.cs

    r3665 r3667  
    7575    private void Content_BestRealVectorChanged(object sender, EventArgs e) {
    7676      if (InvokeRequired)
    77         Invoke(new EventHandler(Content_QualityChanged), sender, e);
     77        Invoke(new EventHandler(Content_BestRealVectorChanged), sender, e);
    7878      else {
    79         realVectorView.ViewType = null;
    8079        realVectorView.Content = Content.BestRealVector;
    8180        pictureBox.Visible = Content.BestRealVector.Length == 2;
     
    8887        Invoke(new EventHandler(Content_QualityChanged), sender, e);
    8988      else {
    90         qualityView.ViewType = null;
    9189        qualityView.Content = Content.BestQuality;
    9290        pictureBox.Visible = Content.BestRealVector.Length == 2;
     
    110108        realVectorView.Content = null;
    111109      } else {
    112         qualityView.ViewType = null;
    113110        qualityView.Content = Content.BestQuality;
    114 
    115         realVectorView.ViewType = null;
    116111        realVectorView.Content = Content.BestRealVector;
    117112
Note: See TracChangeset for help on using the changeset viewer.