Algorytm, którego zadaniem jest wybranie odpowiednich pojemników do zapakowania podanych przedmiotów. Należy podać wymiary przedmiotów do zapakowania oraz listę dostępnych pojemników, dzięki czemu algorytm znajdzie rozwiązanie umożliwiające zapakowanie wszystkich przedmiotów do jak najmniejszej ilości pojemników.
Sklep internetowy jest w trakcie realizacji zamówienia składającego się z trzech przedmiotów. Ponieważ dysponuje jednym rodzajem pojemnika, musi sprawdzić, ile musi ich użyć aby zapakować całe zamówienie.
przestrzeń w pojemniku
o wymiarach
12x12x12
Wymiary: 10x10x10
Ilość: 3
Zapakowano jeden przedmiot
Zapakowano jeden przedmiot
Zapakowano jeden przedmiot
Sklep internetowy jest w trakcie realizacji zamówienia składającego się z trzech przedmiotów. Ponieważ dysponuje różnymi rodzajami pojemników, musi sprawdzić, które z nich powinny zostać użyte do optymalnego zapakowania całego zamówienia.
przestrzeń w pojemniku
o wymiarach
12x12x12
przestrzeń w pojemniku
o wymiarach
24x12x12
Wymiary: 10x10x10
Ilość: 3
24x12x12
Zapakowano 2 przedmioty
12x12x12
Zapakowano jeden przedmiot
Sklep internetowy jest w trakcie realizacji zamówienia składającego się z trzech przedmiotów. Ponieważ dysponuje różnymi rodzajami pojemników, musi sprawdzić, które z nich powinny zostać użyte do optymalnego zapakowania całego zamówienia.
przestrzeń w pojemniku
o wymiarach
12x12x12
przestrzeń w pojemniku
o wymiarach
24x12x12
przestrzeń w pojemniku
o wymiarach
24x24x24
Wymiary: 10x10x10
Ilość: 3
24x24x24
Zapakowano wszystkie 3 przedmioty
ADRESY SERWERÓW
PEM (X.509)
AKCEPTOWANE METODY PRZESYŁANIA DANYCH:
AKCEPTOWANE PROTOKOŁY:
SPOSOBY WYWOŁANIA:
PARAMETRY WYMAGANE
PARAMETRY OPCJONALNE
{"bins":[{"w":5,"h":5,"d":5,"max_wg":0,"id":"Bin1"},{"w":3,"h":3,"d":3,"max_wg":0,"id":"Bin2"}],"items":[{"w":5,"h":3,"d":2,"q":2,"vr":1,"wg":0,"id":"Item1"},{"w":3,"h":3,"d":3,"q":3,"vr":1,"wg":0,"id":"Item2"}],"username":"YOUR_USERNAME","api_key":"YOUR_API_KEY","params":{"images_background_color":"255,255,255","images_bin_border_color":"59,59,59","images_bin_fill_color":"230,230,230","images_item_border_color":"214,79,79","images_item_fill_color":"177,14,14","images_item_back_border_color":"215,103,103","images_sbs_last_item_fill_color":"99,93,93","images_sbs_last_item_border_color":"145,133,133","images_width":100,"images_height":100,"images_source":"file","images_sbs":1,"stats":1,"item_coordinates":1,"images_complete":1,"images_separated":1}}
{"response":{"bins_packed":[{"bin_data":{"w":5,"h":5,"d":5,"id":"Bin1","used_space":69.6,"weight":0,"used_weight":100},"image_complete":"...image_data...","images_generation_time":0.006,"packing_time":0.02697,"items":[{"id":"Item1","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"0","z1":"0","x2":3,"y2":5,"z2":2}},{"id":"Item2","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"0","z1":"2","x2":3,"y2":3,"z2":5}},{"id":"Item1","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"3","y1":"0","z1":"0","x2":5,"y2":5,"z2":3}}]},{"bin_data":{"w":3,"h":3,"d":3,"id":"Bin2","used_space":100},"image_complete":"...image_data...","images_generation_time":0.00269,"packing_time":0.02467,"items":[{"id":"Item2","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"0","z1":"0","x2":3,"y2":3,"z2":3}}]},{"bin_data":{"w":3,"h":3,"d":3,"id":"Bin2","used_space":100,"weight":0,"used_weight":100},"image_complete":"...image_data...","images_generation_time":0.00259,"packing_time":0.0252,"items":[{"id":"Item2","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"0","z1":"0","x2":3,"y2":3,"z2":3}}]}],"errors":[],"status":1,"not_packed_items":[],"response_time":0.09721}}
curl -X POST \ -H "Content-Type: application/json" \ -d '{"bins": [{"w": 5, "h": 5, "d": 5, "max_wg": 0, "id": "Bin1"},{"w": 3, "h": 3, "d": 3, "max_wg": 0, "id": "Bin2"}], "items": [{"w": 5, "h": 3, "d": 2, "q": 2, "vr": 1, "wg": 0, "id": "Item1"},{"w": 3, "h": 3, "d": 3, "q": 3, "vr": 1, "wg": 0, "id": "Item2"}], "username": "YOUR_USERNAME", "api_key": "YOUR_API_KEY", "params": {"images_background_color": "255,255,255", "images_bin_border_color": "59,59,59", "images_bin_fill_color": "230,230,230", "images_item_border_color": "214,79,79", "images_item_fill_color": "177,14,14", "images_item_back_border_color": "215,103,103", "images_sbs_last_item_fill_color": "99,93,93", "images_sbs_last_item_border_color": "145,133,133", "images_width": 100, "images_height": 100, "images_source": "file", "images_sbs": 1, "stats": 1, "item_coordinates": 1, "images_complete": 1, "images_separated": 1}}' \ https://eu.api.3dbinpacking.com/packer/packIntoMany \ -k
{"response": {"bins_packed": [{"bin_data": {"w": 5, "h": 5, "d": 5, "id": "Bin1", "used_space": 69.6, "weight": 0, "used_weight": 100}, "image_complete": "...image_data...", "images_generation_time": 0.006, "packing_time": 0.02697, "items": [{"id": "Item1", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "0", "z1": "0", "x2": 3, "y2": 5, "z2": 2}},{"id": "Item2", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "0", "z1": "2", "x2": 3, "y2": 3, "z2": 5}},{"id": "Item1", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "3", "y1": "0", "z1": "0", "x2": 5, "y2": 5, "z2": 3}}]},{"bin_data": {"w": 3, "h": 3, "d": 3, "id": "Bin2", "used_space": 100}, "image_complete": "...image_data...", "images_generation_time": 0.00269, "packing_time": 0.02467, "items": [{"id": "Item2", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "0", "z1": "0", "x2": 3, "y2": 3, "z2": 3}}]},{"bin_data": {"w": 3, "h": 3, "d": 3, "id": "Bin2", "used_space": 100, "weight": 0, "used_weight": 100}, "image_complete": "...image_data...", "images_generation_time": 0.00259, "packing_time": 0.0252, "items": [{"id": "Item2", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "0", "z1": "0", "x2": 3, "y2": 3, "z2": 3}}]}], "errors": [], "status": 1, "not_packed_items": [], "response_time": 0.09721}}
$data = array( 'bins' => array( array( 'w' => '5', 'h' => '5', 'd' => '5', 'max_wg' => '0', 'id' => 'Bin1' ), array( 'w' => '3', 'h' => '3', 'd' => '3', 'max_wg' => '0', 'id' => 'Bin2' ) ), 'items' => array( array( 'w' => '5', 'h' => '3', 'd' => '2', 'q' => '2', 'vr' => '1', 'wg' => '0', 'id' => 'Item1' ), array( 'w' => '3', 'h' => '3', 'd' => '3', 'q' => '3', 'vr' => '1', 'wg' => '0', 'id' => 'Item2' ) ), 'username' => 'YOUR_USERNAME', 'api_key' => 'YOUR_API_KEY', 'params' => array( 'images_background_color' => '255,255,255', 'images_bin_border_color' => '59,59,59', 'images_bin_fill_color' => '230,230,230', 'images_item_border_color' => '214,79,79', 'images_item_fill_color' => '177,14,14', 'images_item_back_border_color' => '215,103,103', 'images_sbs_last_item_fill_color' => '99,93,93', 'images_sbs_last_item_border_color' => '145,133,133', 'images_width' => '100', 'images_height' => '100', 'images_source' => 'file', 'images_sbs' => '1', 'stats' => '1', 'item_coordinates' => '1', 'images_complete' => '1', 'images_separated' => '1' ) ); $query = json_encode($data); $url = "http://eu.api.3dbinpacking.com/packer/packIntoMany"; $prepared_query = 'query='.$query; $ch = curl_init($url); curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $prepared_query ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $resp = curl_exec($ch); if (curl_errno($ch)) { echo 'Error #' . curl_errno($ch) . ': ' . curl_error($ch).'<br>'; } curl_close($ch); $response = json_decode($resp,true); // display errors if(isset($response['response']['errors'])){ foreach($response['response']['errors'] as $error){ echo $error['message'].'<br>'; } } // display data if( $response['response']['status'] > -1 ){ $b_packed= $response['response']['bins_packed']; foreach ($b_packed as $bin){ echo "<h2>Bin id:{$bin['bin_data']['id']}</h2> <p> {$bin['bin_data']['w']} x {$bin['bin_data']['h']} x {$bin['bin_data']['d']}</p> <p> Weight:{$bin['bin_data']['weight']}</p> <p> Used weight:{ $bin['bin_data']['used_weight'] }</p> <img src=\"{$bin['image_complete']}\"> <h2>Items packed in this bin:</h2>"; $items = $bin['items']; echo '<table style="text-align: center"> <tr><th>Item id</th> <th>Item dimensions</th> <th>Item weight</th> <th>Separated item</th> <th>Step by step</th></tr>'; foreach ( $items as $item){ echo "<tr><td>{$item['id']}</td> <td> {$item['w']} x {$item['h']} x {$bin['bin_data']['d']}</td> <td> {$item['wg']}</td> <td><img src=\"{$item['image_separated']}\"></td> <td><img src=\"{$item['image_sbs']}\"></td> </tr>"; } echo '</table>'; echo '<hr>'; } }
#!/usr/bin/python import httplib import urllib import json conn = httplib.HTTPConnection(host='eu.api.3dbinpacking.com', port=80) data = {"bins": [{"w": 5, "h": 5, "d": 5, "max_wg": 0, "id": "Bin1"},{"w": 3, "h": 3, "d": 3, "max_wg": 0, "id": "Bin2"}], "items": [{"w": 5, "h": 3, "d": 2, "q": 2, "vr": 1, "wg": 0, "id": "Item1"},{"w": 3, "h": 3, "d": 3, "q": 3, "vr": 1, "wg": 0, "id": "Item2"}], "username": "YOUR_USERNAME", "api_key": "YOUR_API_KEY", "params": {"images_background_color": "255,255,255", "images_bin_border_color": "59,59,59", "images_bin_fill_color": "230,230,230", "images_item_border_color": "214,79,79", "images_item_fill_color": "177,14,14", "images_item_back_border_color": "215,103,103", "images_sbs_last_item_fill_color": "99,93,93", "images_sbs_last_item_border_color": "145,133,133", "images_width": 100, "images_height": 100, "images_source": "file", "images_sbs": 1, "stats": 1, "item_coordinates": 1, "images_complete": 1, "images_separated": 1}} params = urllib.urlencode( {'query':json.dumps(data)} ) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} conn.request( "POST", "/packer/packIntoMany", params, headers ) content = conn.getresponse( ).read( ) conn.close( ) print content
package javaapplication1; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;; import org.json.simple.JSONObject; import org.springframework.web.client.RestTemplate; public class JavaApplication1 { /** * @param args the command line arguments */ public static void main(String[] args) throws MalformedURLException, ProtocolException, IOException { RestTemplate restTemplate = new RestTemplate(); JSONObject json = new JSONObject(); //SET BINS List<Map<String , String>> bins = new ArrayList<Map<String,String>>(); Map<String, String> bin1 = new HashMap<String, String>(); bin1.put("w", "5"); bin1.put("h", "5"); bin1.put("d", "5"); bin1.put("max_wg", "0"); bin1.put("id", "Bin1"); bins.add(bin1); Map<String, String> bin2 = new HashMap<String, String>(); bin2.put("w", "3"); bin2.put("h", "3"); bin2.put("d", "3"); bin2.put("max_wg", "0"); bin2.put("id", "Bin2"); bins.add(bin2); //SET ITEMS List<Map<String , String>> items = new ArrayList<Map<String,String>>(); Map<String, String> item1 = new HashMap<String, String>(); item1.put("w", "5"); item1.put("h", "3"); item1.put("d", "2"); item1.put("q", "2"); item1.put("vr", "1"); item1.put("wg", "0"); item1.put("id", "Item1"); items.add(item1); Map<String, String> item2 = new HashMap<String, String>(); item2.put("w", "3"); item2.put("h", "3"); item2.put("d", "3"); item2.put("q", "3"); item2.put("vr", "1"); item2.put("wg", "0"); item2.put("id", "Item2"); items.add(item2); //SET PARAMETERS Map <String , String > params = new HashMap <String , String >(); params.put("images_background_color", "255,255,255") params.put("images_bin_border_color", "59,59,59") params.put("images_bin_fill_color", "230,230,230") params.put("images_item_border_color", "214,79,79") params.put("images_item_fill_color", "177,14,14") params.put("images_item_back_border_color", "215,103,103") params.put("images_sbs_last_item_fill_color", "99,93,93") params.put("images_sbs_last_item_border_color", "145,133,133") params.put("images_width", "100") params.put("images_height", "100") params.put("images_source", "file") params.put("images_sbs", "1") params.put("stats", "1") params.put("item_coordinates", "1") params.put("images_complete", "1") params.put("images_separated", "1") //ADD ELEMENTS TO JSON json.put("username", "YOUR_USERNAME"); json.put("api_key", "YOUR_API_KEY"); json.put("items", items); json.put("bins", bins); json.put("params", params); //CALL QUERY HttpURLConnection conn; URL addr = new URL("http://eu.api.3dbinpacking.com/packer/packIntoMany"); conn = (HttpURLConnection) addr.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.connect(); OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream()); // prepare POST body String query = "query=" + json.toString(); osw.write(query); osw.flush(); osw.close(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String response_json = br.readLine(); //DO SOMETHING COOL WITH THE RESPONSE System.out.println(response_json); } }
string data; System.Net.HttpWebRequest req = System.Net.WebRequest.Create("https://eu.api.3dbinpacking.com/packer/packIntoMany") as System.Net.HttpWebRequest; var request_data = new {username = "YOUR_USERNAME", api_key = "YOUR_API_KEY", items = new[] { new { w = "5", h = "3", d = "2", q = "2", vr = "1", wg = "0", id = "Item1"}, new { w = "3", h = "3", d = "3", q = "3", vr = "1", wg = "0", id = "Item2"} }, bins = new[] { new { w = "5", h = "5", d = "5", max_wg = "0", id = "Bin1"}, new { w = "3", h = "3", d = "3", max_wg = "0", id = "Bin2"} }, @params = new { images_background_color = "255,255,255", images_bin_border_color = "59,59,59", images_bin_fill_color = "230,230,230", images_item_border_color = "214,79,79", images_item_fill_color = "177,14,14", images_item_back_border_color = "215,103,103", images_sbs_last_item_fill_color = "99,93,93", images_sbs_last_item_border_color = "145,133,133", images_width = "100", images_height = "100", images_source = "file", images_sbs = "1", stats = "1", item_coordinates = "1", images_complete = "1", images_separated = "1" } }; string json_str = JsonConvert.SerializeObject(request_data); string queryParam = "query="+json_str; byte[] postBytes = System.Text.Encoding.ASCII.GetBytes(queryParam); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = postBytes.Length; System.IO.Stream postStream = req.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); X509Certificate Cert = X509Certificate2.CreateFromCertFile("path_to_pem_key\eu.api.3dbinpacking.com.pem"); req.ClientCertificates.Add(Cert); using (System.Net.HttpWebResponse response = req.GetResponse() as System.Net.HttpWebResponse) { System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()); data = reader.ReadToEnd(); }