-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.js
93 lines (82 loc) · 2.31 KB
/
item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* List of all items in the warehouse.
* @type {Item[]}
*/
const items = [];
/**
* List of all bin types available in the warehouse.
* @type {BinType[]}
*/
const binTypes = [];
/**
* List of all shelf types in the warehouse.
* @type {ShelfType[]}
*/
const shelfTypes = [];
/**
* Represents an item in the warehouse.
*/
function Item(sku, binTypeId) {
this.sku = sku;
this.binTypeId = binTypeId;
}
/**
* Represents a type of bin in the warehouse.
*/
function BinType(id, height, width, depth) {
this.id = id;
this.height = height;
this.width = width;
this.depth = depth;
}
/**
* Represents a type of shelf in the warehouse.
*/
function ShelfType(length, width, depth) {
this.length = length;
this.width = width;
this.depth = depth;
}
/**
* Finds a bin type by its ID.
* @param {string} id - The ID of the bin type.
* @returns {BinType} The matching bin type, or undefined if not found.
*/
function findBinTypeById(id) {
return binTypes.find(binType => binType.id === id);
}
/**
* Calculates the optimal shelf configuration based on the provided maximum shelf height.
* @param {number} maxHeight - The maximum height available for the shelf.
* @returns {Item[]} The optimal configuration of items.
*/
function calculateOptimalShelfConfiguration(maxHeight) {
// Sort items based on the height of their bin type in descending order
items.sort((a, b) => {
const aBinType = findBinTypeById(a.binTypeId);
const bBinType = findBinTypeById(b.binTypeId);
return bBinType.height - aBinType.height;
});
// Calculate optimal configuration
let remainingHeight = maxHeight;
const configuration = [];
for (const item of items) {
const binType = findBinTypeById(item.binTypeId);
if (remainingHeight >= binType.height) {
configuration.push(item);
remainingHeight -= binType.height;
} else {
break;
}
}
return configuration;
}
// Instantiate your binTypes, Items, and ShelfTypes here
binTypes.push(new BinType('1', 10, 20, 30));
binTypes.push(new BinType('2', 20, 30, 40));
items.push(new Item('SKU1', '1'));
items.push(new Item('SKU2', '2'));
shelfTypes.push(new ShelfType(200, 300, 400));
// Calculate optimal shelf configuration with maxHeight of 50
const optimalConfiguration = calculateOptimalShelfConfiguration(50);
console.log(optimalConfiguration);