Changeset 3641
- Timestamp:
- 05/05/10 16:36:32 (15 years ago)
- 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 81 81 </ItemGroup> 82 82 <ItemGroup> 83 <Compile Include="Analyzers\MultiPopulationBestKnapsackSolutionAnalyzer.cs" /> 84 <Compile Include="Analyzers\PopulationBestKnapsackSolutionAnalyzer.cs" /> 83 85 <Compile Include="Evaluators\KnapsackEvaluator.cs" /> 84 86 <Compile Include="HeuristicLabProblemsKnapsackPlugin.cs" /> 87 <Compile Include="Interfaces\IBestKnapsackSolutionAnalyzer.cs" /> 85 88 <Compile Include="Interfaces\IKnapsackEvaluator.cs" /> 86 <Compile Include="Interfaces\IKnapsackSolutionsVisualizer.cs" />87 89 <Compile Include="Interfaces\IKnapsackMoveEvaluator.cs" /> 88 90 <Compile Include="KnapsackProblem.cs" /> … … 91 93 <Compile Include="MoveEvaluators\KnapsackOneBitflipMoveEvaluator.cs" /> 92 94 <Compile Include="Properties\AssemblyInfo.cs" /> 93 <Compile Include=" Visualizers\BestKnapsackVisualizer.cs" />95 <Compile Include="Analyzers\BestKnapsackSolutionAnalyzer.cs" /> 94 96 </ItemGroup> 95 97 <ItemGroup> -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r3616 r3641 32 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 33 using HeuristicLab.PluginInfrastructure; 34 using HeuristicLab.Problems.Knapsack. Visualizers;34 using HeuristicLab.Problems.Knapsack.Analyzers; 35 35 36 36 namespace HeuristicLab.Problems.Knapsack { … … 120 120 set { BestKnownQualityParameter.Value = value; } 121 121 } 122 private List<I BinaryVectorOperator> operators;122 private List<IOperator> operators; 123 123 public IEnumerable<IOperator> Operators { 124 124 get { return operators.Cast<IOperator>(); } 125 } 126 private IEnumerable<IBestKnapsackSolutionAnalyzer> BestKnapsackSolutionAnalyzers { 127 get { return operators.OfType<IBestKnapsackSolutionAnalyzer>(); } 125 128 } 126 129 #endregion … … 168 171 ParameterizeSolutionCreator(); 169 172 ParameterizeEvaluator(); 170 ParameterizeVisualizer();171 173 172 174 Initialize(); … … 201 203 202 204 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) { 203 SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_ PermutationParameter_ActualNameChanged);204 ParameterizeSolutionCreator(); 205 ParameterizeEvaluator(); 206 Parameterize Visualizer();205 SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_BinaryVectorParameter_ActualNameChanged); 206 ParameterizeSolutionCreator(); 207 ParameterizeEvaluator(); 208 ParameterizeAnalyzers(); 207 209 ParameterizeOperators(); 208 210 OnSolutionCreatorChanged(); 209 211 } 210 private void SolutionCreator_ PermutationParameter_ActualNameChanged(object sender, EventArgs e) {211 ParameterizeEvaluator(); 212 Parameterize Visualizer();212 private void SolutionCreator_BinaryVectorParameter_ActualNameChanged(object sender, EventArgs e) { 213 ParameterizeEvaluator(); 214 ParameterizeAnalyzers(); 213 215 ParameterizeOperators(); 214 216 } 215 217 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 216 218 ParameterizeEvaluator(); 217 Parameterize Visualizer();219 ParameterizeAnalyzers(); 218 220 OnEvaluatorChanged(); 219 221 } 220 222 void KnapsackCapacityParameter_ValueChanged(object sender, EventArgs e) { 221 223 ParameterizeEvaluator(); 222 Parameterize Visualizer();224 ParameterizeAnalyzers(); 223 225 } 224 226 void WeightsParameter_ValueChanged(object sender, EventArgs e) { 225 227 ParameterizeEvaluator(); 226 Parameterize Visualizer();228 ParameterizeAnalyzers(); 227 229 ParameterizeSolutionCreator(); 228 230 … … 237 239 void ValuesParameter_ValueChanged(object sender, EventArgs e) { 238 240 ParameterizeEvaluator(); 239 Parameterize Visualizer();241 ParameterizeAnalyzers(); 240 242 ParameterizeSolutionCreator(); 241 243 … … 264 266 InitializeOperators(); 265 267 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); 266 SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_ PermutationParameter_ActualNameChanged);268 SolutionCreator.BinaryVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_BinaryVectorParameter_ActualNameChanged); 267 269 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 268 270 KnapsackCapacityParameter.ValueChanged += new EventHandler(KnapsackCapacityParameter_ValueChanged); … … 289 291 } 290 292 } 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 } 300 301 } 301 302 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(); 303 308 foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) { 304 309 if (!(op is ISingleObjectiveMoveEvaluator) || (op is IKnapsackMoveEvaluator)) { -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackSolution.cs
r3467 r3641 98 98 } 99 99 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 100 114 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) 102 116 : base() { 103 117 this.binaryVector = binaryVector; … … 105 119 this.weights = weights; 106 120 this.values = values; 121 this.quality = quality; 107 122 Initialize(); 108 123 } … … 113 128 private void Initialize() { 114 129 if (binaryVector != null) RegisterBinaryVectorEvents(); 130 if (quality != null) RegisterQualityEvents(); 115 131 if (capacity != null) RegisterCapacityEvents(); 116 132 if (weights != null) RegisterWeightsEvents(); … … 122 138 cloner.RegisterClonedObject(this, clone); 123 139 clone.binaryVector = (BinaryVector)cloner.Clone(binaryVector); 140 clone.quality = (DoubleValue)cloner.Clone(quality); 124 141 clone.capacity = (IntValue)cloner.Clone(capacity); 125 142 clone.weights = (IntArray)cloner.Clone(weights); … … 158 175 } 159 176 177 public event EventHandler QualityChanged; 178 private void OnQualityChanged() { 179 var changed = QualityChanged; 180 if (changed != null) 181 changed(this, EventArgs.Empty); 182 } 183 160 184 private void RegisterBinaryVectorEvents() { 161 185 BinaryVector.ItemChanged += new EventHandler<EventArgs<int>>(BinaryVector_ItemChanged); … … 196 220 } 197 221 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 198 229 private void BinaryVector_ItemChanged(object sender, EventArgs<int> e) { 199 230 OnBinaryVectorChanged(); … … 216 247 private void Values_Reset(object sender, EventArgs e) { 217 248 OnValuesChanged(); 249 } 250 private void Quality_ValueChanged(object sender, EventArgs e) { 251 OnQualityChanged(); 218 252 } 219 253 #endregion
Note: See TracChangeset
for help on using the changeset viewer.