imankalis Posted May 31, 2004 Share Posted May 31, 2004 Algorithm: Hello!!! I'm a newbie in PHP and MySQL...and I need some help to realise this algo to script. The problem is: My packages are limited by the weight but also by the dimensions (Length+width+height) depending on a specified zone. In the "Outre-Mer TOM": - the maximum weight is 10kg - the maximum dimension (Length+width+height) is 100cm. For the "International": - the maximum weight is 30kg - the maximum dimension (Length+2 x width+2 x height) must be < 300 cm with Length < 150 cm. For the "National" (France): - the maximum weight is 30kg - the maximum dimension (Length+width+height) must be < 200cm. - if 150cm <= (Length+width+height) <= 200cm there is a tax worthing 3.80 euros. IMPORTANT: In my algo: the Length is the greater side of the product. the width is the second greater side of the product. and the height is the smallest side of the product. -> the aim is to optimize the tidying up of the products in a package with its specific restrictions (weight and dimension). the client orders in this order: - the product A in first, - then the product B, - product C - product D in last This is the initial tab for example: Product____A________B________C________D Length____58cm____41cm_____57cm_____47cm Width_____46cm____29cm_____25cm_____36cm height_____39cm____22cm_____15cm_____21cm weight_____10kg_____8kg______6kg______7kg It will be necessary to classify these products in a table depending on their length in the ascending order to put the maximum of products in a package to decrease the shipping cost. Product_________B_________D_________C_________A Length (cm)_____41___41___47___47___57___37___58___58 Width (cm)______29___29___36___36___25___36___46___46 height (cm)______22___22___21___43___15___58___39___97 Dimension (cm)________92________126_______151_______201 Weight (kg)______8____8____7____15___6____21___10___31 Explanation: to begin: initialisation of the total_length, total_width, total_height to zero. for (i=1, i = n, i++) { // in this case n = 4 (it's the number of the products to order) if (length_of_current_product > total_length) then total_length = length_of_current_product; if (width_of_current_product > total_width) then total_width = width_of_current_product; total_height= total_height + heigth_of_current_product; In this example: // for the first product for (i=1, i=4, i++) 41>0 then total_length = 41; 29>0 then total_width=29 total_height = 0+22 // for the second product for(i=2, 1=7, i++) 47>41 then total_length = 47; 36>29 then total_width=36; total_height = 22+ 21 OK??? But It will be necessary to make this boucle "for" while the dimensions_max (Length+width+height) is <100 and the total_weight is <10 for the "Outre-Mer TOM" zone for example. If it's not the case, it will be necessary to create a new package...recursively // 100 is a constant DIMENSION_MAX defined by the administrator in the module shipping, //10 is a constant WEIGHT_MAX also defined by the administrator in the module shipping. //3.8 is a constant SUPPLEMENT_TAX also defined by the administrator in the module shipping for the "national" order I have already created the fields to put the dimension product in categories.php and the fields to put these CONSTANTS in the module shipping. But I don't know how to order a table in the ascending way, and get back the heigth, width and length put in the fields of categorie.php. It will be necessary to compare if it's more interesting to make for example 2 packages without this SUPPLEMENT_TAX worthing 3.80 or else make only one package but with the SUPPLEMENT_TAX always with the constraint of DIMENSION_MAX For National Order: Zone 1 Shipping Table 0.5:4.00,1:4.80,2:5.60,3:6.20,5:7.40,7:8.20,10:10.00,11:11.80,30:16.50 Exemple 1:Two packages is better With one Package: Product G (10kg) + Product H (0,5 kg) but this product make the (Length+width+height)>150 cm then 3,80 Euro added. ------------------------------ Total_weight = 10,5 kg -> 11.80 Euros (shipping cost) + Supplement_tax = 3,80 Euros ---------------------------------------------------- Total_shipping_cost = 15,6 Eur BUT With two packages: Product G (10 kg) -> shipping cost =10 Euros Product H (0,5kg) -> shipping cost = 4 Euros ------------------------------------------------------------------ Total_shipping_cost = 14 Euros. Exemple 2: One package is better With one Package: Product I (9,4 kg) +Product H (0,5 kg) but this product make the (Length+width+height)>150 cm then 3,80 Euro added. ---------------------------- Total_weight = 9,9 kg -> 10 Euros (shipping cost) + Supplement_tax = 3,80 Euros ---------------------------------------------------- Total_shipping_cost = 13,8 Eur BUT With two packages: Product I (9,4 kg) -> shipping cost =10 Euros Product H (0,5kg) -> shipping cost = 6 Euros ------------------------------------------------------------------ Total_shipping_cost = 16 Euros. Expected result : For a National Order for example: ________ product A| product B| product C| product D| ________|--->ERROR: MAX_WEIGHT_IS_LIMITED TO package 1: ( 15 kg)___________11,80 Euros (shipping cost) - product B - product D package 2: (16 kg)___________16,50 Euros (shipping cost) - product C - product A The aim is to be able to order for 31 kg of products despite the fact that you are limited by the weight (30kg) ! Remark: We can?t do that: Package 1: (21kg)_____________16,50 Euros (shipping cost) - Product B - Product D - Product C Package 2: (10kg)_____________10 Euros (shipping cost) - Product A Because the dimension (Length+width+height) of the first package is 151 cm and we are limited to 150 cm for national order!!! OK? You begin to see the problem? The errors to display: - When the dimension of a product (Length+width+height) is > 100cm for OUTRE MER TOM - When the dimension of a product (Length+width+height) is > 200 cm for National - When the dimenson of a product (Length+2 x width+ 2 x Height) is > 300cm or Length >150cm for International. Thanks a lot! Any remark which will advance the problem is welcome! The winner will win a bottle of White Wine (Bordeaux) of France. Good Luck! A bient?t. Imankalis. Quote Link to comment Share on other sites More sharing options...
imankalis Posted May 31, 2004 Author Share Posted May 31, 2004 Does somebody find the solution? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.