12,301,965 members (54,948 online)
Rate this:
See more: (untagged)
Hi All,

I have a problem with nesting of lengths please suggest me the best way of solving this. my problem is as follows.

I have some standard length lets say Total length (This is the total length which we need to fill with some specific length blocks)

input is list of length blocks eg: 5000, 4000, 3000 .....

and gap between each block is a range eg: 200 to 500 (this gap can be adjusted with in the range)

Now we have to fill the Total length with the above available length blocks with gap between each block and that gap should be with in the gap range given above.

Please suggest me some way of solving this problem.

Regards,
Anil
Posted 30-May-12 0:24am
Andreas Gieriet 4-Jun-12 11:41am

You give too little information about constraints.
Is this an optimum calculation? What is a "good enough" solution?
Cheers
Andi

Rate this:

## Solution 1

Assuming you have
- a total length Ltotal
- a list of n varying length segments Si
- possible gaps in the range of [Gmin...Gmax]

If you have no further constraints (e.g. not all segments need to be placed, and any size of gap can remain at the end), then start to fill randomly (or from begin to end) and leave a Gmin between each segement. Stop when there is no segment left or when the next segment can not be placed any more.

This is an obvious solution, but maybe not good enough.

If you have to check for the possible solution where all segments must be places and no trailing gap is allowed, then you calculate the best versus worst case:
1) Sum of all segments: Stotal = ∑ Si
2) Room for all gaps: Gtotal = Ltotal - Stotal
3) Minimal gaps: Gtotal(min) = (n-1) x Gmin
4) Maximal gaps: Gtotal(max) = (n-1) x Gmax

5) ok if Gtotal(min) ≤ Gtotal ≤ Gtotal(max)

6a) if ok, average gap Gav = Gtotal / (n-1)
7a) if ok, place one segment Si after the other and place gap Gav in between.

6b) if not ok, error.

Cheers
Andi
v2

Top Experts
Last 24hrsThis month
 BillWoodruff 360 CHill60 330 Dave Kreskowiak 280 Sergey Alexandrovich Kryukov 209 OriginalGriff 207
 OriginalGriff 9,996 ppolymorphe 5,936 CHill60 5,827 Karthik Bangalore 5,391 Richard MacCutchan 5,282