Working out how to fill a gap with the least number of items between 2 sizes and using a 2nd item if required.

56 Views Asked by At

I'm working on a project and all going swimingly so far until I hit the maths wall.

At the moment we work this out by hand by reverse engineering from a number we already know the answer too (2114) but with each of us working it out slightly different and it taking quite awhile sometimes as none of us are very good with a calculator we always end up if slightly different results. Hence the need for something that works it out. And adding it to our intranet.

Any help working this out would be awesome. thanks.

Rules;

Get Number(gap) Between 590 -> 4500

Work out the sizes of Panel & Infills required to fill this gap with the below rules;

Panels must = odd number

Infills (if required) must = even number & be no more than 1 higher in quantity than Panels

Minumum Size for Panels = 590 Max Size for Panels = 705

Minimum Size for Infills = 75 Max Size for Infills = 175

I don't currently have a formula for an example (because I don't even know where to start) All I've managed to do is some really basic: gap / 705 = a then if a isn't a whole number find the difference and do diff / 75 = b but keep repeating this until i get anywhere near a good size.

I'm not even sure what tags to use.

2

There are 2 best solutions below

0
On

I'm pretty sure there is no formula for this. You will need an algorithm.

Your problem is related to the typesetting problem for right justifying lines - you need to put some words (your panels) of varying lengths into a fixed length line (your gap) with whitespace (your infills) between words.

There's a lot of literature on this that may help. The search for typography line justification algorithms is a place to start - read about how to do it, not whether to do it.

It's not clear from your question whether you are free to vary the lengths of the panels, or whether they are given with fixed bounded lengths (like words).

You started in a reasonable way, by trying to guess at the (largest?) number of panels that will fit. Then, as you say

keep repeating this until i get anywhere near a good size.

If you can make the conditions/requirements a little more formal you could consult a local computer science savvy person for an algorithm, or ask at stackexchange.com

Good luck.

2
On

The suggestion given by awkward is quite useful: Excel Solver can work this problem out.
However, since there is not a single solution, the Solver will provide you with the first it is going to find.

Before going "fully authomatically" I would suggest an intermediate step, going through a graphical program.

Consider in fact to call $n$ the number of panels, $x$ their size, $m$ the number of infills , $y$ the size of them and $G$ the gap size.

Then you shall have $$ n\,x + m\,y = G $$ rewrite it as $$ {n \over {G/x}}\, + {m \over {G/y}}\, = {n \over a}\, + {m \over b} = 1 $$ which, in the plane $n,m$ is the equation of a line with intercepts at $n=a$ and $m=b$.

Panels_infills_1

Referring to the sketch above, you actually have just a few points $(n,m)$ to test.
So choose one of them, draw a line through it, determine the intercepts, and given $G$ find $(x,y)$ and check whether they obey the relative bounds.

You can use a graphic system like Geogebra to automate the calculation and representation of the point in $x,y$ in function of the change that you make to the line.

These first trials will also indicate, depending on other technical features/conditions you might desire, whether and how you can fix an optimization function on $x,y$, which then will
allow a "Solver" to provide a unique answer.