Changeset 15182
- Timestamp:
- 07/10/17 17:41:38 (7 years ago)
- Location:
- branches/BinPackingExtension
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking
-
Property
svn:mergeinfo
set to
/trunk/sources/HeuristicLab.Problems.BinPacking merged eligible
-
Property
svn:mergeinfo
set to
-
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views
-
Property
svn:mergeinfo
set to
/trunk/sources/HeuristicLab.Problems.BinPacking.Views merged eligible
-
Property
svn:mergeinfo
set to
-
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml
r14835 r15182 30 30 MouseWheel="Container3DView_OnMouseWheel" 31 31 MouseEnter="Container3DView_OnMouseEnter" 32 KeyDown="Container3DView_OnKeyDown"33 32 Focusable="true" 34 33 > 35 34 <Grid> 36 < Viewport3D Name="viewport3D1">37 <Viewport3D .Camera>38 < PerspectiveCamera x:Name="camMain" Position="0.5 8 8" LookDirection="0 -1 -1"> <!-- camera position for design time-->39 </PerspectiveCamera>40 </Viewport3D.Camera>41 <ModelVisual3D>42 <ModelVisual3D .Content>43 < DirectionalLight x:Name="dirLightMain" Direction="0,-1,-1"/>44 </ModelVisual3D.Content>45 </ModelVisual3D>46 <ModelVisual3D>47 </ModelVisual3D>48 <ModelVisual3D x:Name="MyModel">49 <ModelVisual3D .Content>50 <Model 3DGroup>51 </Model3DGroup>52 </ModelVisual3D.Content>53 <ModelVisual3D.Transform>54 < Transform3DGroup>55 < ScaleTransform3D x:Name="scale" ScaleX="1" ScaleY="1" ScaleZ="1"/>56 <TranslateTransform3D OffsetX="-0.5" OffsetY="-0.5" OffsetZ="-0.5"/>57 <RotateTransform3D>58 <RotateTransform3D.Rotation>59 <AxisAngleRotation3D x:Name="rotateX"Axis="0 1 0"/>60 </RotateTransform3D.Rotation>61 </RotateTransform3D>62 <RotateTransform3D>63 <RotateTransform3D.Rotation>64 <AxisAngleRotation3D x:Name="rotateY"Axis="1 0 0"/>65 </RotateTransform3D.Rotation>66 </RotateTransform3D>67 <TranslateTransform3D OffsetX="0.5" OffsetY="0.5" OffsetZ="0.5"/>68 < ScaleTransform3D x:Name="scaleZoom" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="1" ScaleY="1" ScaleZ="1"/>69 </ Transform3DGroup>70 </ModelVisual3D .Transform>71 </ ModelVisual3D>72 </ Viewport3D>35 <Border BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"> 36 <Viewport3D Name="viewport3D1" > 37 <Viewport3D.Camera> 38 <PerspectiveCamera x:Name="camMain" Position="0.5 8 8" LookDirection="0 -1 -1"> <!-- camera position for design time--> 39 </PerspectiveCamera> 40 </Viewport3D.Camera> 41 <ModelVisual3D> 42 <ModelVisual3D.Content> 43 <DirectionalLight x:Name="dirLightMain" Direction="0,-1,-1"/> 44 </ModelVisual3D.Content> 45 </ModelVisual3D> 46 <ModelVisual3D> 47 </ModelVisual3D> 48 <ModelVisual3D x:Name="MyModel"> 49 <ModelVisual3D.Content> 50 <Model3DGroup> 51 </Model3DGroup> 52 </ModelVisual3D.Content> 53 <ModelVisual3D.Transform> 54 <Transform3DGroup> 55 <ScaleTransform3D x:Name="scale" ScaleX="1" ScaleY="1" ScaleZ="1"/> 56 <RotateTransform3D x:Name="rotateX"> 57 <RotateTransform3D.Rotation> 58 <AxisAngleRotation3D Axis="0 1 0"/> 59 </RotateTransform3D.Rotation> 60 </RotateTransform3D> 61 <RotateTransform3D x:Name="rotateY"> 62 <RotateTransform3D.Rotation> 63 <AxisAngleRotation3D Axis="1 0 0"/> 64 </RotateTransform3D.Rotation> 65 </RotateTransform3D> 66 <ScaleTransform3D x:Name="scaleZoom" ScaleX="1" ScaleY="1" ScaleZ="1"/> 67 </Transform3DGroup> 68 </ModelVisual3D.Transform> 69 </ModelVisual3D> 70 </Viewport3D> 71 </Border> 73 72 </Grid> 74 73 </UserControl> -
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs
r14835 r15182 46 46 Color.FromRgb(0x63, 0xC2, 0x16), 47 47 }; 48 48 49 49 private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA); 50 50 private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA); … … 52 52 private Point startPos; 53 53 private bool mouseDown = false; 54 private bool ctrlDown = false;55 54 private double startAngleX; 56 55 private double startAngleY; … … 103 102 var hiddenMaterial = new DiffuseMaterial(new SolidColorBrush(hiddenColor)); 104 103 105 foreach (var item in packing.Items) { 106 var position = packing.Positions[item.Key]; 107 108 var w = position.Rotated ? item.Value.Depth : item.Value.Width; 109 var h = item.Value.Height; 110 var d = position.Rotated ? item.Value.Width : item.Value.Depth; 111 112 var model = new GeometryModel3D { Geometry = new MeshGeometry3D() }; 113 DiffuseMaterial material; 114 if (selectedItemKey >= 0 && selectedItemKey != item.Key) 115 material = hiddenMaterial; 116 else { 104 if (selectedItemKey >= 0) { 105 var selectedItem = packing.Items.Single(x => selectedItemKey == x.Key); 106 var selectedPos = packing.Positions[selectedItem.Key]; 107 108 var colorIdx = selectedItem.Value.Material; 109 while (colorIdx < 0) colorIdx += colors.Length; 110 colorIdx = colorIdx % colors.Length; 111 var color = colors[colorIdx]; 112 var material = new DiffuseMaterial { Brush = new SolidColorBrush(color) }; 113 materials[selectedItem.Value.Material] = material; 114 115 var selectedModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = material }; 116 AddSolidCube((MeshGeometry3D)selectedModel.Geometry, selectedPos.X, selectedPos.Y, selectedPos.Z, 117 selectedPos.Rotated ? selectedItem.Value.Depth : selectedItem.Value.Width, 118 selectedItem.Value.Height, 119 selectedPos.Rotated ? selectedItem.Value.Width : selectedItem.Value.Depth); 120 modelGroup.Children.Add(selectedModel); 121 122 foreach (var item in packing.Items.Where(x => selectedItemKey != x.Key)) { 123 var position = packing.Positions[item.Key]; 124 125 var w = position.Rotated ? item.Value.Depth : item.Value.Width; 126 var h = item.Value.Height; 127 var d = position.Rotated ? item.Value.Width : item.Value.Depth; 128 129 var model = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = hiddenMaterial }; 130 AddWireframeCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d, 1); 131 modelGroup.Children.Add(model); 132 } 133 } else { 134 foreach (var item in packing.Items) { 135 var position = packing.Positions[item.Key]; 136 137 var w = position.Rotated ? item.Value.Depth : item.Value.Width; 138 var h = item.Value.Height; 139 var d = position.Rotated ? item.Value.Width : item.Value.Depth; 140 141 var model = new GeometryModel3D { Geometry = new MeshGeometry3D() }; 142 DiffuseMaterial material; 117 143 if (!materials.TryGetValue(item.Value.Material, out material)) { 118 144 var colorIdx = item.Value.Material; … … 123 149 materials[item.Value.Material] = material; 124 150 } 151 var selectedModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = material }; 152 AddSolidCube((MeshGeometry3D)selectedModel.Geometry, position.X, position.Y, position.Z, w, h, d); 153 modelGroup.Children.Add(selectedModel); 125 154 } 126 model.Material = material;127 modelGroup.Children.Add(model);128 129 AddSolidCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d);130 155 } 131 156 … … 140 165 scale.ScaleZ = 1.0 / ratio; 141 166 142 scale.CenterX = .5; 143 scale.CenterY = .5; 144 scale.CenterZ = 0; 167 scaleZoom.CenterX = rotateX.CenterX = rotateY.CenterX = container.Width / (2.0 * ratio); 168 scaleZoom.CenterY = rotateX.CenterY = rotateY.CenterY = container.Height / (2.0 * ratio); 169 scaleZoom.CenterZ = rotateX.CenterZ = rotateY.CenterZ = container.Depth / (2.0 * ratio); 170 171 camMain.Position = new Point3D( 172 scaleZoom.CenterX, 173 3, 174 3); 175 camMain.LookDirection = new Vector3D( 176 0, 177 scaleZoom.CenterY - camMain.Position.Y, 178 scaleZoom.CenterZ - camMain.Position.Z); 145 179 } 146 180 … … 149 183 ((Model3DGroup)MyModel.Content).Children.Clear(); 150 184 materials.Clear(); 151 185 152 186 mouseDown = false; 153 187 startAngleX = 0; … … 158 192 if (!mouseDown) return; 159 193 var pos = e.GetPosition((IInputElement)this); 160 161 rotateX.Angle = startAngleX + (pos.X - startPos.X) / 4;162 rotateY.Angle = startAngleY + (pos.Y - startPos.Y) / 4;194 195 ((AxisAngleRotation3D)rotateX.Rotation).Angle = startAngleX + (pos.X - startPos.X) / 4; 196 ((AxisAngleRotation3D)rotateY.Rotation).Angle = startAngleY + (pos.Y - startPos.Y) / 4; 163 197 } 164 198 165 199 private void Container3DView_MouseDown(object sender, MouseButtonEventArgs e) { 166 startAngleX = rotateX.Angle;167 startAngleY = rotateY.Angle;200 startAngleX = ((AxisAngleRotation3D)rotateX.Rotation).Angle; 201 startAngleY = ((AxisAngleRotation3D)rotateY.Rotation).Angle; 168 202 this.startPos = e.GetPosition((IInputElement)this); 169 203 this.mouseDown = true; … … 189 223 Focus(); // for mouse wheel events 190 224 } 191 192 private void Container3DView_OnKeyDown(object sender, KeyEventArgs e) {193 ctrlDown = e.Key.HasFlag(Key.LeftCtrl) || e.Key.HasFlag(Key.RightCtrl);194 }195 196 225 197 226 #region helper for cubes … … 302 331 mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth)); 303 332 304 AddPlane(mesh, 0, 4, 6, 2); 305 AddPlane(mesh, 0, 3, 5, 4); 306 307 AddPlane(mesh, 4, 8, 10, 6); 308 AddPlane(mesh, 4, 7, 9, 8); 309 310 AddPlane(mesh, 8, 12, 14, 10); 311 AddPlane(mesh, 8, 11, 13, 12); 312 313 AddPlane(mesh, 0, 2, 14, 12); 314 AddPlane(mesh, 0, 12, 15, 1); 315 316 AddPlane(mesh, 0, 1, 17, 16); 317 AddPlane(mesh, 0, 16, 19, 3); 318 319 AddPlane(mesh, 4, 20, 23, 7); 320 AddPlane(mesh, 4, 5, 21, 20); 321 322 AddPlane(mesh, 8, 24, 27, 11); 323 AddPlane(mesh, 8, 9, 25, 24); 324 325 AddPlane(mesh, 12, 28, 31, 15); 326 AddPlane(mesh, 12, 13, 29, 28); 327 328 AddPlane(mesh, 16, 18, 22, 20); 329 AddPlane(mesh, 16, 20, 21, 19); 330 331 AddPlane(mesh, 20, 22, 26, 24); 332 AddPlane(mesh, 20, 24, 25, 23); 333 334 AddPlane(mesh, 24, 28, 29, 27); 335 AddPlane(mesh, 24, 26, 30, 28); 336 337 AddPlane(mesh, 28, 30, 18, 16); 338 AddPlane(mesh, 28, 16, 17, 31); 333 // Point 0, non-edge 334 mesh.Positions.Add(new Point3D(x + thickness, y, z + thickness)); 335 mesh.Positions.Add(new Point3D(x, y + thickness, z + thickness)); 336 mesh.Positions.Add(new Point3D(x + thickness, y + thickness, z)); 337 338 // Point 1, non-edge 339 mesh.Positions.Add(new Point3D(x + width, y + thickness, z + thickness)); 340 mesh.Positions.Add(new Point3D(x + width - thickness, y, z + thickness)); 341 mesh.Positions.Add(new Point3D(x + width - thickness, y + thickness, z)); 342 343 // Point 2, non-edge 344 mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + thickness)); 345 mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + thickness)); 346 mesh.Positions.Add(new Point3D(x + width - thickness, y + height - thickness, z)); 347 348 // Point 3, non-edge 349 mesh.Positions.Add(new Point3D(x, y + height - thickness, z + thickness)); 350 mesh.Positions.Add(new Point3D(x + thickness, y + height, z + thickness)); 351 mesh.Positions.Add(new Point3D(x + thickness, y + height - thickness, z)); 352 353 // Point 4, non-edge 354 mesh.Positions.Add(new Point3D(x + thickness, y, z + depth - thickness)); 355 mesh.Positions.Add(new Point3D(x, y + thickness, z + depth - thickness)); 356 mesh.Positions.Add(new Point3D(x + thickness, y + thickness, z + depth)); 357 358 // Point 5, non-edge 359 mesh.Positions.Add(new Point3D(x + width, y + thickness, z + depth - thickness)); 360 mesh.Positions.Add(new Point3D(x + width - thickness, y, z + depth - thickness)); 361 mesh.Positions.Add(new Point3D(x + width - thickness, y + thickness, z + depth)); 362 363 // Point 6, non-edge 364 mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + depth - thickness)); 365 mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + depth - thickness)); 366 mesh.Positions.Add(new Point3D(x + width - thickness, y + height - thickness, z + depth)); 367 368 // Point 7, non-edge 369 mesh.Positions.Add(new Point3D(x, y + height - thickness, z + depth - thickness)); 370 mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth - thickness)); 371 mesh.Positions.Add(new Point3D(x + thickness, y + height - thickness, z + depth)); 372 373 // Draw the 24 corner plates 374 AddPlane(mesh, 0, 1, 32, 2); 375 AddPlane(mesh, 0, 2, 33, 3); 376 AddPlane(mesh, 0, 3, 34, 1); 377 378 AddPlane(mesh, 4, 6, 36, 7); 379 AddPlane(mesh, 4, 5, 35, 6); 380 AddPlane(mesh, 4, 7, 37, 5); 381 382 AddPlane(mesh, 8, 10, 39, 11); 383 AddPlane(mesh, 8, 9, 38, 10); 384 AddPlane(mesh, 8, 11, 40, 9); 385 386 AddPlane(mesh, 12, 13, 41, 14); 387 AddPlane(mesh, 12, 14, 42, 15); 388 AddPlane(mesh, 12, 15, 43, 13); 389 390 AddPlane(mesh, 16, 18, 44, 17); 391 AddPlane(mesh, 16, 19, 45, 18); 392 AddPlane(mesh, 16, 17, 46, 19); 393 394 AddPlane(mesh, 20, 23, 48, 22); 395 AddPlane(mesh, 20, 22, 47, 21); 396 AddPlane(mesh, 20, 21, 49, 23); 397 398 AddPlane(mesh, 24, 27, 51, 26); 399 AddPlane(mesh, 24, 26, 50, 25); 400 AddPlane(mesh, 24, 25, 52, 27); 401 402 AddPlane(mesh, 28, 31, 54, 30); 403 AddPlane(mesh, 28, 30, 53, 29); 404 AddPlane(mesh, 28, 29, 55, 31); 405 406 // Draw the connecting plates 407 // on the bottom 408 AddPlane(mesh, 1, 7, 36, 32); 409 AddPlane(mesh, 1, 34, 37, 7); 410 411 AddPlane(mesh, 5, 11, 39, 35); 412 AddPlane(mesh, 5, 37, 40, 11); 413 414 AddPlane(mesh, 9, 15, 42, 38); 415 AddPlane(mesh, 9, 40, 43, 15); 416 417 AddPlane(mesh, 13, 3, 33, 41); 418 AddPlane(mesh, 13, 43, 34, 3); 419 420 // between bottom and top 421 AddPlane(mesh, 2, 32, 44, 18); 422 AddPlane(mesh, 2, 18, 45, 33); 423 424 AddPlane(mesh, 6, 22, 48, 36); 425 AddPlane(mesh, 6, 35, 47, 22); 426 427 AddPlane(mesh, 10, 26, 51, 39); 428 AddPlane(mesh, 10, 38, 50, 26); 429 430 AddPlane(mesh, 14, 30, 54, 42); 431 AddPlane(mesh, 14, 41, 53, 30); 432 433 // on the top 434 AddPlane(mesh, 17, 44, 48, 23); 435 AddPlane(mesh, 17, 23, 49, 46); 436 437 AddPlane(mesh, 21, 47, 51, 27); 438 AddPlane(mesh, 21, 27, 52, 49); 439 440 AddPlane(mesh, 25, 50, 54, 31); 441 AddPlane(mesh, 25, 31, 55, 52); 442 443 AddPlane(mesh, 29, 19, 46, 55); 444 AddPlane(mesh, 29, 53, 45, 19); 339 445 } 340 446 -
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/BinPacking2D.cs
r14976 r15182 83 83 rotated ? item.Height : item.Width, 84 84 rotated ? item.Width : item.Height, 85 item.TargetBin); 85 item.TargetBin) { 86 Material = item.Material, 87 Weight = item.Weight 88 }; 86 89 87 90 int epIndex = 0; -
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/IntegerVectorEncoding/IntegerVectorProblem.cs
r14162 r15182 24 24 using System.Collections.Generic; 25 25 using System.Linq; 26 using HeuristicLab.Analysis; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; 28 29 using HeuristicLab.Encodings.IntegerVectorEncoding; 29 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Optimization.Operators; 30 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 33 … … 52 54 Encoding = new IntegerVectorEncoding(EncodedSolutionName, Items.Count, min: 0, max: LowerBound + 1); // NOTE: assumes that all items can be packed into LowerBound+1 bins 53 55 AddOperators(); 56 Parameterize(); 54 57 RegisterEventHandlers(); 55 58 } … … 63 66 } 64 67 68 protected override void OnEncodingChanged() { 69 base.OnEncodingChanged(); 70 Parameterize(); 71 } 65 72 66 73 private void AddOperators() { 67 68 74 // move operators are not yet supported (TODO) 69 75 Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator); 70 76 Operators.RemoveAll(x => x is SingleObjectiveMoveMaker); 71 77 Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator); 78 Operators.Add(new HammingSimilarityCalculator()); 79 Operators.Add(new EuclideanSimilarityCalculator()); 80 Operators.Add(new QualitySimilarityCalculator()); 81 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 72 82 73 Encoding.ConfigureOperators(Operators.OfType<IOperator>()); // gkronber: not strictly necessary (only when customer ops are added)83 Encoding.ConfigureOperators(Operators.OfType<IOperator>()); 74 84 } 75 85 76 86 private void RegisterEventHandlers() { 77 87 // update encoding length when number of items is changed 78 ItemsParameter.ValueChanged += (sender, args) => Encoding.Length = Items.Count; 79 LowerBoundParameter.Value.ValueChanged += (sender, args) => { 80 for (int i = 0; i < Encoding.Bounds.Rows; i++) { 81 Encoding.Bounds[i, 1] = LowerBound + 1; 82 } 83 }; 88 ItemsParameter.ValueChanged += (sender, args) => Parameterize(); 89 LowerBoundParameter.Value.ValueChanged += (sender, args) => Parameterize(); 84 90 } 85 91 … … 96 102 return result; 97 103 } 104 105 private void Parameterize() { 106 Encoding.Length = Items.Count; 107 for (int i = 0; i < Encoding.Bounds.Rows; i++) { 108 Encoding.Bounds[i, 1] = LowerBound + 1; 109 } 110 foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) { 111 similarityCalculator.SolutionVariableName = Encoding.SolutionCreator.IntegerVectorParameter.ActualName; 112 similarityCalculator.QualityVariableName = Evaluator.QualityParameter.ActualName; 113 } 114 } 98 115 #endregion 99 116 } -
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/PermutationEncoding/PermutationProblem.cs
r14162 r15182 23 23 24 24 using System.Linq; 25 using System.Windows.Forms;25 using HeuristicLab.Analysis; 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Encodings.PermutationEncoding; 29 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Optimization.Operators; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 … … 51 52 Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute); 52 53 AddOperators(); 54 Parameterize(); 53 55 RegisterEventHandlers(); 54 56 } … … 62 64 } 63 65 66 protected override void OnEncodingChanged() { 67 base.OnEncodingChanged(); 68 Parameterize(); 69 } 64 70 65 71 private void AddOperators() { … … 70 76 Operators.RemoveAll(x => x is SingleObjectiveMoveMaker); 71 77 Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator); 78 Operators.Add(new HammingSimilarityCalculator()); 79 Operators.Add(new QualitySimilarityCalculator()); 80 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 72 81 73 82 Encoding.ConfigureOperators(Operators.OfType<IOperator>()); … … 83 92 private void RegisterEventHandlers() { 84 93 // update encoding length when number of items is changed 85 ItemsParameter.ValueChanged += (sender, args) => Encoding.Length = Items.Count; 94 ItemsParameter.ValueChanged += (sender, args) => Parameterize(); 95 } 96 97 private void Parameterize() { 98 Encoding.Length = Items.Count; 99 foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) { 100 similarityCalculator.SolutionVariableName = Encoding.SolutionCreator.PermutationParameter.ActualName; 101 similarityCalculator.QualityVariableName = Evaluator.QualityParameter.ActualName; 102 } 86 103 } 87 104 } -
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/IntegerVectorEncoding/IntegerVectorProblem.cs
r14167 r15182 24 24 using System.Collections.Generic; 25 25 using System.Linq; 26 using HeuristicLab.Analysis; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; 28 29 using HeuristicLab.Encodings.IntegerVectorEncoding; 29 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Optimization.Operators; 30 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 33 … … 51 53 Encoding = new IntegerVectorEncoding(EncodedSolutionName, Items.Count, min: 0, max: LowerBound + 1); // NOTE: assumes that all items can be packed into LowerBound+1 bins 52 54 AddOperators(); 55 Parameterize(); 53 56 RegisterEventHandlers(); 54 57 } … … 62 65 } 63 66 67 protected override void OnEncodingChanged() { 68 base.OnEncodingChanged(); 69 Parameterize(); 70 } 64 71 65 72 private void AddOperators() { 66 67 73 // move operators are not yet supported (TODO) 68 74 Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator); 69 75 Operators.RemoveAll(x => x is SingleObjectiveMoveMaker); 70 76 Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator); 77 Operators.Add(new HammingSimilarityCalculator()); 78 Operators.Add(new EuclideanSimilarityCalculator()); 79 Operators.Add(new QualitySimilarityCalculator()); 80 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 71 81 72 82 Encoding.ConfigureOperators(Operators.OfType<IOperator>()); // gkronber: not strictly necessary (only when customer ops are added) … … 75 85 private void RegisterEventHandlers() { 76 86 // update encoding length when number of items is changed 77 ItemsParameter.ValueChanged += (sender, args) => Encoding.Length = Items.Count; 78 LowerBoundParameter.Value.ValueChanged += (sender, args) => { 79 for (int i = 0; i < Encoding.Bounds.Rows; i++) { 80 Encoding.Bounds[i, 1] = LowerBound + 1; 81 } 82 }; 87 ItemsParameter.ValueChanged += (sender, args) => Parameterize(); 88 LowerBoundParameter.Value.ValueChanged += (sender, args) => Parameterize(); 83 89 } 84 90 85 91 #region helpers 86 87 92 public static List<List<int>> GenerateSequenceMatrix(IntegerVector intVec) { 88 93 List<List<int>> result = new List<List<int>>(); … … 95 100 return result; 96 101 } 102 103 private void Parameterize() { 104 Encoding.Length = Items.Count; 105 for (int i = 0; i < Encoding.Bounds.Rows; i++) { 106 Encoding.Bounds[i, 1] = LowerBound + 1; 107 } 108 foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) { 109 similarityCalculator.SolutionVariableName = Encoding.SolutionCreator.IntegerVectorParameter.ActualName; 110 similarityCalculator.QualityVariableName = Evaluator.QualityParameter.ActualName; 111 } 112 } 97 113 #endregion 98 114 } -
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/PermutationProblem.cs
r14167 r15182 23 23 24 24 using System.Linq; 25 using HeuristicLab.Analysis; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Encodings.PermutationEncoding; 28 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Optimization.Operators; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 32 … … 49 51 Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute); 50 52 AddOperators(); 53 Parameterize(); 51 54 RegisterEventHandlers(); 52 55 } … … 60 63 } 61 64 65 protected override void OnEncodingChanged() { 66 base.OnEncodingChanged(); 67 Parameterize(); 68 } 62 69 63 70 private void AddOperators() { … … 68 75 Operators.RemoveAll(x => x is SingleObjectiveMoveMaker); 69 76 Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator); 77 Operators.Add(new HammingSimilarityCalculator()); 78 Operators.Add(new QualitySimilarityCalculator()); 79 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 70 80 71 81 Encoding.ConfigureOperators(Operators.OfType<IOperator>()); … … 82 92 private void RegisterEventHandlers() { 83 93 // update encoding length when number of items is changed 84 ItemsParameter.ValueChanged += (sender, args) => Encoding.Length = Items.Count; 94 ItemsParameter.ValueChanged += (sender, args) => Parameterize(); 95 } 96 97 private void Parameterize() { 98 Encoding.Length = Items.Count; 99 foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) { 100 similarityCalculator.SolutionVariableName = Encoding.SolutionCreator.PermutationParameter.ActualName; 101 similarityCalculator.QualityVariableName = Evaluator.QualityParameter.ActualName; 102 } 85 103 } 86 104 } -
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/Plugin.cs.frame
r14174 r15182 28 28 [Plugin("HeuristicLab.Problems.BinPacking", "3.3.14.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.BinPacking-3.3.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.Analysis", "3.3")] 30 31 [PluginDependency("HeuristicLab.Collections", "3.3")] 31 32 [PluginDependency("HeuristicLab.Common", "3.3")] … … 36 37 [PluginDependency("HeuristicLab.Operators", "3.3")] 37 38 [PluginDependency("HeuristicLab.Optimization", "3.3")] 39 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 38 40 [PluginDependency("HeuristicLab.Parameters", "3.3")] 39 41 [PluginDependency("HeuristicLab.Persistence", "3.3")]
Note: See TracChangeset
for help on using the changeset viewer.