Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3641 for trunk/sources


Ignore:
Timestamp:
05/05/10 16:36:32 (15 years ago)
Author:
svonolfe
Message:

Added anaylzers for the knapsack problem (#999)

Location:
trunk/sources/HeuristicLab.Problems.Knapsack/3.3
Files:
5 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/HeuristicLab.Problems.Knapsack-3.3.csproj

    r3467 r3641  
    8181  </ItemGroup>
    8282  <ItemGroup>
     83    <Compile Include="Analyzers\MultiPopulationBestKnapsackSolutionAnalyzer.cs" />
     84    <Compile Include="Analyzers\PopulationBestKnapsackSolutionAnalyzer.cs" />
    8385    <Compile Include="Evaluators\KnapsackEvaluator.cs" />
    8486    <Compile Include="HeuristicLabProblemsKnapsackPlugin.cs" />
     87    <Compile Include="Interfaces\IBestKnapsackSolutionAnalyzer.cs" />
    8588    <Compile Include="Interfaces\IKnapsackEvaluator.cs" />
    86     <Compile Include="Interfaces\IKnapsackSolutionsVisualizer.cs" />
    8789    <Compile Include="Interfaces\IKnapsackMoveEvaluator.cs" />
    8890    <Compile Include="KnapsackProblem.cs" />
     
    9193    <Compile Include="MoveEvaluators\KnapsackOneBitflipMoveEvaluator.cs" />
    9294    <Compile Include="Properties\AssemblyInfo.cs" />
    93     <Compile Include="Visualizers\BestKnapsackVisualizer.cs" />
     95    <Compile Include="Analyzers\BestKnapsackSolutionAnalyzer.cs" />
    9496  </ItemGroup>
    9597  <ItemGroup>
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r3616 r3641  
    3232using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3333using HeuristicLab.PluginInfrastructure;
    34 using HeuristicLab.Problems.Knapsack.Visualizers;
     34using HeuristicLab.Problems.Knapsack.Analyzers;
    3535
    3636namespace HeuristicLab.Problems.Knapsack {
     
    120120      set { BestKnownQualityParameter.Value = value; }
    121121    }
    122     private List<IBinaryVectorOperator> operators;
     122    private List<IOperator> operators;
    123123    public IEnumerable<IOperator> Operators {
    124124      get { return operators.Cast<IOperator>(); }
     125    }
     126    private IEnumerable<IBestKnapsackSolutionAnalyzer> BestKnapsackSolutionAnalyzers {
     127      get { return operators.OfType<IBestKnapsackSolutionAnalyzer>(); }
    125128    }
    126129    #endregion
     
    168171      ParameterizeSolutionCreator();
    169172      ParameterizeEvaluator();
    170       ParameterizeVisualizer();
    171173
    172174      Initialize();
     
    201203
    202204    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
    203       SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
    204       ParameterizeSolutionCreator();
    205       ParameterizeEvaluator();
    206       ParameterizeVisualizer();
     205      SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_BinaryVectorParameter_ActualNameChanged);
     206      ParameterizeSolutionCreator();
     207      ParameterizeEvaluator();
     208      ParameterizeAnalyzers();
    207209      ParameterizeOperators();
    208210      OnSolutionCreatorChanged();
    209211    }
    210     private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {
    211       ParameterizeEvaluator();
    212       ParameterizeVisualizer();
     212    private void SolutionCreator_BinaryVectorParameter_ActualNameChanged(object sender, EventArgs e) {
     213      ParameterizeEvaluator();
     214      ParameterizeAnalyzers();
    213215      ParameterizeOperators();
    214216    }
    215217    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    216218      ParameterizeEvaluator();
    217       ParameterizeVisualizer();
     219      ParameterizeAnalyzers();
    218220      OnEvaluatorChanged();
    219221    }
    220222    void KnapsackCapacityParameter_ValueChanged(object sender, EventArgs e) {
    221223      ParameterizeEvaluator();
    222       ParameterizeVisualizer();
     224      ParameterizeAnalyzers();
    223225    }
    224226    void WeightsParameter_ValueChanged(object sender, EventArgs e) {
    225227      ParameterizeEvaluator();
    226       ParameterizeVisualizer();
     228      ParameterizeAnalyzers();
    227229      ParameterizeSolutionCreator();
    228230
     
    237239    void ValuesParameter_ValueChanged(object sender, EventArgs e) {
    238240      ParameterizeEvaluator();
    239       ParameterizeVisualizer();
     241      ParameterizeAnalyzers();
    240242      ParameterizeSolutionCreator();
    241243
     
    264266      InitializeOperators();
    265267      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    266       SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
     268      SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_BinaryVectorParameter_ActualNameChanged);
    267269      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    268270      KnapsackCapacityParameter.ValueChanged += new EventHandler(KnapsackCapacityParameter_ValueChanged);
     
    289291      }
    290292    }
    291     private void ParameterizeVisualizer() {
    292       //if (Visualizer is IKnapsackSolutionsVisualizer) {
    293       //  IKnapsackSolutionsVisualizer visualizer =
    294       //    (IKnapsackSolutionsVisualizer)Visualizer;
    295       //  visualizer.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    296       //  visualizer.KnapsackCapacityParameter.ActualName = KnapsackCapacityParameter.Name;
    297       //  visualizer.WeightsParameter.ActualName = WeightsParameter.Name;
    298       //  visualizer.ValuesParameter.ActualName = ValuesParameter.Name;
    299       //}
     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      }
    300301    }
    301302    private void InitializeOperators() {
    302       operators = new List<IBinaryVectorOperator>();
     303      operators = new List<IOperator>();
     304      operators.Add(new BestKnapsackSolutionAnalyzer());
     305      operators.Add(new PopulationBestKnapsackSolutionAnalyzer());
     306      operators.Add(new MultiPopulationBestKnapsackSolutionAnalyzer());
     307      ParameterizeAnalyzers();
    303308      foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
    304309        if (!(op is ISingleObjectiveMoveEvaluator) || (op is IKnapsackMoveEvaluator)) {
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackSolution.cs

    r3467 r3641  
    9898    }
    9999
     100    [Storable]
     101    private DoubleValue quality;
     102    public DoubleValue Quality {
     103      get { return quality; }
     104      set {
     105        if (quality != value) {
     106          if (quality != null) DeregisterQualityEvents();
     107          quality = value;
     108          if (quality != null) RegisterQualityEvents();
     109          OnQualityChanged();
     110        }
     111      }
     112    }
     113
    100114    public KnapsackSolution() : base() { }
    101     public KnapsackSolution(BinaryVector binaryVector, IntValue capacity, IntArray weights, IntArray values)
     115    public KnapsackSolution(BinaryVector binaryVector, DoubleValue quality, IntValue capacity, IntArray weights, IntArray values)
    102116      : base() {
    103117      this.binaryVector = binaryVector;
     
    105119      this.weights = weights;
    106120      this.values = values;
     121      this.quality = quality;
    107122      Initialize();
    108123    }
     
    113128    private void Initialize() {
    114129      if (binaryVector != null) RegisterBinaryVectorEvents();
     130      if (quality != null) RegisterQualityEvents();
    115131      if (capacity != null) RegisterCapacityEvents();
    116132      if (weights != null) RegisterWeightsEvents();
     
    122138      cloner.RegisterClonedObject(this, clone);
    123139      clone.binaryVector = (BinaryVector)cloner.Clone(binaryVector);
     140      clone.quality = (DoubleValue)cloner.Clone(quality);
    124141      clone.capacity = (IntValue)cloner.Clone(capacity);
    125142      clone.weights = (IntArray)cloner.Clone(weights);
     
    158175    }
    159176
     177    public event EventHandler QualityChanged;
     178    private void OnQualityChanged() {
     179      var changed = QualityChanged;
     180      if (changed != null)
     181        changed(this, EventArgs.Empty);
     182    }
     183
    160184    private void RegisterBinaryVectorEvents() {
    161185      BinaryVector.ItemChanged += new EventHandler<EventArgs<int>>(BinaryVector_ItemChanged);
     
    196220    }
    197221
     222    private void RegisterQualityEvents() {
     223      Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
     224    }
     225    private void DeregisterQualityEvents() {
     226      Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
     227    }
     228
    198229    private void BinaryVector_ItemChanged(object sender, EventArgs<int> e) {
    199230      OnBinaryVectorChanged();
     
    216247    private void Values_Reset(object sender, EventArgs e) {
    217248      OnValuesChanged();
     249    }
     250    private void Quality_ValueChanged(object sender, EventArgs e) {
     251      OnQualityChanged();
    218252    }
    219253    #endregion
Note: See TracChangeset for help on using the changeset viewer.