bin-packing | javascript binary tree based algorithm for 2d bin | Game Engine library
kandi X-RAY | bin-packing Summary
kandi X-RAY | bin-packing Summary
A javascript binary tree based algorithm for 2d bin-packing suitable for generating CSS sprites
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of bin-packing
bin-packing Key Features
bin-packing Examples and Code Snippets
Community Discussions
Trending Discussions on bin-packing
QUESTION
I am playing with a 2d bin packing model. I tried this using:
...ANSWER
Answered 2021-Feb-20 at 00:49If you set solver.parameters.log_search_progress = True
you'll see:
QUESTION
I have a problem that is similar to the bin packing problem, however the problem is different:
- There are x vehicles, which could be anywhere in a 2D plane
- Each vehicle has passenger capacity y
- There are z passengers, which could be anywhere in a 2D plane
I'd like to write an algorithm to sort the passengers into the vehicles, within the following constraints:
- Passengers must move to their closest vehicle
- If a vehicle reaches capacity, no more passengers can move to it
I would like a pseudo-code algorithm as I'm not yet sure if I'll be implementing this in JavaScript, PHP or SQL. My first attempt is this:
- Assign each passenger a numeric ID starting from 0 and incrementing by 1
- Assign each vehicle a numeric ID starting from 0 and incrementing by 1
- Create an array for each vehicle with the same name/ID as its vehicle ID
- For each passenger, calculate the distance between it and all vehicles
- Store the results in a passenger/vehicle array:
[passengerID, distance to vehicleID1, distance to vehicleID2, etc.]
- Repeat these step for z passengers:
- Iterate over the array and find the smallest distance value. This should be the passenger who is closest to a vehicle
- Add the passengerID to the vehicle array
- Remove that passenger item from the passenger/vehicle array
- Check the occupants of the vehicle array added to. If length equals capacity, nullify every instance of the passenger-distance value in the passenger/vehicle array
At the end of execution, we should have an empty passenger/vehicle array if number of passengers is less than total vehicle capacity, or a few elements left in that array if there are more passengers than would fit in all vehicles. We should also have arrays for each vehicle that have the same number of elements as their capacity, or possibly fewer if there were fewer passengers than vehicle capacity.
I am pretty sure the above will work, but I feel that there could be a more efficient method. I'm particularly concerned about calculating the distances between every passenger and vehicle to begin with, as this will be computationally expensive.
Can anyone point me to a more efficient solution?
Many thanks, Arj
...ANSWER
Answered 2020-Feb-02 at 03:39Firstly, any algorithm must make use of both dimensions. If you project all points onto the x plane or y plane then you lose one dimension of information. So you must measure the distance between any vehicle / passenger pair.
Once you do this you can think of it as a region growing algorithm:
- Uniformly grow a region (circle) around each vehicle.
- As soon as a passenger is included in the region for a vehicle then that passenger is assigned to that vehicle
- When a vehicle reaches it's capacity, stop growing the region
In code, the start would be the same but you can speed it up slightly with sorting:
- Create an array for each vehicle, storing the distance to each passenger
- Take the unique values across all of these arrays and sort them in ascending order
- Then iterate through this unique list of distances. For each distance assign passengers who have that distance across each array.
- When a vehicle reaches its capacity, remove that array.
QUESTION
I have a package (https://github.com/skjolber/3d-bin-container-packing/) that will pack items into a container for me. However, if there are too many items for example a quantity of 1000 shirts, and only 500 fit in the biggest container we have, it won't try to pack the remaining 500 the result simply returns null and does not try to combine the containers available.
I am tackling a bin-packing-problem. Note that this doesn't need to be an exact solution as we are just putting together a cost calculator for freight. I stumbled upon a package that handles most of the problem. Basically I have 5 containers that are usable. The API receives a request with products and I gather the dimensions and pack them. My initial thought was to check if the pack was successful and if it was then add it to the List packingResults object so that I have a list. But the way this package is set up I suspect that it will not work without losing integrity of the products.
Here is the service constructor
...ANSWER
Answered 2019-Jan-16 at 17:12See if Spring retry can be of any use. To have retrial and different logic in the method where you doubt you will not get your first list and so on.
QUESTION
I'm using this binary pack code. I'm using its GrowingPacker
approach. It works fine, but I have a hard time figuring out the dimensions of the final pack, I mean the bounding box of final result like (xMin, xMax, yMin, yMax)
. What is the best approach to find it?
Can I use the final values of x, y, w, h
for this.root
to compute the bounding box?
I'm not sure if it is correct, but currently I'm using a loop like that loop to compute the bounding box of final pack (I'm using C++):
...ANSWER
Answered 2019-Jul-24 at 23:08To calculate the bounding box that encompasses all the bounding boxes in your list of blocks, you need find the minimum and maximum X and Y and then use that to calculate the width and height of the overall bounding box.
Calculating the maximum width and height of the smaller boxes won't work because that will be the size of the widest and highest of the individual smaller boxes, which won't necessarily be the dimensions of the overall bounding box that encompasses all of them.
QUESTION
I have used the bin packing js implementation here https://github.com/jakesgordon/bin-packing
When I specify the frame size as 800x600
and Blocks size as 150x700,150x700 it would say that, it cant accommodate However, there is ample space. The same when 700x150, 700x150 is made, it would fit it.
How Do I adapt the code, so that it can dynamically rotate the block size and fits in to the frame.
The js packer used here is,
...ANSWER
Answered 2019-Jun-18 at 23:50I think the code below might do the trick...?! (Ie, I did limited testing, but for what I tested, it appears to work.)
I essentially added another option in the findnode routine to rotate the block (ie, switch the width and height dimensions) as an option if it doesn't fit in it's predefined orientation. This involved adding another property to block dubbed rotate as an indicator that the dimensions were swapped. (And the introduction of swapping and the rotate property necessitated, of course, passing block to findnode rather than w and h as in the previous code.)
QUESTION
the below script is bin-packing First-fit algorithm,the script is running normally on ubuntu Linux and i can call bin_packing.awk, but when I try to run it on unix solaris I'm getting errors
bin_packing.awk
:
ANSWER
Answered 2019-May-11 at 00:42using nawk
(new awk) or /usr/xpg4/bin/awk
(POSIX awk) with Solaris. awk
is the original legacy version with Perl to glean the same info as find's -printf:
Here is the soluation:
QUESTION
I've never used Jolt Transform before and I'm not sure how to fix what I've done, so I apologize if this is actually a really easy fix.
I have two XML files (dummy versions below, actual contains PII) that I merged together using MergeRecord in NiFi. Because of the way that the output is (one flow file with an array of JSONS) it was suggested that I use JoltTransform to merge them together properly. I was pointed to this question on how to essentially do a streaming join in NiFi (which is what I needed).
While this works for the most part, I am still having one issue. All of the tags on my "base" level (FatherID, FatherName, BirthDate, etc.) are turned into arrays. I need these to not be arrays, because I'd like to use the same combined schema I used in MergeRecord (which does not have those fields as arrays).
Is there something I need to change in the spec, or do I need to do another JoltTransform (which is fine)?
Input XML 1
...ANSWER
Answered 2019-Apr-23 at 17:02MergeContent and MergeRecord are usually for merging two or more flowfiles whose schema is the same, such as bundling individual JSON objects into a larger array.
You might be able to use LookupRecord using an XMLFileLookupService, that will get the content of the second XML file and insert it into the record of the first flowfile at the location you choose. The part I'm not sure of is how you'd lookup the DOCID (to match the FatherID), then return each of the fields in the top-level DOC element.
If that doesn't work, you can always try ExecuteScript or InvokeScriptedProcessor (or a ScriptedLookupService) to do the "merge" manually.
EDIT (additional info): If the JOLT spec always puts the non-null value first (or all elements in the array will be null or identical), you might be able to add a spec to your chain that replaces the field value with the first element in its array.
QUESTION
For my task I had to write a bin-packing algorithm where there are N objects with different volumes. They all had to be packed into boxes of volume V. Using Decreasing Sorting I successfully wrote the algorithm. But another task includes writing out all possible variations of bin-packing in an amount of boxes that I previously found most effective. So for example:
There are 4 objects with volumes: 4, 6, 3, 2. Volume of boxes is 10. Using the bin-packing algorithm I find that I will need 2 boxes.
All possible variations would be:
...ANSWER
Answered 2019-Apr-01 at 13:12The general algorithm for solving this problem goes like this:
Try to fit all objects in n bins by creating all possible split configurations into n groups and test if any such configuration fits in the bins.
If not, increase n and try again.
Now, how do you find all possible split configurations?
Consider putting a tag on each object to decide into which bin it belongs. If you have 3 objects and 2 bins, then each object can get the tag 0
or 1
(for any of the two bins). This makes 2^3 = 8 combinations:
QUESTION
I'm trying to replicate this Algorithm in C, the Packing Blocks into a Fixed Rectangle
part and I already make a question about it, the solution to that question was correct, but it didn't fixed the overall problem. I have found specific input that is causing a "error" and to show that, I set the values statically in the code just to make it easier for testing.
ANSWER
Answered 2018-Nov-30 at 16:52I think you have a bug in your code:
QUESTION
I saw this Algorithm, it's made with javascript and I'm trying to do Packing Blocks into a Fixed Rectangle
in C.
In my code, shown below, I read data from a .txt
. This part have no problem, I'm just making a array of pointers to struct Blocks
and after I sort it.
After that I'm doing exactly like the code in the article, same logic, and that is where the errors are happening.
ANSWER
Answered 2018-Nov-29 at 14:43You are correct in your assumption that ||
has different semantics in JavaScript and C.
In JavaScript, a || b
returns a
if a
is "truthy" and b
if a
is falsy
.
Meanwhile in C, a || b
is a boolean expression. It will always return true
or false
instead of the original expressions.
For example, 5 || 0
is 5
in JavaScript but 1
in C.
Replacing return findNode(root->right, w, h) || findNode(root->down, w, h);
with
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bin-packing
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page