Algorytm ten umożliwia znalezienie rozmiaru pojemnika dla podanych przedmiotów.
Sklep internetowy posiada własną maszynę do tworzenia opakowań o wybranych wymiarach. W celu jej zaprogramowania należy obliczyć wymiary opakowania dla danego zamówienia.
przestrzeń w pojemniku
o wymiarach
?
Wymiary: 10x10x10
Ilość: 8
20x20x20
Zapakowano wszystkie 8 przedmiotów
Obliczony wymiar potrzebnego pojemnika: 20x20x20
Sklep internetowy posiada własną maszynę do tworzenia opakowań o wybranych wymiarach. W celu jej zaprogramowania należy obliczyć wymiary opakowania dla danego zamówienia.
przestrzeń w pojemniku
o wymiarach
max: 20x15x20
Wymiary: 10x10x10
Ilość: 8
20x10x20
Zapakowano 4 przedmioty
Obliczony wymiar potrzebnego pojemnika: 20x10x20
4 przedmioty niezapakowane (zbyt mała pojemność pojemnika)
ADRESY SERWERÓW
PEM (X.509)
AKCEPTOWANE METODY PRZESYŁANIA DANYCH:
AKCEPTOWANE PROTOKOŁY:
SPOSOBY WYWOŁANIA:
PARAMETRY WYMAGANE
PARAMETRY OPCJONALNE
{"bins":[{"w":0,"h":0,"d":0,"id":"Bin1"}],"items":[{"w":5,"h":3,"d":2,"q":2,"vr":1,"id":"Item1"},{"w":3,"h":3,"d":3,"q":3,"vr":1,"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":6,"d":6,"id":"Bin1","used_space":78.3333},"image_complete":"...image_data...","images_generation_time":0.02894,"packing_time":0.09116,"items":[{"id":"Item1","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"0","z1":"0","x2":2,"y2":5,"z2":3}},{"id":"Item1","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"5","z1":"0","x2":2,"y2":8,"z2":5}},{"id":"Item2","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"2","y1":"0","z1":"0","x2":5,"y2":3,"z2":3}},{"id":"Item2","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"2","y1":"3","z1":"0","x2":5,"y2":6,"z2":3}},{"id":"Item2","image_searated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"2","y1":"6","z1":"0","x2":5,"y2":9,"z2":3}}],"not_packed_items":[]},{"bin_data":{"w":3,"h":18,"d":3,"id":1,"used_space":70.3704},"image_complete":"...image_data...","images_generation_time":0.00363,"packing_time":0.08667,"items":[{"id":0,"image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"0","z1":"0","x2":2,"y2":5,"z2":3}},{"id":0,"image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"5","z1":"0","x2":2,"y2":10,"z2":3}},{"id":"1","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"10","z1":"0","x2":3,"y2":13,"z2":3}},{"id":"1","image_separated":"...image_data...","image_sbs":"...image_data...","coordinates":{"x1":"0","y1":"13","z1":"0","x2":3,"y2":16,"z2":3}}],"not_packed_items":[{"id":"1","q":1}]}],"errors":[],"status":1,"not_packed_items":[],"response_time":0.22307}}
curl -X POST \ -H "Content-Type: application/json" \ -d '{"bins": [{"w": 0, "h": 0, "d": 0, "id": "Bin1"}], "items": [{"w": 5, "h": 3, "d": 2, "q": 2, "vr": 1, "id": "Item1"},{"w": 3, "h": 3, "d": 3, "q": 3, "vr": 1, "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/findBinSize \ -k
{"response": {"bins_packed": [{"bin_data": {"w": 5, "h": 6, "d": 6, "id": "Bin1", "used_space": 78.3333}, "image_complete": "...image_data...", "images_generation_time": 0.02894, "packing_time": 0.09116, "items": [{"id": "Item1", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "0", "z1": "0", "x2": 2, "y2": 5, "z2": 3}},{"id": "Item1", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "5", "z1": "0", "x2": 2, "y2": 8, "z2": 5}},{"id": "Item2", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "2", "y1": "0", "z1": "0", "x2": 5, "y2": 3, "z2": 3}},{"id": "Item2", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "2", "y1": "3", "z1": "0", "x2": 5, "y2": 6, "z2": 3}},{"id": "Item2", "image_searated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "2", "y1": "6", "z1": "0", "x2": 5, "y2": 9, "z2": 3}}], "not_packed_items": []},{"bin_data": {"w": 3, "h": 18, "d": 3, "id": 1, "used_space": 70.3704}, "image_complete": "...image_data...", "images_generation_time": 0.00363, "packing_time": 0.08667, "items": [{"id": 0, "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "0", "z1": "0", "x2": 2, "y2": 5, "z2": 3}},{"id": 0, "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "5", "z1": "0", "x2": 2, "y2": 10, "z2": 3}},{"id": "1", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "10", "z1": "0", "x2": 3, "y2": 13, "z2": 3}},{"id": "1", "image_separated": "...image_data...", "image_sbs": "...image_data...", "coordinates": {"x1": "0", "y1": "13", "z1": "0", "x2": 3, "y2": 16, "z2": 3}}], "not_packed_items": [{"id": "1", "q": 1}]}], "errors": [], "status": 1, "not_packed_items": [], "response_time": 0.22307}}
$data = array( 'bins' => array( array( 'w' => '0', 'h' => '0', 'd' => '0', 'id' => 'Bin1' ) ), 'items' => array( array( 'w' => '5', 'h' => '3', 'd' => '2', 'q' => '2', 'vr' => '1', 'id' => 'Item1' ), array( 'w' => '3', 'h' => '3', 'd' => '3', 'q' => '3', 'vr' => '1', '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/findBinSize"; $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": 0, "h": 0, "d": 0, "id": "Bin1"}], "items": [{"w": 5, "h": 3, "d": 2, "q": 2, "vr": 1, "id": "Item1"},{"w": 3, "h": 3, "d": 3, "q": 3, "vr": 1, "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/findBinSize", 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", "0"); bin1.put("h", "0"); bin1.put("d", "0"); bin1.put("id", "Bin1"); bins.add(bin1); //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("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("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/findBinSize"); 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/findBinSize") 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", id = "Item1"}, new { w = "3", h = "3", d = "3", q = "3", vr = "1", id = "Item2"} }, bins = new[] { new { w = "0", h = "0", d = "0", id = "Bin1"} }, @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(); }