Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: logic
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 30-May-12 1:24am
Comments
Andreas Gieriet at 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

Rate this: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 4 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100