[reportlab-users] Problem with row&column spanning code not calculating table heights

Robin Becker reportlab-users@reportlab.com
Thu, 16 Oct 2003 13:45:33 +0100


In article <3F8E7B32.7000606@gmx.net>, Oliver Bleutgen <myzope@gmx.net>
writes
>Hmm, the first try didn't make it, resending, sorry if this appears twice.
>
>Robin Becker wrote:
>> In article <PGECLPOBGNBNKHNAGIJHIENEFJAA.andy@reportlab.com>, Andy
>> Robinson <andy@reportlab.com> writes
>>
>>
>>
>> ....
>> gurk. I believe it's more complicated
>>
>> [example snipped]
>>
>> Of course this is about the simplest possible row spanning problem. In a
>> more general problem with multiple overlapping spans we can still solve
>> the LP formulation to get the required minimum required overall heights.
>> I'm not sure if there's a simple general formulation that is easy to
>> solve.
>

Your approach sounds more feasible. I think it boils down to
1) Find the minimum distance from the top of each cell bottom based only
on cells above it; append this to a list cb[r].

2) Find the maximum value over the elements of cb[r]. That gives a
feasible bottom of row r.

The only problem here is that when we have bothe spanned columns and
rows the idea of a column is slightly harder to establish. I'm guessing
that we really need to search over cells establishing the minimum stuff
above us. My only other gripe with this is that wne rows are not in the
maximum path we don't adjust them in proportion to their desires so in
the first case below the cells in column 1 both require height 0.5, but
in the computed solution the row heights are 0.5 and 1.5. Although
completely feasible this may not look nice.
   
>Interesting riddle. I may be way off, but I think to describe that as LP
>overstates the problem.
>After all, the space of possible solutions is finite in this case, isn't it?
>
>What about the following snipped (which is actually runnable):

My version of the code is slightly more efficient I get this when I run
it

Robin's Case 1: column 1 occupies 2 rows and is binding
input [{0: 0.5, 1: 0.5}, {1: 2}]
output [0.5, 2]
Robin's Case 1: column 1 occupies 2 rows
input [{0: 0.5, 1: 0.5}, {1: 0.90000000000000002}]
output [0.5, 1.0]
input [{0: 1, 1: 3, 2: 1}, {0: 1, 2: 2}, {0: 2, 2: 1}]
output [2, 4, 5]

####################################################
def find_mre(crh):
        nc = len(crh)   #number of columns

        nr = -1                 # find the number of rows
        for c in crh:
                nr = max(nr, max(c.keys()))
        nr += 1

        rha = [0]*nc    # accumulates the needed absolute height per col
        mre = []
        for r in xrange(nr):
                mrh = 0
                for c in xrange(nc):
                        rha[c] += crh[c].get(r,0)
                        mrh = max(mrh,rha[c])
                mre.append(mrh)

        return mre

print "Robin's Case 1: column 1 occupies 2 rows and is binding"
crh =[{0:0.5,1:0.5},{1:2}]
print 'input',crh
print 'output',find_mre(crh)

print "Robin's Case 1: column 1 occupies 2 rows"
crh =[{0:0.5,1:0.5},{1:0.9}]
print 'input',crh
print 'output',find_mre(crh)

crh = [{0:1,1:3,2:1},{0:1,2:2},{0:2,2:1}]
print 'input',crh
print 'output',find_mre(crh)
####################################################

..... original code snipped
>
>cheers,
>oliver
-- 
Robin Becker