Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

Thank in advance...

Regards,
Anil
Posted
Comments
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

1 solution

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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900