Answer the question
In order to leave comments, you need to log in
How to most efficiently place elements on the square?
Condition of the problem:
We have an area with given proportions, say:
The first element in the array is height, the second is width. And we have an array with elements:const area = [100, 200];
const items = [
[10, 4],
[20, 30],
[25, 3],
...
];
function resolve(area, items) {...};
console.log(resolve(area, items));
// { solved: [[4, 10], [20, 30], [3, 25]...], exclude: [[50, 60],[2, 100]...]};
Answer the question
In order to leave comments, you need to log in
I think this is the most accurate solution I've found:
rosettacode.org/wiki/Knapsack_problem
The packing problem has no "math. formula" solution.
Your case is somewhat simpler because of the discreteness.
A normal topic for fl, provided that there is an understanding that optimization problems are not always solved in the best possible way)
Haha, laugh. Although a year ago, when I took on a similar project, I also wore the same rose-colored glasses)))
As a result, the project cost 200k.
The general scheme is as follows:
1. Drive in the coordinates of ALL points of your site into the database, i. 100 * 200 = 20000 points (I had 1000 * 1000)
2. I did it in php - I receive an incoming request for the desired size, for example, I need a 12 * 7 rectangle, I select an array of free points from the database, then I process it in php, there on 300 lines of the script turned out.
3. then return to the database - I mark all points from the selected place with the BUSY mark
, etc.
Of course, you have a fundamentally different task, but the complexity is definitely similar!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question