- a total length L

_{total}

- a list of n varying length segments S

_{i}

- possible gaps in the range of [G

_{min}...G

_{max}]

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 G

_{min}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: S

_{total}= ∑ S

_{i}

2) Room for all gaps: G

_{total}= L

_{total}- S

_{total}

3) Minimal gaps: G

_{total(min)}= (n-1) x G

_{min}

4) Maximal gaps: G

_{total(max)}= (n-1) x G

_{max}

5) ok if G

_{total(min)}≤ G

_{total}≤ G

_{total(max)}

6a) if ok, average gap G

_{av}= G

_{total}/ (n-1)

7a) if ok, place one segment S

_{i}after the other and place gap G

_{av}in between.

6b) if not ok, error.

Cheers

Andi

Is this an optimum calculation? What is a "good enough" solution?

Cheers

Andi