Changeset 15278


Ignore:
Timestamp:
07/21/17 11:29:08 (2 years ago)
Author:
abeham
Message:

#2762, #2739: merged revisions 14708, 14709, 14971, 14978, 14979, 15167, 15230, 15233, 15240, 15241, 15276 to stable

Location:
stable
Files:
18 edited
8 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Optimizer

  • stable/HeuristicLab.Problems.BinPacking

    • Property svn:mergeinfo set to (toggle deleted branches)
      /trunk/sources/HeuristicLab.Problems.BinPackingmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Problems.BinPacking10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.BinPacking5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Problems.BinPacking6917-7005
      /branches/BinPackingExtension/HeuristicLab.Problems.BinPacking14835-15229
      /branches/CloningRefactoring/HeuristicLab.Problems.BinPacking4656-4721
      /branches/CodeEditor/HeuristicLab.Problems.BinPacking11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.BinPacking5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.BinPacking5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.BinPacking4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.BinPacking10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.BinPacking6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.BinPacking5060
      /branches/HLScript/HeuristicLab.Problems.BinPacking10331-10358
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.BinPacking11570-12508
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.BinPacking6123-9799
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.BinPacking11130-12721
      /branches/HiveStatistics/sources/HeuristicLab.Problems.BinPacking12440-12877
      /branches/LogResidualEvaluator/HeuristicLab.Problems.BinPacking10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.BinPacking5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Problems.BinPacking12033-12122
      /branches/ParallelEngine/HeuristicLab.Problems.BinPacking5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.BinPacking7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.BinPacking6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.BinPacking6828
      /branches/RuntimeOptimizer/HeuristicLab.Problems.BinPacking8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.BinPacking7787-8333
      /branches/SlaveShutdown/HeuristicLab.Problems.BinPacking8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.BinPacking10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.BinPacking5370-5682
      /branches/Trunk/HeuristicLab.Problems.BinPacking6829-6865
      /branches/UnloadJobs/HeuristicLab.Problems.BinPacking9168-9215
      /branches/VNS/HeuristicLab.Problems.BinPacking5594-5752
      /branches/crossvalidation-2434/HeuristicLab.Problems.BinPacking12948-12950
      /branches/histogram/HeuristicLab.Problems.BinPacking5959-6341
      /branches/symbreg-factors-2650/HeuristicLab.Problems.BinPacking14232-14825
      /trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/HeuristicLab.Problems.BinPacking14175
  • stable/HeuristicLab.Problems.BinPacking.Views

    • Property svn:mergeinfo set to (toggle deleted branches)
      /trunk/sources/HeuristicLab.Problems.BinPacking.Viewsmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Problems.BinPacking.Views10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.BinPacking.Views5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Problems.BinPacking.Views6917-7005
      /branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views14835-15229
      /branches/CloningRefactoring/HeuristicLab.Problems.BinPacking.Views4656-4721
      /branches/CodeEditor/HeuristicLab.Problems.BinPacking.Views11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.BinPacking.Views5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.BinPacking.Views5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.BinPacking.Views4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.BinPacking.Views10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.BinPacking.Views6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.BinPacking.Views5060
      /branches/HLScript/HeuristicLab.Problems.BinPacking.Views10331-10358
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.BinPacking.Views11570-12508
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.BinPacking.Views6123-9799
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.BinPacking.Views11130-12721
      /branches/HiveStatistics/sources/HeuristicLab.Problems.BinPacking.Views12440-12877
      /branches/LogResidualEvaluator/HeuristicLab.Problems.BinPacking.Views10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.BinPacking.Views5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Problems.BinPacking.Views12033-12122
      /branches/ParallelEngine/HeuristicLab.Problems.BinPacking.Views5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.BinPacking.Views7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.BinPacking.Views6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.BinPacking.Views6828
      /branches/RuntimeOptimizer/HeuristicLab.Problems.BinPacking.Views8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.BinPacking.Views7787-8333
      /branches/SlaveShutdown/HeuristicLab.Problems.BinPacking.Views8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.BinPacking.Views10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.BinPacking.Views5370-5682
      /branches/Trunk/HeuristicLab.Problems.BinPacking.Views6829-6865
      /branches/UnloadJobs/HeuristicLab.Problems.BinPacking.Views9168-9215
      /branches/VNS/HeuristicLab.Problems.BinPacking.Views5594-5752
      /branches/crossvalidation-2434/HeuristicLab.Problems.BinPacking.Views12948-12950
      /branches/histogram/HeuristicLab.Problems.BinPacking.Views5959-6341
      /branches/symbreg-factors-2650/HeuristicLab.Problems.BinPacking.Views14232-14825
      /trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/HeuristicLab.Problems.BinPacking.Views14175
  • stable/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml

    r14162 r15278  
    3333             >
    3434    <Grid>
    35         <Viewport3D Name="viewport3D1" >
    36             <Viewport3D.Camera>
    37                 <PerspectiveCamera x:Name="camMain" Position="0.5 8 8" LookDirection="0 -1 -1"> <!-- camera position for design time-->
    38                 </PerspectiveCamera>
    39             </Viewport3D.Camera>
    40             <ModelVisual3D>
    41                 <ModelVisual3D.Content>
    42                     <DirectionalLight x:Name="dirLightMain" Direction="0,-1,-1"/>
    43                 </ModelVisual3D.Content>
    44             </ModelVisual3D>
    45             <ModelVisual3D>
    46             </ModelVisual3D>
    47             <ModelVisual3D x:Name="MyModel">
    48                 <ModelVisual3D.Content>
    49                     <Model3DGroup>
    50                         <GeometryModel3D>
    51                             <GeometryModel3D.Geometry>
    52                                 <!-- two opaque cubes, one in front one in back-->
    53                                 <MeshGeometry3D x:Name="meshMain"
    54                                 Positions="0 0 -2.5 1 0 -2.5  0 1 -2.5  1 1 -2.5  0 0 -1.5  1 0 -1.5  0 1 -1.5  1 1 -1.5
    55                                            0 0 0 1 0 0  0 1 0  1 1 0  0 0 1  1 0 1  0 1 1  1 1 1"
    56                                 TriangleIndices="10 11 9  10 9 8  15 9 11  15 13 9  14 13 15  14 12 13  14 10 12  10 8 12  10 15 11  10 14 15  0 9 13  8 13 12
    57                                                  2 3 1  2 1 0  7 1 3  7 5 1  6 5 7  6 4 5  6 2 4  2 0 4  2 7 3  2 6 7  0 1 5  0 5 4 ">
    58                                 </MeshGeometry3D>
    59                             </GeometryModel3D.Geometry>
    60                             <GeometryModel3D.Material>
    61                                 <DiffuseMaterial>
    62                                     <DiffuseMaterial.Brush>
    63                                         <SolidColorBrush Color="LightGreen"/>
    64                                     </DiffuseMaterial.Brush>
    65                                 </DiffuseMaterial>
    66                             </GeometryModel3D.Material>
    67                         </GeometryModel3D>
    68                         <GeometryModel3D>
    69                             <GeometryModel3D.Geometry>
    70                                 <!-- two transparent cubes, one in front one in back-->
    71                                 <!-- draw transparent cubes from back to front and always draw outer and inner triangles and draw from front to back-->
    72                                 <MeshGeometry3D x:Name="meshInsides"
    73                                 Positions="-1 -1 -1  2 -1 -1  -1 2 -1  2 2 -1  -1 -1 2  2 -1 2  -1 2 2  2 2 2
    74                                            -1 -1 -3  2 -1 -3  -1 2 -3  2 2 -3  -1 -1 -1  2 -1 -1  -1 2 -1  2 2 -1"
    75                                 TriangleIndices="9 11 10  8 9 10  11 9 15  9 13 15  15 13 14  13 12 14  12 10 14  12 8 10  11 15 10  15 14 10  13 9 8  12 13 8
    76                                                  1 3 2  0 1 2  3 1 7  1 5 7  7 5 6  5 4 6  4 2 6  4 0 2  3 7 2  7 6 2  5 1 0  4 5 0
    77                                                  ">
    78                                 </MeshGeometry3D>
    79                             </GeometryModel3D.Geometry>
    80                             <GeometryModel3D.Material>
    81                                 <MaterialGroup>
    82                                     <DiffuseMaterial>
    83                                         <DiffuseMaterial.Brush>
    84                                             <SolidColorBrush Opacity="0.1"  Color="DarkGray"/>
    85                                         </DiffuseMaterial.Brush>
    86                                     </DiffuseMaterial>
    87                                 </MaterialGroup>
    88                             </GeometryModel3D.Material>
    89                         </GeometryModel3D>
    90                         <GeometryModel3D>
    91                             <GeometryModel3D.Geometry>
    92                                 <!-- two transparent cubes, one in front one in back-->
    93                                 <!-- draw transparent cubes from back to front and always draw outer and inner triangles and draw from front to back-->
    94                                 <MeshGeometry3D x:Name="meshTransparent"
    95                                 Positions="-1 -1 -1  2 -1 -1  -1 2 -1  2 2 -1  -1 -1 2  2 -1 2  -1 2 2  2 2 2
    96                                            -1 -1 -3  2 -1 -3  -1 2 -3  2 2 -3  -1 -1 -1  2 -1 -1  -1 2 -1  2 2 -1"
    97                                 TriangleIndices="2 3 1  2 1 0  7 1 3  7 5 1  6 5 7  6 4 5  6 2 4  2 0 4  2 7 3  2 6 7  0 1 5  0 5 4                                                 
    98                                                  10 11 9  10 9 8  15 9 11  15 13 9  14 13 15  14 12 13  14 10 12  10 8 12  10 15 11  10 14 15  0 9 13  8 13 12
    99                                                  ">
    100                                 </MeshGeometry3D>
    101                             </GeometryModel3D.Geometry>
    102                             <GeometryModel3D.Material>
    103                                 <MaterialGroup>
    104                                     <DiffuseMaterial>
    105                                         <DiffuseMaterial.Brush>
    106                                             <SolidColorBrush Opacity="0.1"  Color="DarkGray"/>
    107                                         </DiffuseMaterial.Brush>
    108                                     </DiffuseMaterial>
    109                                 </MaterialGroup>
    110                             </GeometryModel3D.Material>
    111                         </GeometryModel3D>
    112 
    113                     </Model3DGroup>
    114                 </ModelVisual3D.Content>
    115                 <ModelVisual3D.Transform>
    116                     <Transform3DGroup>
    117                         <ScaleTransform3D x:Name="scale" ScaleX="1" ScaleY="1" ScaleZ="1"/>
    118                         <TranslateTransform3D OffsetX="-0.5" OffsetY="-0.5" OffsetZ="-0.5" />
    119                         <RotateTransform3D>
    120                             <RotateTransform3D.Rotation>
    121                                 <AxisAngleRotation3D x:Name="rotateX" Axis="0 1 0"/>
    122                             </RotateTransform3D.Rotation>
    123                         </RotateTransform3D>
    124                         <RotateTransform3D>
    125                             <RotateTransform3D.Rotation>
    126                                 <AxisAngleRotation3D x:Name="rotateY" Axis="1 0 0"/>
    127                             </RotateTransform3D.Rotation>
    128                         </RotateTransform3D>
    129                         <TranslateTransform3D OffsetX="0.5" OffsetY="0.5" OffsetZ="0.5" />
    130                         <ScaleTransform3D x:Name="scaleZoom" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="1" ScaleY="1" ScaleZ="1"/>
    131                     </Transform3DGroup>
    132                 </ModelVisual3D.Transform>
    133             </ModelVisual3D>
    134         </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>
    13572    </Grid>
    13673</UserControl>
  • stable/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs

    r14162 r15278  
    1919
    2020using System;
     21using System.Collections.Generic;
    2122using System.Linq;
    2223using System.Windows;
    2324using System.Windows.Controls;
    2425using System.Windows.Input;
     26using System.Windows.Media;
    2527using System.Windows.Media.Media3D;
    2628using HeuristicLab.Problems.BinPacking3D;
     
    2830namespace HeuristicLab.Problems.BinPacking.Views {
    2931  public partial class Container3DView : UserControl {
     32    private static readonly Color[] colors = new[] {
     33      Color.FromRgb(0x40, 0x6A, 0xB7),
     34      Color.FromRgb(0xB1, 0x6D, 0x01),
     35      Color.FromRgb(0x4E, 0x8A, 0x06),
     36      Color.FromRgb(0x75, 0x50, 0x7B),
     37      Color.FromRgb(0x72, 0x9F, 0xCF),
     38      Color.FromRgb(0xA4, 0x00, 0x00),
     39      Color.FromRgb(0xAD, 0x7F, 0xA8),
     40      Color.FromRgb(0x29, 0x50, 0xCF),
     41      Color.FromRgb(0x90, 0xB0, 0x60),
     42      Color.FromRgb(0xF5, 0x89, 0x30),
     43      Color.FromRgb(0x55, 0x57, 0x53),
     44      Color.FromRgb(0xEF, 0x59, 0x59),
     45      Color.FromRgb(0xED, 0xD4, 0x30),
     46      Color.FromRgb(0x63, 0xC2, 0x16),
     47    };
     48
     49    private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA);
     50    private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA);
     51
    3052    private Point startPos;
    3153    private bool mouseDown = false;
     
    4567    }
    4668
     69    private Dictionary<int, DiffuseMaterial> materials;
     70
    4771    public Container3DView() {
    4872      InitializeComponent();
    4973      camMain.Position = new Point3D(0.5, 3, 3); // for design time we use a different camera position
     74      materials = new Dictionary<int, DiffuseMaterial>();
    5075      Clear();
    5176    }
     
    7499      if (packing == null) return; // nothing to display
    75100
    76       // draw all items
    77       // order by Z position to reduce artifacts (because of transparent objects)
    78       // TODO: improve code to reduce artifacts
    79       //  - from triangle definitions and lighting
    80       //  - from rotation and Z-ordering
    81 
    82       foreach (var item in packing.Items.OrderBy(i => packing.Positions[i.Key].Z)) {
    83         var position = packing.Positions[item.Key];
    84 
    85         var w = position.Rotated ? item.Value.Depth : item.Value.Width;
    86         var h = item.Value.Height;
    87         var d = position.Rotated ? item.Value.Width : item.Value.Depth;
    88 
    89         // ignore the item.Material
    90 
    91         // if nothing is selected then draw all cubes opaque
    92         // otherwise draw only the selected cube opaque and all others transparent
    93         if (selectedItemKey < 0 || selectedItemKey == item.Key) {
    94           AddCube(meshMain, position.X, position.Y, position.Z, w, h, d);
    95         } else {
    96           AddCube(meshTransparent, position.X, position.Y, position.Z, w, h, d, addInsideTriangles: true);
     101      var modelGroup = (Model3DGroup)MyModel.Content;
     102      var hiddenMaterial = new DiffuseMaterial(new SolidColorBrush(hiddenColor));
     103
     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;
     143          if (!materials.TryGetValue(item.Value.Material, out material)) {
     144            var colorIdx = item.Value.Material;
     145            while (colorIdx < 0) colorIdx += colors.Length;
     146            colorIdx = colorIdx % colors.Length;
     147            var color = colors[colorIdx];
     148            material = new DiffuseMaterial { Brush = new SolidColorBrush(color) };
     149            materials[item.Value.Material] = material;
     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);
    97154        }
    98155      }
    99156
    100157      var container = packing.BinShape;
    101       // draw a transparent container
    102       AddCube(meshTransparent, container.Origin.X, container.Origin.Y, container.Origin.Z, container.Width, container.Height, container.Depth, addInsideTriangles: true);
    103 
    104       // TODO: support cuboids with different side lengths
    105       // apply scaling so that the container fits into the unit cube (necessary for the transformations)
    106       scale.ScaleX = 1.0 / (container.Width);
    107       scale.ScaleY = 1.0 / (container.Height);
    108       scale.ScaleZ = 1.0 / (container.Depth);
     158      var containerModel = new GeometryModel3D(new MeshGeometry3D(), new DiffuseMaterial(new SolidColorBrush(containerColor)));
     159      modelGroup.Children.Add(containerModel);
     160      AddWireframeCube((MeshGeometry3D)containerModel.Geometry, container.Origin.X - .5, container.Origin.Y - .5, container.Origin.Z - .5, container.Width + 1, container.Height + 1, container.Depth + 1);
     161
     162      var ratio = Math.Max(container.Width, Math.Max(container.Height, container.Depth));
     163      scale.ScaleX = 1.0 / ratio;
     164      scale.ScaleY = 1.0 / ratio;
     165      scale.ScaleZ = 1.0 / ratio;
     166
     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);
    109179    }
    110180
    111181
    112182    private void Clear() {
    113       meshInsides.Positions.Clear();
    114       meshInsides.TriangleIndices.Clear();
    115 
    116       meshMain.Positions.Clear();
    117       meshMain.TriangleIndices.Clear();
    118 
    119       meshTransparent.Positions.Clear();
    120       meshTransparent.TriangleIndices.Clear();
     183      ((Model3DGroup)MyModel.Content).Children.Clear();
     184      materials.Clear();
    121185
    122186      mouseDown = false;
     
    128192      if (!mouseDown) return;
    129193      var pos = e.GetPosition((IInputElement)this);
    130       rotateX.Angle = startAngleX + (pos.X - startPos.X) / 4;
    131       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;
    132197    }
    133198
    134199    private void Container3DView_MouseDown(object sender, MouseButtonEventArgs e) {
    135       startAngleX = rotateX.Angle;
    136       startAngleY = rotateY.Angle;
     200      startAngleX = ((AxisAngleRotation3D)rotateX.Rotation).Angle;
     201      startAngleY = ((AxisAngleRotation3D)rotateY.Rotation).Angle;
    137202      this.startPos = e.GetPosition((IInputElement)this);
    138203      this.mouseDown = true;
     
    155220    }
    156221
     222    private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) {
     223      Focus(); // for mouse wheel events
     224    }
    157225
    158226    #region helper for cubes
    159 
    160     private void AddCube(MeshGeometry3D mesh, int x, int y, int z, int width, int height, int depth, bool addInsideTriangles = false) {
    161       AddOutsideTriangles(mesh, AddPoints(mesh, x, y, z, width, height, depth));
    162       if (addInsideTriangles) AddInsideTriangles(meshInsides, AddPoints(meshInsides, x, y, z, width, height, depth));
    163     }
    164 
    165     private void AddOutsideTriangles(MeshGeometry3D mesh, int[] pointIdx) {
    166       // point indices counter-clockwise
    167       // back side
    168       mesh.TriangleIndices.Add(pointIdx[0]);
    169       mesh.TriangleIndices.Add(pointIdx[2]);
    170       mesh.TriangleIndices.Add(pointIdx[1]);
    171 
    172       mesh.TriangleIndices.Add(pointIdx[0]);
    173       mesh.TriangleIndices.Add(pointIdx[3]);
    174       mesh.TriangleIndices.Add(pointIdx[2]);
    175 
    176       // bottom side
    177       mesh.TriangleIndices.Add(pointIdx[5]);
    178       mesh.TriangleIndices.Add(pointIdx[4]);
    179       mesh.TriangleIndices.Add(pointIdx[0]);
    180 
    181       mesh.TriangleIndices.Add(pointIdx[5]);
    182       mesh.TriangleIndices.Add(pointIdx[0]);
    183       mesh.TriangleIndices.Add(pointIdx[1]);
    184 
    185       // right side
    186       mesh.TriangleIndices.Add(pointIdx[2]);
    187       mesh.TriangleIndices.Add(pointIdx[6]);
    188       mesh.TriangleIndices.Add(pointIdx[5]);
    189 
    190       mesh.TriangleIndices.Add(pointIdx[1]);
    191       mesh.TriangleIndices.Add(pointIdx[2]);
    192       mesh.TriangleIndices.Add(pointIdx[5]);
    193 
    194       // left side
    195       mesh.TriangleIndices.Add(pointIdx[7]);
    196       mesh.TriangleIndices.Add(pointIdx[3]);
    197       mesh.TriangleIndices.Add(pointIdx[4]);
    198 
    199       mesh.TriangleIndices.Add(pointIdx[4]);
    200       mesh.TriangleIndices.Add(pointIdx[3]);
    201       mesh.TriangleIndices.Add(pointIdx[0]);
    202 
    203       // top side
    204       mesh.TriangleIndices.Add(pointIdx[3]);
    205       mesh.TriangleIndices.Add(pointIdx[7]);
    206       mesh.TriangleIndices.Add(pointIdx[6]);
    207 
    208       mesh.TriangleIndices.Add(pointIdx[3]);
    209       mesh.TriangleIndices.Add(pointIdx[6]);
    210       mesh.TriangleIndices.Add(pointIdx[2]);
    211 
    212       // front side
    213       mesh.TriangleIndices.Add(pointIdx[6]);
    214       mesh.TriangleIndices.Add(pointIdx[7]);
    215       mesh.TriangleIndices.Add(pointIdx[4]);
    216 
    217       mesh.TriangleIndices.Add(pointIdx[6]);
    218       mesh.TriangleIndices.Add(pointIdx[4]);
    219       mesh.TriangleIndices.Add(pointIdx[5]);
    220     }
    221 
    222     private void AddInsideTriangles(MeshGeometry3D mesh, int[] pointIdx) {
    223       // for each cube we also draw the triangles facing inside because they are visible when a cube is transparent
    224       // point indices clockwise
    225 
    226       // back side
    227       mesh.TriangleIndices.Add(pointIdx[1]);
    228       mesh.TriangleIndices.Add(pointIdx[2]);
    229       mesh.TriangleIndices.Add(pointIdx[0]);
    230 
    231       mesh.TriangleIndices.Add(pointIdx[2]);
    232       mesh.TriangleIndices.Add(pointIdx[3]);
    233       mesh.TriangleIndices.Add(pointIdx[0]);
    234 
    235       // bottom side
    236       mesh.TriangleIndices.Add(pointIdx[0]);
    237       mesh.TriangleIndices.Add(pointIdx[4]);
    238       mesh.TriangleIndices.Add(pointIdx[5]);
    239 
    240       mesh.TriangleIndices.Add(pointIdx[1]);
    241       mesh.TriangleIndices.Add(pointIdx[0]);
    242       mesh.TriangleIndices.Add(pointIdx[5]);
    243 
    244       // right side
    245       mesh.TriangleIndices.Add(pointIdx[5]);
    246       mesh.TriangleIndices.Add(pointIdx[6]);
    247       mesh.TriangleIndices.Add(pointIdx[2]);
    248 
    249       mesh.TriangleIndices.Add(pointIdx[5]);
    250       mesh.TriangleIndices.Add(pointIdx[2]);
    251       mesh.TriangleIndices.Add(pointIdx[1]);
    252 
    253       // left side
    254       mesh.TriangleIndices.Add(pointIdx[4]);
    255       mesh.TriangleIndices.Add(pointIdx[3]);
    256       mesh.TriangleIndices.Add(pointIdx[7]);
    257 
    258       mesh.TriangleIndices.Add(pointIdx[0]);
    259       mesh.TriangleIndices.Add(pointIdx[3]);
    260       mesh.TriangleIndices.Add(pointIdx[4]);
    261 
    262       // top side
    263       mesh.TriangleIndices.Add(pointIdx[6]);
    264       mesh.TriangleIndices.Add(pointIdx[7]);
    265       mesh.TriangleIndices.Add(pointIdx[3]);
    266 
    267       mesh.TriangleIndices.Add(pointIdx[2]);
    268       mesh.TriangleIndices.Add(pointIdx[6]);
    269       mesh.TriangleIndices.Add(pointIdx[3]);
    270 
    271       // front side
    272       mesh.TriangleIndices.Add(pointIdx[4]);
    273       mesh.TriangleIndices.Add(pointIdx[7]);
    274       mesh.TriangleIndices.Add(pointIdx[6]);
    275 
    276       mesh.TriangleIndices.Add(pointIdx[5]);
    277       mesh.TriangleIndices.Add(pointIdx[4]);
    278       mesh.TriangleIndices.Add(pointIdx[6]);
    279     }
    280 
    281     private int[] AddPoints(MeshGeometry3D mesh, int x, int y, int z, int w, int h, int d) {
     227    /// <summary>
     228    /// Creates a solid cube by adding the respective points and triangles.
     229    /// </summary>
     230    /// <param name="mesh">The mesh to which points and triangles are added.</param>
     231    /// <param name="x">The leftmost point</param>
     232    /// <param name="y">The frontmost point</param>
     233    /// <param name="z">The lowest point</param>
     234    /// <param name="width">The extension to the right</param>
     235    /// <param name="height">The extension to the back</param>
     236    /// <param name="depth">The extension to the top</param>
     237    private void AddSolidCube(MeshGeometry3D mesh, int x, int y, int z, int width, int height, int depth) {
    282238      // ground
    283239      mesh.Positions.Add(new Point3D(x, y, z));
    284       mesh.Positions.Add(new Point3D(x + w, y, z));
    285       mesh.Positions.Add(new Point3D(x + w, y + h, z));
    286       mesh.Positions.Add(new Point3D(x, y + h, z));
     240      mesh.Positions.Add(new Point3D(x + width, y, z));
     241      mesh.Positions.Add(new Point3D(x + width, y + height, z));
     242      mesh.Positions.Add(new Point3D(x, y + height, z));
    287243      // top
    288       mesh.Positions.Add(new Point3D(x, y, z + d));
    289       mesh.Positions.Add(new Point3D(x + w, y, z + d));
    290       mesh.Positions.Add(new Point3D(x + w, y + h, z + d));
    291       mesh.Positions.Add(new Point3D(x, y + h, z + d));
    292 
    293       return Enumerable.Range(mesh.Positions.Count - 8, 8).ToArray();
     244      mesh.Positions.Add(new Point3D(x, y, z + depth));
     245      mesh.Positions.Add(new Point3D(x + width, y, z + depth));
     246      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth));
     247      mesh.Positions.Add(new Point3D(x, y + height, z + depth));
     248
     249      // front
     250      AddPlane(mesh, 0, 1, 5, 4);
     251      // right side
     252      AddPlane(mesh, 1, 2, 6, 5);
     253      // back
     254      AddPlane(mesh, 3, 7, 6, 2);
     255      // left side
     256      AddPlane(mesh, 0, 4, 7, 3);
     257      // top
     258      AddPlane(mesh, 4, 5, 6, 7);
     259      // bottom
     260      AddPlane(mesh, 0, 3, 2, 1);
     261    }
     262
     263    /// <summary>
     264    /// Creates a wireframe cube by adding the respective points and triangles.
     265    /// </summary>
     266    /// <param name="mesh">The mesh to which points and triangles are added.</param>
     267    /// <param name="x">The leftmost point</param>
     268    /// <param name="y">The frontmost point</param>
     269    /// <param name="z">The lowest point</param>
     270    /// <param name="width">The extension to the right</param>
     271    /// <param name="height">The extension to the back</param>
     272    /// <param name="depth">The extension to the top</param>
     273    /// <param name="thickness">The thickness of the frame</param>
     274    private void AddWireframeCube(MeshGeometry3D mesh, double x, double y, double z, double width, double height, double depth, double thickness = double.NaN) {
     275      // default thickness of the wireframe is 5% of smallest dimension
     276      if (double.IsNaN(thickness))
     277        thickness = Math.Min(width, Math.Min(height, depth)) * 0.05;
     278
     279      // The cube contains of 8 corner, each corner has 4 points:
     280      // 1. The corner point
     281      // 2. A point on the edge to the right of the corner
     282      // 3. A point on the edge atop or below the corner
     283      // 4. A point on the edge to the left of the corner
     284
     285      // Point 0, Front Left Bottom
     286      mesh.Positions.Add(new Point3D(x, y, z));
     287      mesh.Positions.Add(new Point3D(x + thickness, y, z));
     288      mesh.Positions.Add(new Point3D(x, y, z + thickness));
     289      mesh.Positions.Add(new Point3D(x, y + thickness, z));
     290
     291      // Point 1, Front Right Bottom
     292      mesh.Positions.Add(new Point3D(x + width, y, z));
     293      mesh.Positions.Add(new Point3D(x + width, y + thickness, z));
     294      mesh.Positions.Add(new Point3D(x + width, y, z + thickness));
     295      mesh.Positions.Add(new Point3D(x + width - thickness, y, z));
     296
     297      // Point 2, Back Right Bottom
     298      mesh.Positions.Add(new Point3D(x + width, y + height, z));
     299      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z));
     300      mesh.Positions.Add(new Point3D(x + width, y + height, z + thickness));
     301      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z));
     302
     303      // Point 3, Back Left Bottom
     304      mesh.Positions.Add(new Point3D(x, y + height, z));
     305      mesh.Positions.Add(new Point3D(x, y + height - thickness, z));
     306      mesh.Positions.Add(new Point3D(x, y + height, z + thickness));
     307      mesh.Positions.Add(new Point3D(x + thickness, y + height, z));
     308
     309      // Point 4, Front Left Top
     310      mesh.Positions.Add(new Point3D(x, y, z + depth));
     311      mesh.Positions.Add(new Point3D(x + thickness, y, z + depth));
     312      mesh.Positions.Add(new Point3D(x, y, z + depth - thickness));
     313      mesh.Positions.Add(new Point3D(x, y + thickness, z + depth));
     314
     315      // Point 5, Front Right Top
     316      mesh.Positions.Add(new Point3D(x + width, y, z + depth));
     317      mesh.Positions.Add(new Point3D(x + width, y + thickness, z + depth));
     318      mesh.Positions.Add(new Point3D(x + width, y, z + depth - thickness));
     319      mesh.Positions.Add(new Point3D(x + width - thickness, y, z + depth));
     320
     321      // Point 6, Back Right Top
     322      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth));
     323      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + depth));
     324      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth - thickness));
     325      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + depth));
     326
     327      // Point 7, Back Left Top
     328      mesh.Positions.Add(new Point3D(x, y + height, z + depth));
     329      mesh.Positions.Add(new Point3D(x, y + height - thickness, z + depth));
     330      mesh.Positions.Add(new Point3D(x, y + height, z + depth - thickness));
     331      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth));
     332
     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);
     445    }
     446
     447    /// <summary>
     448    /// Adds a plane by two triangles. The indices of the points have to be given
     449    /// in counter-clockwise sequence.
     450    /// </summary>
     451    /// <param name="mesh">The mesh to add the triangles to</param>
     452    /// <param name="a">The index of the first point</param>
     453    /// <param name="b">The index of the second point</param>
     454    /// <param name="c">The index of the third point</param>
     455    /// <param name="d">The index of the fourth point</param>
     456    private void AddPlane(MeshGeometry3D mesh, int a, int b, int c, int d) {
     457      // two triangles form a plane
     458      mesh.TriangleIndices.Add(a);
     459      mesh.TriangleIndices.Add(b);
     460      mesh.TriangleIndices.Add(d);
     461      mesh.TriangleIndices.Add(c);
     462      mesh.TriangleIndices.Add(d);
     463      mesh.TriangleIndices.Add(b);
    294464    }
    295465    #endregion
    296466
    297     private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) {
    298       Focus(); // for mouse wheel events
    299     }
    300467  }
    301468}
  • stable/HeuristicLab.Problems.BinPacking.Views/3.3/HeuristicLab.Problems.BinPacking.Views-3.3.csproj

    r14180 r15278  
    7575    <Reference Include="System" />
    7676    <Reference Include="System.Core" />
     77    <Reference Include="System.Data" />
    7778    <Reference Include="System.Drawing" />
    7879    <Reference Include="System.Windows.Forms" />
    7980    <Reference Include="System.Xaml" />
     81    <Reference Include="System.Xml" />
    8082    <Reference Include="UIAutomationProvider" />
    8183    <Reference Include="WindowsBase" />
  • stable/HeuristicLab.Problems.BinPacking/3.3/2D/BinPacking2D.cs

    r14966 r15278  
    3434    public BinPacking2D(PackingShape binShape)
    3535      : base(binShape) {
    36       ExtremePoints = new SortedSet<PackingPosition>();
    3736      ExtremePoints.Add(binShape.Origin);
    3837      InitializeOccupationLayers();
     
    4140    [StorableConstructor]
    4241    protected BinPacking2D(bool deserializing) : base(deserializing) { }
    43     protected BinPacking2D(BinPacking2D original, Cloner cloner)
    44       : base(original, cloner) {
    45       this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)));
    46     }
     42    protected BinPacking2D(BinPacking2D original, Cloner cloner) : base(original, cloner) { }
    4743    public override IDeepCloneable Clone(Cloner cloner) {
    4844      return new BinPacking2D(this, cloner);
     
    8884      };
    8985
    90       int epIndex = 0;
    91       while (epIndex < ExtremePoints.Count && (!IsPositionFeasible(rotatedItem, ExtremePoints.ElementAt(epIndex)))) { epIndex++; }
    92 
    93       if (epIndex < ExtremePoints.Count) {
    94         var currentPoint = ExtremePoints.ElementAt(epIndex);
    95 
    96         var result = new PackingPosition(currentPoint.AssignedBin, currentPoint.X, currentPoint.Y, rotated);
     86      var ep = ExtremePoints.Where(x => IsPositionFeasible(rotatedItem, x, stackingConstraints)).FirstOrDefault();
     87      if (ep != null) {
     88        var result = new PackingPosition(ep.AssignedBin, ep.X, ep.Y, rotated);
    9789        return result;
    9890      }
    9991      return null;
    10092    }
    101     public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) {
     93    public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated, bool stackingConstraints) {
    10294      PackingPosition currentPosition = new PackingPosition(0,
    10395        BinShape.Width - (rotated ? item.Height : item.Width),
    10496        BinShape.Height - (rotated ? item.Width : item.Height), rotated);
    10597      //Slide the item as far as possible to the left
    106       while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
    107         || IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition))) {
     98      while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints)
     99        || IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints)) {
    108100        //Slide the item as far as possible to the bottom
    109         while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition))) {
     101        while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints)) {
    110102          currentPosition = PackingPosition.MoveDown(currentPosition);
    111103        }
    112         if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)))
     104        if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints))
    113105          currentPosition = PackingPosition.MoveLeft(currentPosition);
    114106      }
    115107
    116       return IsPositionFeasible(item, currentPosition) ? currentPosition : null;
    117     }
    118 
    119     public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items) {
     108      return IsPositionFeasible(item, currentPosition, stackingConstraints) ? currentPosition : null;
     109    }
     110
     111    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints) {
    120112      var temp = new List<int>(sequence);
    121113      for (int i = 0; i < temp.Count; i++) {
    122114        var item = items[temp[i]];
    123         var position = FindPositionBySliding(item, false);
     115        var position = FindPositionBySliding(item, false, stackingConstraints);
    124116        if (position != null) {
    125117          PackItem(temp[i], item, position);
     
    128120      }
    129121    }
    130     public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray) {
     122    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray, bool stackingConstraints) {
    131123      var temp = new List<int>(sequence);
    132124      for (int i = 0; i < temp.Count; i++) {
    133125        var item = items[temp[i]];
    134         var position = FindPositionBySliding(item, rotationArray[temp[i]]);
     126        var position = FindPositionBySliding(item, rotationArray[temp[i]], stackingConstraints);
    135127        if (position != null) {
    136128          PackItem(temp[i], item, position);
     
    150142      }
    151143    }
     144   
    152145    public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray) {
    153146      var temp = new List<int>(sequence);
     
    186179      throw new NotSupportedException();
    187180    }
    188 
    189181    protected override void InitializeOccupationLayers() {
    190182      for (int i = 0; i * 10 <= BinShape.Width; i += 1) {
  • stable/HeuristicLab.Problems.BinPacking/3.3/2D/IntegerVectorEncoding/BottomLeftIntegerVectorDecoder.cs

    r14170 r15278  
    4747
    4848    protected override PackingPosition FindPositionForItem(BinPacking2D bp, PackingItem item) {
    49       return bp.FindPositionBySliding(item, rotated: false);
     49      return bp.FindPositionBySliding(item, rotated: false, stackingConstraints: false);
    5050    }
    5151
     
    5454      ref IList<int> remainingIDs, IList<PackingItem> items) {
    5555      var bp = new BinPacking2D(partialSolution.BinShape);
    56       bp.SlidingBasedPacking(ref remainingIDs, items);
     56      bp.SlidingBasedPacking(ref remainingIDs, items, stackingConstraints: false);
    5757      return bp;
    5858    }
  • stable/HeuristicLab.Problems.BinPacking/3.3/2D/PermutationEncoding/BottomLeftPermutationDecoder.cs

    r14170 r15278  
    4646      while (remainingIDs.Count > 0) {
    4747        var bp = new BinPacking2D(binShape);
    48         bp.SlidingBasedPacking(ref remainingIDs, items);
     48        bp.SlidingBasedPacking(ref remainingIDs, items, stackingConstraints: false);
    4949        result.Bins.Add(bp);
    5050      }
  • stable/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs

    r14966 r15278  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3233  public class BinPacking3D : BinPacking<PackingPosition, PackingShape, PackingItem> {
    3334
     35    [Storable]
     36    public Dictionary<PackingPosition, Tuple<int, int, int>> ResidualSpace { get; protected set; }
     37
    3438    public BinPacking3D(PackingShape binShape)
    3539      : base(binShape) {
    36       ExtremePoints = new SortedSet<PackingPosition>();
    37       ExtremePoints.Add(binShape.Origin);
     40      ResidualSpace = new Dictionary<PackingPosition, Tuple<int,int,int>>();
     41      AddExtremePoint(binShape.Origin);
    3842      InitializeOccupationLayers();
    3943    }
     
    4246    protected BinPacking3D(BinPacking3D original, Cloner cloner)
    4347      : base(original, cloner) {
    44       this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)));
     48      this.ResidualSpace = new Dictionary<PackingPosition, Tuple<int, int, int>>();
     49      foreach (var o in original.ResidualSpace)
     50        this.ResidualSpace.Add(cloner.Clone(o.Key), Tuple.Create(o.Value.Item1, o.Value.Item2, o.Value.Item3));
    4551    }
    4652    public override IDeepCloneable Clone(Cloner cloner) {
    4753      return new BinPacking3D(this, cloner);
     54    }
     55
     56
     57    [StorableHook(HookType.AfterDeserialization)]
     58    private void AfterDeserialization() {
     59      // BackwardsCompatibility3.3
     60      #region Backwards compatible code, remove with 3.4
     61      if (ResidualSpace == null)
     62        ResidualSpace = new Dictionary<PackingPosition, Tuple<int, int, int>>();
     63      #endregion
     64    }
     65
     66    public override void PackItem(int itemID, PackingItem item, PackingPosition position) {
     67      ResidualSpace.Remove(position);
     68      base.PackItem(itemID, item, position);
    4869    }
    4970
     
    6081          current = PackingPosition.MoveDown(current);
    6182        }
    62         ExtremePoints.Add((PackingPosition)current.Clone());
     83        AddExtremePoint((PackingPosition)current.Clone());
    6384        while (current.X > 0 && !IsPointOccupied(PackingPosition.MoveLeft(current))) {
    6485          current = PackingPosition.MoveLeft(current);
    6586        }
    66         ExtremePoints.Add(current);
     87        AddExtremePoint(current);
    6788
    6889        //Traversing down the z-axis
     
    7192          current = PackingPosition.MoveBack(current);
    7293        }
    73         ExtremePoints.Add((PackingPosition)current.Clone());
    74         while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
    75           current = PackingPosition.MoveDown(current);
    76         }
    77         ExtremePoints.Add(current);
     94        AddExtremePoint((PackingPosition)current.Clone());
     95        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     96          current = PackingPosition.MoveDown(current);
     97        }
     98        AddExtremePoint(current);
    7899      }
    79100
     
    86107          current = PackingPosition.MoveLeft(current);
    87108        }
    88         ExtremePoints.Add((PackingPosition)current.Clone());
    89         while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
    90           current = PackingPosition.MoveDown(current);
    91         }
    92         ExtremePoints.Add(current);
     109        AddExtremePoint((PackingPosition)current.Clone());
     110        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     111          current = PackingPosition.MoveDown(current);
     112        }
     113        AddExtremePoint(current);
    93114
    94115        //Traversing down the z-axis
     
    97118          current = PackingPosition.MoveBack(current);
    98119        }
    99         ExtremePoints.Add((PackingPosition)current.Clone());
    100         while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
    101           current = PackingPosition.MoveDown(current);
    102         }
    103         ExtremePoints.Add(current);
     120        AddExtremePoint((PackingPosition)current.Clone());
     121        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     122          current = PackingPosition.MoveDown(current);
     123        }
     124        AddExtremePoint(current);
    104125      }
    105126
     
    112133          current = PackingPosition.MoveLeft(current);
    113134        }
    114         ExtremePoints.Add((PackingPosition)current.Clone());
    115         while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
    116           current = PackingPosition.MoveDown(current);
    117         }
    118         ExtremePoints.Add(current);
     135        AddExtremePoint((PackingPosition)current.Clone());
     136        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     137          current = PackingPosition.MoveDown(current);
     138        }
     139        AddExtremePoint(current);
    119140
    120141        //Traversing down the y-axis
     
    123144          current = PackingPosition.MoveDown(current);
    124145        }
    125         ExtremePoints.Add((PackingPosition)current.Clone());
     146        AddExtremePoint((PackingPosition)current.Clone());
    126147        while (current.X > 0 && !IsPointOccupied(PackingPosition.MoveLeft(current))) {
    127148          current = PackingPosition.MoveLeft(current);
    128149        }
    129         ExtremePoints.Add(current);
     150        AddExtremePoint(current);
     151      }
     152    }
     153
     154    private void AddExtremePoint(PackingPosition current) {
     155      if (ExtremePoints.Add(current)) {
     156        var tuple = Tuple.Create(BinShape.Width - current.X, BinShape.Height - current.Y, BinShape.Depth - current.Z);
     157        ResidualSpace.Add(current, tuple);
    130158      }
    131159    }
    132160
    133161    public override PackingPosition FindExtremePointForItem(PackingItem item, bool rotated, bool stackingConstraints) {
    134 
    135162      PackingItem newItem = new PackingItem(
    136163        rotated ? item.Depth : item.Width,
     
    139166        item.TargetBin, item.Weight, item.Material);
    140167
    141       int epIndex = 0;
    142       while (epIndex < ExtremePoints.Count && (
    143         !IsPositionFeasible(newItem, ExtremePoints.ElementAt(epIndex))
    144         || !IsSupportedByAtLeastOnePoint(newItem, ExtremePoints.ElementAt(epIndex))
    145         || (stackingConstraints && !IsStaticStable(newItem, ExtremePoints.ElementAt(epIndex)))
    146         || (stackingConstraints && !IsWeightSupported(newItem, ExtremePoints.ElementAt(epIndex)))
    147       )) { epIndex++; }
    148 
    149       if (epIndex < ExtremePoints.Count) {
    150         var origPoint = ExtremePoints.ElementAt(epIndex);
    151         var result = new PackingPosition(origPoint.AssignedBin, origPoint.X, origPoint.Y, origPoint.Z, rotated);
     168      var ep = ExtremePoints.Where(x => IsPositionFeasible(newItem, x, stackingConstraints)).FirstOrDefault();
     169      if (ep != null) {
     170        var result = new PackingPosition(ep.AssignedBin, ep.X, ep.Y, ep.Z, rotated);
    152171        return result;
    153172      }
     
    155174    }
    156175
    157     public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) {
    158       //TODO: does not support stacking constraints yet
     176    public override bool IsPositionFeasible(PackingItem item, PackingPosition position, bool stackingConstraints) {
     177      var feasible = base.IsPositionFeasible(item, position, stackingConstraints);
     178      return feasible
     179        && IsSupportedByAtLeastOnePoint(item, position)
     180        && (!stackingConstraints || (IsStaticStable(item, position) && IsWeightSupported(item, position)));
     181    }
     182
     183    public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated, bool stackingConstraints) {
    159184      //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height)
    160185      PackingPosition currentPosition = new PackingPosition(0,
     
    163188        BinShape.Depth - (rotated ? item.Width : item.Depth), rotated);
    164189      //Slide the item as far as possible to the bottom
    165       while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition))
    166         || IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
    167         || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
     190      while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints)
     191        || IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints)
     192        || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition), stackingConstraints)) {
    168193        //Slide the item as far as possible to the left
    169         while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
    170       || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
     194        while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints)
     195      || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition), stackingConstraints)) {
    171196          //Slide the item as far as possible to the back
    172           while (IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
     197          while (IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition), stackingConstraints)) {
    173198            currentPosition = PackingPosition.MoveBack(currentPosition);
    174199          }
    175           if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)))
     200          if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints))
    176201            currentPosition = PackingPosition.MoveLeft(currentPosition);
    177202        }
    178         if (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition)))
     203        if (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints))
    179204          currentPosition = PackingPosition.MoveDown(currentPosition);
    180205      }
    181206
    182       return IsPositionFeasible(item, currentPosition) ? currentPosition : null;
    183     }
    184 
    185     public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items) {
     207      return IsPositionFeasible(item, currentPosition, stackingConstraints) ? currentPosition : null;
     208    }
     209
     210    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints) {
    186211      var temp = new List<int>(sequence);
    187212      for (int i = 0; i < temp.Count; i++) {
    188213        var item = items[temp[i]];
    189         var position = FindPositionBySliding(item, false);
     214        var position = FindPositionBySliding(item, false, stackingConstraints);
    190215        if (position != null) {
    191216          PackItem(temp[i], item, position);
     
    194219      }
    195220    }
    196     public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray) {
     221    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray, bool stackingConstraints) {
    197222      var temp = new List<int>(sequence);
    198223      for (int i = 0; i < temp.Count; i++) {
    199224        var item = items[temp[i]];
    200         var position = FindPositionBySliding(item, rotationArray[i]);
     225        var position = FindPositionBySliding(item, rotationArray[i], stackingConstraints);
    201226        if (position != null) {
    202227          PackItem(temp[i], item, position);
     
    212237        if (positionFound != null) {
    213238          PackItem(itemID, item, positionFound);
     239          if (Items.Count > 1)
     240            UpdateResidualSpace(item, positionFound);
    214241          sequence.Remove(itemID);
    215242        }
     
    227254      }
    228255    }
    229 
    230256    public override int ShortestPossibleSideFromPoint(PackingPosition position) {
    231257
     
    297323    }
    298324
    299 
    300325    protected override void InitializeOccupationLayers() {
    301326      for (int i = 0; i * 10 <= BinShape.Depth; i += 1) {
     
    320345      for (int i = z1; i <= z2; i++)
    321346        result.AddRange(OccupationLayers[i]);
    322 
    323347      return result;
    324348    }
     349   
     350    public void UpdateResidualSpace(PackingItem item, PackingPosition pos) {
     351      foreach (var ep in ExtremePoints) {
     352        if (ep.Z >= pos.Z && ep.Z <= pos.Z + item.Depth) {
     353          if (ep.X <= pos.X && ep.Y > pos.Y && ep.Y < pos.Y + item.Height) {
     354            var diff = pos.X - ep.X;
     355            var newRSX = ResidualSpace[ep].Item1 < diff ? ResidualSpace[ep].Item1 : diff;
     356            ResidualSpace[ep] = Tuple.Create(newRSX, ResidualSpace[ep].Item2, ResidualSpace[ep].Item3);
     357          }
     358          if (ep.Y <= pos.Y && ep.X > pos.X && ep.X < pos.X + item.Width) {
     359            var diff = pos.Y - ep.Y;
     360            var newRSY = ResidualSpace[ep].Item2 < diff ? ResidualSpace[ep].Item2 : diff;
     361            ResidualSpace[ep] = Tuple.Create(ResidualSpace[ep].Item1, newRSY, ResidualSpace[ep].Item3);
     362          }
     363        }
     364        if (ep.Z <= pos.Z &&
     365          ep.Y > pos.Y && ep.Y < pos.Y + item.Height &&
     366          ep.X > pos.X && ep.X < pos.X + item.Width) {
     367            var diff = pos.Z - ep.Z;
     368            var newRSZ = ResidualSpace[ep].Item3 < diff ? ResidualSpace[ep].Item3 : diff;
     369            ResidualSpace[ep] = Tuple.Create(ResidualSpace[ep].Item1, ResidualSpace[ep].Item2, newRSZ);
     370        }
     371      }
     372      return;
     373    }
    325374  }
    326 
    327375}
  • stable/HeuristicLab.Problems.BinPacking/3.3/3D/IntegerVectorEncoding/BottomLeftIntegerVectorDecoder.cs

    r14170 r15278  
    5454
    5555    protected override PackingPosition FindPositionForItem(BinPacking3D bp, PackingItem item, bool useStackingConstraints) {
    56       return bp.FindPositionBySliding(item, rotated: false);
     56      return bp.FindPositionBySliding(item, rotated: false, stackingConstraints: useStackingConstraints);
    5757    }
    5858
     
    6161      ref IList<int> remainingIDs, IList<PackingItem> items, bool useStackingConstraints) {
    6262      var bp = new BinPacking3D(partialSolution.BinShape);
    63       bp.SlidingBasedPacking(ref remainingIDs, items);
     63      bp.SlidingBasedPacking(ref remainingIDs, items, useStackingConstraints);
    6464      return bp;
    6565    }
  • stable/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/BottomLeftPermutationDecoder.cs

    r14170 r15278  
    4646      while (remainingIDs.Count > 0) {
    4747        var bp = new BinPacking3D(binShape);
    48         bp.SlidingBasedPacking(ref remainingIDs, items);
     48        bp.SlidingBasedPacking(ref remainingIDs, items, useStackingConstraints);
    4949        result.Bins.Add(bp);
    5050      }
  • stable/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/ExtremePointPermutationDecoder.cs

    r14170 r15278  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2526using System.Collections.Generic;
    2627using HeuristicLab.Encodings.PermutationEncoding;
     28using System.Linq;
     29
    2730
    2831namespace HeuristicLab.Problems.BinPacking3D {
    2932  [Item("Extreme-point Permutation Decoder (3d)", "Decodes the permutation and creates a packing solution candidate")]
    3033  [StorableClass]
    31   public class ExtremePointPermutationDecoder : Item, IDecoder<Permutation> {
     34  public class ExtremePointPermutationDecoder : ExtremePointPermutationDecoderBase {
    3235
    3336    [StorableConstructor]
     
    4144    }
    4245
    43     public Solution Decode(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
     46    public override Solution Decode(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
     47      return Apply(permutation, binShape, items, useStackingConstraints);
     48    }
     49
     50    public static Solution Apply(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
    4451      Solution result = new Solution(binShape, useExtremePoints: true, stackingConstraints: useStackingConstraints);
    4552      IList<int> remainingIDs = new List<int>(permutation);
  • stable/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/ExtremePointPermutationDecoderBase.cs

    r15230 r15278  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • stable/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/FreeVolumeBestFitExtremePointPermutationDecoder.cs

    r15230 r15278  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • stable/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/ResidualSpaceBestFitExtremePointPermutationDecoder.cs

    r15230 r15278  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • stable/HeuristicLab.Problems.BinPacking/3.3/3D/ProblemBase.cs

    r14162 r15278  
    175175    public override bool Maximization { get { return true; } }
    176176
    177 
    178177    public override double Evaluate(Individual individual, IRandom random) {
    179178      var encodedSolutionCand = (TSol)individual[EncodedSolutionName];
  • stable/HeuristicLab.Problems.BinPacking/3.3/BinPacking.cs

    r14162 r15278  
    5050    [Storable]
    5151    protected Dictionary<int, List<int>> OccupationLayers { get; set; }
     52   
     53    #endregion Properties
    5254
    53     #endregion Properties
     55    public int FreeVolume {
     56      get { return BinShape.Volume - Items.Sum(x => x.Value.Volume); }
     57    }
    5458
    5559    protected BinPacking(TBin binShape)
     
    5862      Items = new ObservableDictionary<int, TItem>();
    5963      BinShape = (TBin)binShape.Clone();
     64      ExtremePoints = new SortedSet<TPos>();
    6065      OccupationLayers = new Dictionary<int, List<int>>();
    6166    }
    62 
    6367
    6468    [StorableConstructor]
     
    7579      }
    7680      this.BinShape = (TBin)original.BinShape.Clone(cloner);
     81      this.ExtremePoints = new SortedSet<TPos>(original.ExtremePoints.Select(p => cloner.Clone(p)));
    7782      this.OccupationLayers = new Dictionary<int, List<int>>();
    7883      foreach (var kvp in original.OccupationLayers) {
     
    8489
    8590    public abstract TPos FindExtremePointForItem(TItem item, bool rotated, bool stackingConstraints);
    86     public abstract TPos FindPositionBySliding(TItem item, bool rotated);
     91    public abstract TPos FindPositionBySliding(TItem item, bool rotated, bool stackingConstraints);
    8792
    88     public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<TItem> items);
    89     public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<TItem> items, Dictionary<int, bool> rotationArray);
     93    public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<TItem> items, bool stackingConstraints);
     94    public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<TItem> items, Dictionary<int, bool> rotationArray, bool stackingConstraints);
    9095    public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList<TItem> items, bool stackingConstraints);
    9196    public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList<TItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray);
    9297
    93     public void PackItem(int itemID, TItem item, TPos position) {
     98    public virtual void PackItem(int itemID, TItem item, TPos position) {
    9499      Items[itemID] = item;
    95100      Positions[itemID] = position;
     
    97102      foreach (int id in Items.Select(x => x.Key))
    98103        GenerateNewExtremePointsForNewItem(Items[id], Positions[id]);
    99 
     104     
    100105      AddNewItemToOccupationLayers(itemID, item, position);
     106    }
     107    public virtual bool PackItemIfFeasible(int itemID, TItem item, TPos position, bool stackingConstraints) {
     108      if (IsPositionFeasible(item, position, stackingConstraints)) {
     109        PackItem(itemID, item, position);
     110        return true;
     111      }
     112      return false;
    101113    }
    102114
     
    127139      return false;
    128140    }
    129     public bool IsPositionFeasible(TItem item, TPos position) {
     141    public virtual bool IsPositionFeasible(TItem item, TPos position, bool stackingConstraints) {
    130142      //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the point is supported by something; 3. the item does not collide with another already packed item
    131143      if (!BinShape.Encloses(position, item))
     
    139151      return true;
    140152    }
     153   
    141154    public abstract int ShortestPossibleSideFromPoint(TPos position);
    142155    public abstract bool IsStaticStable(TItem measures, TPos position);
    143 
    144156
    145157    protected abstract void InitializeOccupationLayers();
  • stable/HeuristicLab.Problems.BinPacking/3.3/HeuristicLab.Problems.BinPacking-3.3.csproj

    r15217 r15278  
    106106    <Compile Include="3D\Evaluators\BinUtilizationEvaluator.cs" />
    107107    <Compile Include="3D\Evaluators\PackingRatioEvaluator.cs" />
     108    <Compile Include="Algorithms\3D\ExtremePointAlgorithm.cs" />
     109    <Compile Include="3D\Instances\ThreeDInstanceDescriptor.cs" />
    108110    <Compile Include="3D\Instances\BPPData.cs" />
    109111    <Compile Include="3D\Instances\RandomDataDescriptor.cs" />
     112    <Compile Include="3D\Instances\RealWorldContainerPackingInstanceProvider.cs" />
    110113    <Compile Include="3D\Instances\RandomInstanceProvider.cs" />
     114    <Compile Include="3D\Instances\ThreeDInstanceParser.cs" />
    111115    <Compile Include="3D\IntegerVectorEncoding\BottomLeftIntegerVectorDecoder.cs" />
    112116    <Compile Include="3D\IntegerVectorEncoding\ExtremePointIntegerVectorDecoder.cs" />
     
    121125    <Compile Include="3D\PackingShape.cs" />
    122126    <Compile Include="3D\PermutationEncoding\BottomLeftPermutationDecoder.cs" />
     127    <Compile Include="3D\PermutationEncoding\ResidualSpaceBestFitExtremePointPermutationDecoder.cs" />
     128    <Compile Include="3D\PermutationEncoding\FreeVolumeBestFitExtremePointPermutationDecoder.cs" />
     129    <Compile Include="3D\PermutationEncoding\ExtremePointPermutationDecoderBase.cs" />
    123130    <Compile Include="3D\PermutationEncoding\ExtremePointPermutationDecoder.cs" />
    124131    <Compile Include="3D\PermutationEncoding\PermutationProblem.cs" />
     
    144151  </ItemGroup>
    145152  <ItemGroup>
     153    <EmbeddedResource Include="3D\Instances\ContainerPackingInstances.zip" />
    146154    <None Include="HeuristicLab.snk" />
    147155    <None Include="Properties\AssemblyInfo.cs.frame" />
Note: See TracChangeset for help on using the changeset viewer.