Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15182


Ignore:
Timestamp:
07/10/17 17:41:38 (7 years ago)
Author:
abeham
Message:

#2762: Merged trunk into branch

Location:
branches/BinPackingExtension
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking

  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views

  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml

    r14835 r15182  
    3030             MouseWheel="Container3DView_OnMouseWheel"
    3131             MouseEnter="Container3DView_OnMouseEnter"
    32              KeyDown="Container3DView_OnKeyDown"
    3332             Focusable="true"
    3433             >
    3534    <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                     <Model3DGroup>
    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>
    7372    </Grid>
    7473</UserControl>
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs

    r14835 r15182  
    4646      Color.FromRgb(0x63, 0xC2, 0x16),
    4747    };
    48    
     48
    4949    private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA);
    5050    private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA);
     
    5252    private Point startPos;
    5353    private bool mouseDown = false;
    54     private bool ctrlDown = false;
    5554    private double startAngleX;
    5655    private double startAngleY;
     
    103102      var hiddenMaterial = new DiffuseMaterial(new SolidColorBrush(hiddenColor));
    104103
    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;
    117143          if (!materials.TryGetValue(item.Value.Material, out material)) {
    118144            var colorIdx = item.Value.Material;
     
    123149            materials[item.Value.Material] = material;
    124150          }
     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);
    125154        }
    126         model.Material = material;
    127         modelGroup.Children.Add(model);
    128 
    129         AddSolidCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d);
    130155      }
    131156
     
    140165      scale.ScaleZ = 1.0 / ratio;
    141166
    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);
    145179    }
    146180
     
    149183      ((Model3DGroup)MyModel.Content).Children.Clear();
    150184      materials.Clear();
    151      
     185
    152186      mouseDown = false;
    153187      startAngleX = 0;
     
    158192      if (!mouseDown) return;
    159193      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;
    163197    }
    164198
    165199    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;
    168202      this.startPos = e.GetPosition((IInputElement)this);
    169203      this.mouseDown = true;
     
    189223      Focus(); // for mouse wheel events
    190224    }
    191 
    192     private void Container3DView_OnKeyDown(object sender, KeyEventArgs e) {
    193       ctrlDown = e.Key.HasFlag(Key.LeftCtrl) || e.Key.HasFlag(Key.RightCtrl);
    194     }
    195 
    196225
    197226    #region helper for cubes
     
    302331      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth));
    303332
    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);
    339445    }
    340446
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/BinPacking2D.cs

    r14976 r15182  
    8383        rotated ? item.Height : item.Width,
    8484        rotated ? item.Width : item.Height,
    85         item.TargetBin);
     85        item.TargetBin) {
     86        Material = item.Material,
     87        Weight = item.Weight
     88      };
    8689
    8790      int epIndex = 0;
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/IntegerVectorEncoding/IntegerVectorProblem.cs

    r14162 r15182  
    2424using System.Collections.Generic;
    2525using System.Linq;
     26using HeuristicLab.Analysis;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    2829using HeuristicLab.Encodings.IntegerVectorEncoding;
    2930using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3032using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3133
     
    5254      Encoding = new IntegerVectorEncoding(EncodedSolutionName, Items.Count, min: 0, max: LowerBound + 1); // NOTE: assumes that all items can be packed into LowerBound+1 bins
    5355      AddOperators();
     56      Parameterize();
    5457      RegisterEventHandlers();
    5558    }
     
    6366    }
    6467
     68    protected override void OnEncodingChanged() {
     69      base.OnEncodingChanged();
     70      Parameterize();
     71    }
    6572
    6673    private void AddOperators() {
    67 
    6874      // move operators are not yet supported (TODO)
    6975      Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
    7076      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
    7177      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>()));
    7282
    73       Encoding.ConfigureOperators(Operators.OfType<IOperator>()); // gkronber: not strictly necessary (only when customer ops are added)
     83      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
    7484    }
    7585
    7686    private void RegisterEventHandlers() {
    7787      // 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();
    8490    }
    8591
     
    96102      return result;
    97103    }
     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    }
    98115    #endregion
    99116  }
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/PermutationEncoding/PermutationProblem.cs

    r14162 r15182  
    2323
    2424using System.Linq;
    25 using System.Windows.Forms;
     25using HeuristicLab.Analysis;
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Encodings.PermutationEncoding;
    2929using HeuristicLab.Optimization;
     30using HeuristicLab.Optimization.Operators;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132
     
    5152      Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
    5253      AddOperators();
     54      Parameterize();
    5355      RegisterEventHandlers();
    5456    }
     
    6264    }
    6365
     66    protected override void OnEncodingChanged() {
     67      base.OnEncodingChanged();
     68      Parameterize();
     69    }
    6470
    6571    private void AddOperators() {
     
    7076      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
    7177      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
     78      Operators.Add(new HammingSimilarityCalculator());
     79      Operators.Add(new QualitySimilarityCalculator());
     80      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    7281
    7382      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
     
    8392    private void RegisterEventHandlers() {
    8493      // 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      }
    86103    }
    87104  }
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/IntegerVectorEncoding/IntegerVectorProblem.cs

    r14167 r15182  
    2424using System.Collections.Generic;
    2525using System.Linq;
     26using HeuristicLab.Analysis;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    2829using HeuristicLab.Encodings.IntegerVectorEncoding;
    2930using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3032using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3133
     
    5153      Encoding = new IntegerVectorEncoding(EncodedSolutionName, Items.Count, min: 0, max: LowerBound + 1); // NOTE: assumes that all items can be packed into LowerBound+1 bins
    5254      AddOperators();
     55      Parameterize();
    5356      RegisterEventHandlers();
    5457    }
     
    6265    }
    6366
     67    protected override void OnEncodingChanged() {
     68      base.OnEncodingChanged();
     69      Parameterize();
     70    }
    6471
    6572    private void AddOperators() {
    66 
    6773      // move operators are not yet supported (TODO)
    6874      Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
    6975      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
    7076      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>()));
    7181
    7282      Encoding.ConfigureOperators(Operators.OfType<IOperator>()); // gkronber: not strictly necessary (only when customer ops are added)
     
    7585    private void RegisterEventHandlers() {
    7686      // 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();
    8389    }
    8490
    8591    #region helpers
    86 
    8792    public static List<List<int>> GenerateSequenceMatrix(IntegerVector intVec) {
    8893      List<List<int>> result = new List<List<int>>();
     
    95100      return result;
    96101    }
     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    }
    97113    #endregion
    98114  }
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/PermutationProblem.cs

    r14167 r15182  
    2323
    2424using System.Linq;
     25using HeuristicLab.Analysis;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Encodings.PermutationEncoding;
    2829using HeuristicLab.Optimization;
     30using HeuristicLab.Optimization.Operators;
    2931using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3032
     
    4951      Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
    5052      AddOperators();
     53      Parameterize();
    5154      RegisterEventHandlers();
    5255    }
     
    6063    }
    6164
     65    protected override void OnEncodingChanged() {
     66      base.OnEncodingChanged();
     67      Parameterize();
     68    }
    6269
    6370    private void AddOperators() {
     
    6875      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
    6976      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
     77      Operators.Add(new HammingSimilarityCalculator());
     78      Operators.Add(new QualitySimilarityCalculator());
     79      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    7080
    7181      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
     
    8292    private void RegisterEventHandlers() {
    8393      // 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      }
    85103    }
    86104  }
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/Plugin.cs.frame

    r14174 r15182  
    2828  [Plugin("HeuristicLab.Problems.BinPacking", "3.3.14.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.BinPacking-3.3.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3031  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3132  [PluginDependency("HeuristicLab.Common", "3.3")]
     
    3637  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3738  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     39  [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")]
    3840  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3941  [PluginDependency("HeuristicLab.Persistence", "3.3")]
Note: See TracChangeset for help on using the changeset viewer.