1 | using System;
|
---|
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
3 | using HeuristicLab.Problems.BinPacking3D;
|
---|
4 | using System.Collections.Generic;
|
---|
5 |
|
---|
6 | using HeuristicLab.Problems.BinPacking._3D.Utils.Tests;
|
---|
7 | using System.Threading;
|
---|
8 | using System.Linq;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Problems.BinPacking._3D.Algorithms.Tests {
|
---|
11 | [TestClass]
|
---|
12 | public class ExtremePointAlgorithmTest {
|
---|
13 |
|
---|
14 | private PackingShape _packingShape1;
|
---|
15 | private PackingShape _packingShape2;
|
---|
16 | private PackingShape _packingShape3;
|
---|
17 | private IList<PackingItem> _items;
|
---|
18 | private ExtremePointAlgorithm _extremPointAlgorithm;
|
---|
19 |
|
---|
20 | [TestInitialize]
|
---|
21 | public void Initializes() {
|
---|
22 | _packingShape1 = new PackingShape(19, 19, 19);
|
---|
23 | _packingShape2 = new PackingShape(18, 18, 18);
|
---|
24 | _packingShape3 = new PackingShape(20, 20, 20);
|
---|
25 | _items = new List<PackingItem>();
|
---|
26 |
|
---|
27 | _items.Add(new PackingItem(8, 10, 10, _packingShape1, 1000, 1)); // 0, V = 800, A = 80, h = 10
|
---|
28 | _items.Add(new PackingItem(10, 8, 10, _packingShape1, 1000, 2)); // 1, V = 800, A = 100, h = 8
|
---|
29 | _items.Add(new PackingItem(10, 10, 8, _packingShape1, 1000, 3)); // 2, V = 800, A = 80, h = 10
|
---|
30 | _items.Add(new PackingItem(8, 8, 10, _packingShape1, 1000, 4)); // 3, V = 640, A = 80, h = 8
|
---|
31 | _items.Add(new PackingItem(10, 8, 8, _packingShape1, 1000, 0)); // 4, V = 640, A = 80, h = 8
|
---|
32 | _items.Add(new PackingItem(8, 10, 8, _packingShape1, 1000, 1)); // 5, V = 640, A = 64, h = 10
|
---|
33 | _items.Add(new PackingItem(8, 8, 8, _packingShape1, 1000, 2)); // 6, V = 512, A = 64, h = 8
|
---|
34 |
|
---|
35 | _items.Add(new PackingItem(10, 10, 10, _packingShape1, 1000, 3)); // 7, V = 1000, A = 100, h = 10
|
---|
36 |
|
---|
37 | _items.Add(new PackingItem(9, 10, 10, _packingShape1, 1000, 4)); // 8, V = 900, A = 90, h = 10
|
---|
38 | _items.Add(new PackingItem(10, 9, 10, _packingShape1, 1000, 0)); // 9, V = 900, A = 100, h = 9
|
---|
39 | _items.Add(new PackingItem(10, 10, 9, _packingShape1, 1000, 1)); // 10, V = 900, A = 90, h = 10
|
---|
40 | _items.Add(new PackingItem(9, 9, 10, _packingShape1, 1000, 2)); // 11, V = 810, A = 90, h = 9
|
---|
41 | _items.Add(new PackingItem(10, 9, 9, _packingShape1, 1000, 3)); // 12, V = 810, A = 90, h = 9
|
---|
42 | _items.Add(new PackingItem(9, 10, 9, _packingShape1, 1000, 4)); // 13, V = 810, A = 81, h = 10
|
---|
43 | _items.Add(new PackingItem(9, 9, 9, _packingShape1, 1000, 0)); // 14, V = 729, A = 81, h = 9
|
---|
44 |
|
---|
45 | _extremPointAlgorithm = new ExtremePointAlgorithm();
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | [TestMethod]
|
---|
51 | [TestCategory("Problems.BinPacking.3D")]
|
---|
52 | [TestProperty("Time", "long")]
|
---|
53 | public void TestExtremePointAlgorithm() {
|
---|
54 |
|
---|
55 | IList<BinPacking3D.PackingPosition> positionsBin0 = new List<BinPacking3D.PackingPosition>() {
|
---|
56 | new BinPacking3D.PackingPosition(0, 0,0,0),
|
---|
57 | new BinPacking3D.PackingPosition(0, 8,0,0),
|
---|
58 | new BinPacking3D.PackingPosition(0, 0,0,10),
|
---|
59 | new BinPacking3D.PackingPosition(0, 10,0,10),
|
---|
60 | new BinPacking3D.PackingPosition(0, 8,8,0),
|
---|
61 | new BinPacking3D.PackingPosition(0, 0,10,0),
|
---|
62 | new BinPacking3D.PackingPosition(0, 0,10,8),
|
---|
63 | new BinPacking3D.PackingPosition(0, 8,10,8),
|
---|
64 | };
|
---|
65 |
|
---|
66 | IList<BinPacking3D.PackingPosition> positionsBin1 = new List<BinPacking3D.PackingPosition>() {
|
---|
67 | new BinPacking3D.PackingPosition(1, 0,0,0),
|
---|
68 | new BinPacking3D.PackingPosition(1, 9,0,0),
|
---|
69 | new BinPacking3D.PackingPosition(1, 0,0,10),
|
---|
70 | new BinPacking3D.PackingPosition(1, 10,0,10),
|
---|
71 | new BinPacking3D.PackingPosition(1, 9,9,0),
|
---|
72 | new BinPacking3D.PackingPosition(1, 0,10,0),
|
---|
73 | new BinPacking3D.PackingPosition(1, 0,10,9)
|
---|
74 | };
|
---|
75 |
|
---|
76 | object[] parameters = new object[] { _packingShape3,
|
---|
77 | _items,
|
---|
78 | new SortingMethod[] { SortingMethod.Given },
|
---|
79 | new FittingMethod[] { FittingMethod.FirstFit },
|
---|
80 | new ExtremePointCreationMethod[] { ExtremePointCreationMethod.PointProjection},
|
---|
81 | new CancellationToken() };
|
---|
82 | _extremPointAlgorithm.SortingMethodParameter.Value.Value = SortingMethod.Given;
|
---|
83 | _extremPointAlgorithm.FittingMethodParameter.Value.Value = FittingMethod.FirstFit;
|
---|
84 | _extremPointAlgorithm.ExtremePointCreationMethodParameter.Value.Value = ExtremePointCreationMethod.PointProjection;
|
---|
85 | _extremPointAlgorithm.SortByMaterialParameter.Value.Value = false;
|
---|
86 | var result = TestUtils.InvokeMethod(typeof(ExtremePointAlgorithm), _extremPointAlgorithm, "GetBest", parameters) as Tuple<Solution, double, SortingMethod?, FittingMethod?, ExtremePointCreationMethod?>;
|
---|
87 |
|
---|
88 | int i = 0;
|
---|
89 | foreach (var item in result.Item1.Bins[0].Positions.Values) {
|
---|
90 | Assert.AreEqual(positionsBin0[i].X, item.X);
|
---|
91 | Assert.AreEqual(positionsBin0[i].Y, item.Y);
|
---|
92 | Assert.AreEqual(positionsBin0[i].Z, item.Z);
|
---|
93 | i++;
|
---|
94 | }
|
---|
95 |
|
---|
96 | i = 0;
|
---|
97 | foreach (var item in result.Item1.Bins[1].Positions.Values) {
|
---|
98 | Assert.AreEqual(positionsBin1[i].X, item.X);
|
---|
99 | Assert.AreEqual(positionsBin1[i].Y, item.Y);
|
---|
100 | Assert.AreEqual(positionsBin1[i].Z, item.Z);
|
---|
101 | i++;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|