Simplifying
First I want to simplify the problem, to do that:
- I switch the axes and add them to each other, this results in x2 growth
- I assume it is parabola on a closed interval
[a, b], where a = 0
and for this example b = 3
Lets say you are given b
(second part of interval) and w
(width of a segment), then you can find total number of segments by n=Floor[b/w]
. In this case there exists a trivial case to maximize Riemann sum and function to get i'th segment height is: f(b-(b*i)/(n+1)))
. Actually it is an assumption and I'm not 100% sure.
Max'ed example for 17
segments on closed interval [0, 3]
for function Sqrt[x]
real values:
And the segment heights function in this case is Re[Sqrt[3-3*Range[1,17]/18]]
, and values are:
{Sqrt[17/6], 2 Sqrt[2/3], Sqrt[5/2],
Sqrt[7/3], Sqrt[13/6], Sqrt[2],
Sqrt[11/6], Sqrt[5/3], Sqrt[3/2],
2/Sqrt[3], Sqrt[7/6], 1, Sqrt[5/6],
Sqrt[2/3], 1/Sqrt[2], 1/Sqrt[3],
1/Sqrt[6]}
{1.6832508230603465,
1.632993161855452, 1.5811388300841898, 1.5275252316519468, 1.4719601443879744, 1.4142135623730951, 1.35400640077266, 1.2909944487358056, 1.224744871391589, 1.1547005383792517, 1.0801234497346435, 1, 0.9128709291752769, 0.816496580927726, 0.7071067811865475, 0.5773502691896258, 0.4082482904638631}
What you have archived is a Bin-Packing problem, with partially filled bin.
Finding b
If b
is unknown or our task is to find smallest possible b
under what all sticks form the initial bunch fit. Then we can limit at least b
values to:
- lower limit : if sum of segment heights = sum of stick heights
- upper limit :
number of segments = number of sticks longest stick < longest segment height
One of the simplest way to find b
is to take a pivot at (higher limit-lower limit)/2
find if solution exists. Then it becomes new higher or lower limit and you repeat the process until required precision is met.
When you are looking for b
you do not need exact result, but suboptimal and it would be much faster if you use efficient algorithm to find relatively close pivot point to actual b
.
For example:
- sort the stick by length: largest to smallest
- start 'putting largest items' into first bin thy fit