配送に必要な箱のサイズを計算するための最良の方法を見つけようとしています。
サイズの異なる3つの輸送コンテナがあります。製品の幅、長さ、深さ、および質量をデータベースで定義しています。
発送に必要な最小の箱の数と、カート内のアイテムの数を考慮したそれらの箱の最小の寸法を見つける方法を知りたいです。
私の現在の「アイデア」は、製品配列全体の最大幅を見つけ、それに応じてボックスを選択し、必要に応じて注文を分割することです...これはうまくいかないようです。
私のボックスのサイズは次のとおりです。-8x6x 6=228立方インチ-10x8 x 8=640立方インチ-12.5x12.5 x 12.5=1953.125立方インチ
製品は次のように定義されます。
[Product] => Array
(
[STOCK_CODE] => 010003
[Product_Slug] => GABA_010003
[ItemName] => GABA
[WHOLESALE_PRICE] => 17.47
[RETAIL_PRICE] => 24.95
[Brand] =>
[ProductLine] =>
[image_name] => 705077000440
[MASS] => 0.313
[Height] => 4.625
[Width] => 2.375
[Depth] => 2.375
[cubic_inches] => 26.087890625
)
ナップサック問題、パッキング問題などを調べましたが、これを行う方法が見つかりません。どんな助けでも素晴らしいでしょう。
function shipping(){
$this->CartProduct->unbindModel(
array('belongsTo' => array('User'))
);
//find all cart products by current logged in user
$cartItems = $this->CartProduct->find('all', array('conditions' => array('CartProduct.user_id' => $this->Auth->user('id'))));
$i = 0;
//get the max width, height, depth
$maxHeight = 0;
$maxWidth = 0;
$maxDepth = 0;
foreach($cartItems as $c){
$cartItems[$i]['Product']['cubic_inches'] = $c['Product']['Height'] * $c['Product']['Width'] * $c['Product']['Depth'];
$cartItems[$i]['CartProduct']['total_cubic_inches'] = ($c['Product']['Height'] * $c['Product']['Width'] * $c['Product']['Depth']) * $c['CartProduct']['qty'];
if($c['Product']['Height'] > $maxHeight)
{
$maxHeight = $c['Product']['Height'];
}
if($c['Product']['Width'] > $maxWidth)
{
$maxWidth = $c['Product']['Width'];
}
if($c['Product']['Depth'] > $maxDepth)
{
$maxDepth = $c['Product']['Depth'];
}
$i++;
}
//possible containers
//8 x 6 x 6 = 228 ci
//10 x 8 x 8 = 640 ci
//12.5 x 12.5 x 12.5 = 1953.125
$possibleContainers = array(
1 => array(
'Height' => 8,
'Width' => 6,
'Depth' => 6,
'Cubic' => 228),
2 => array(
'Height' => 10,
'Width' => 8,
'Depth' => 8,
'Cubic' => 640),
3 => array(
'Height' => 12.5,
'Width' => 12.5,
'Depth' => 12.5,
'Cubic' => 1953.125)
);
$max = array(
'Height' => $maxHeight,
'Width' => $maxWidth,
'Depth' => $maxDepth,
);
pr($cartItems);
pr($possibleContainers);
die();
}