Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/21/10 18:33:42 (15 years ago)
Author:
svonolfe
Message:

Added simple view for the KnapsackProblem (#917)

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

Legend:

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

    r3384 r3467  
    8787    <Compile Include="Interfaces\IKnapsackMoveEvaluator.cs" />
    8888    <Compile Include="KnapsackProblem.cs" />
     89    <Compile Include="KnapsackSolution.cs" />
    8990    <Compile Include="MoveEvaluators\KnapsackMoveEvaluator.cs" />
    9091    <Compile Include="MoveEvaluators\KnapsackOneBitflipMoveEvaluator.cs" />
    9192    <Compile Include="Properties\AssemblyInfo.cs" />
     93    <Compile Include="Visualizers\BestKnapsackVisualizer.cs" />
    9294  </ItemGroup>
    9395  <ItemGroup>
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Interfaces/IKnapsackSolutionsVisualizer.cs

    r3116 r3467  
    2121
    2222using HeuristicLab.Optimization;
     23using HeuristicLab.Core;
     24using HeuristicLab.Encodings.BinaryVectorEncoding;
     25using HeuristicLab.Data;
    2326
    2427namespace HeuristicLab.Problems.Knapsack {
     
    2629  /// An interface which represents an operator for visualizing solutions of Knapsack Problems.
    2730  /// </summary>
    28   public interface IKnapsackSolutionsVisualizer : ISingleObjectiveSolutionsVisualizer { }
     31  public interface IKnapsackSolutionsVisualizer : ISingleObjectiveSolutionsVisualizer {
     32    ILookupParameter<ItemArray<BinaryVector>> BinaryVectorParameter { get; }
     33    ILookupParameter<IntValue> KnapsackCapacityParameter { get; }
     34    ILookupParameter<IntArray> WeightsParameter { get; }
     35    ILookupParameter<IntArray> ValuesParameter { get; }
     36  }
    2937}
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r3463 r3467  
    3232using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3333using HeuristicLab.PluginInfrastructure;
     34using HeuristicLab.Problems.Knapsack.Visualizers;
    3435
    3536namespace HeuristicLab.Problems.Knapsack {
     
    161162      RandomBinaryVectorCreator creator = new RandomBinaryVectorCreator();
    162163      KnapsackEvaluator evaluator = new KnapsackEvaluator();
     164      IKnapsackSolutionsVisualizer visualizer = new BestKnapsackVisualizer();
    163165
    164166      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Knapsack Problem is a maximization problem.", new BoolValue(true)));
     
    170172      Parameters.Add(new ValueParameter<IKnapsackEvaluator>("Evaluator", "The operator which should be used to evaluate Knapsack solutions.", evaluator));
    171173      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this Knapsack instance."));
    172       Parameters.Add(new ValueParameter<IKnapsackSolutionsVisualizer>("Visualizer", "The operator which should be used to visualize Knapsack solutions.", null));
     174      Parameters.Add(new ValueParameter<IKnapsackSolutionsVisualizer>("Visualizer", "The operator which should be used to visualize Knapsack solutions.", visualizer));
    173175
    174176      creator.BinaryVectorParameter.ActualName = "KnapsackSolution";
     
    179181      ParameterizeSolutionCreator();
    180182      ParameterizeEvaluator();
     183      ParameterizeVisualizer();
    181184
    182185      Initialize();
     
    219222      ParameterizeSolutionCreator();
    220223      ParameterizeEvaluator();
     224      ParameterizeVisualizer();
    221225      ParameterizeOperators();
    222226      OnSolutionCreatorChanged();
     
    224228    private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {
    225229      ParameterizeEvaluator();
     230      ParameterizeVisualizer();
    226231      ParameterizeOperators();
    227232    }
    228233    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    229234      ParameterizeEvaluator();
     235      ParameterizeVisualizer();
    230236      OnEvaluatorChanged();
    231237    }
    232238    void KnapsackCapacityParameter_ValueChanged(object sender, EventArgs e) {
    233239      ParameterizeEvaluator();
     240      ParameterizeVisualizer();
    234241    }
    235242    void WeightsParameter_ValueChanged(object sender, EventArgs e) {
    236243      ParameterizeEvaluator();
     244      ParameterizeVisualizer();
    237245      ParameterizeSolutionCreator();
    238246
     
    247255    void ValuesParameter_ValueChanged(object sender, EventArgs e) {
    248256      ParameterizeEvaluator();
     257      ParameterizeVisualizer();
    249258      ParameterizeSolutionCreator();
    250259
     
    302311      }
    303312    }
     313    private void ParameterizeVisualizer() {
     314      if (Visualizer is IKnapsackSolutionsVisualizer) {
     315        IKnapsackSolutionsVisualizer visualizer =
     316          (IKnapsackSolutionsVisualizer)Visualizer;
     317        visualizer.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
     318        visualizer.KnapsackCapacityParameter.ActualName = KnapsackCapacityParameter.Name;
     319        visualizer.WeightsParameter.ActualName = WeightsParameter.Name;
     320        visualizer.ValuesParameter.ActualName = ValuesParameter.Name;
     321      }
     322    }
    304323    private void InitializeOperators() {
    305324      operators = new List<IBinaryVectorOperator>();
Note: See TracChangeset for help on using the changeset viewer.