A linear constraint solver is employed to determine the table geometry from the table topology, the content of table entries, and explicit auxiliary constraints supplied by the table creator. The grid data structure represents the topology of all the table entries and contains pointers to their content. The layout algorithm enumerates all of the table entries and generates appropriate constraints on their positions. Additional constraints may be supplied with the table to impose special conditions such as forcing columns of equal width. Solving the resulting system of linear inequalities produces the computed positions of all the grid lines and table entries.
5.5.3 The Constraint Table Layout Problem
The table layout algorithm introduced in Section 5.4.4 depends on a linear inequality constraint solver to compute the positions of the grid and table entries. This section discusses the linear inequalities actually used to describe the table arrangement.
Consider a particular table entry represented as a box k. This table entry is positioned within a pair of horizontal grid lines and a pair of vertical grid lines as shown in Figure 5-17. The alignment point of the box is to be aligned with other boxes that share the same pair of grid lines. Label the four grid lines surrounding the box as leftGridk, rightGridk, topGridk, bottomGridk. Label the offsets from the alignment point to the edge of the box as distances leftOffsetk, rightOffsetk, topOffsetk and bottomOffsetk (these offsets are fixed by the content and can be determined before table layout). The position of the alignment point within box k will be (Xk, Yk).
The vertical grid lines represent column boundaries and their positions are designated by the variables Ci. The horizontal grid lines represent row boundaries and their positions are designated by the variables Rj. Boxes within the pair of grid lines left and right that are vertically aligned will be positioned at the variable Vleft,right, while boxes horizontally aligned within the row between grid lines top and bottom will be positioned at Htop,bottom. All variables are restricted to positive values.
====================
///Beach/Thesis/Figure5-17-BoxConstraints.Press
leftMargin: 92 pt, topMargin: 136 pt, width: 338 pt, height: 112 pt
Figure 5-17. CONSTRAINT VARIABLES FOR A PARTICULAR TABLE ENTRY are shown in this diagram. The box representing the table entry is in dark grey and the grid module formed by two pairs of grid lines is shown in light grey, the column lines Cleft and Cright and the row lines Rtop and Rbottom. The alignment point of the table entry box goes through the two alignment lines, Vleft,right and Htop,bottom.
====================
The objective function for the constraint solver will be to minimize the width and depth of the table. For a table with m rows and n columns, the objective function would be
Min {(Cn — C0) + (Rm — R0)} .
The table layout the relationships among grid lines and alignment points can be described by inequality constraints. The first set of constraints (1) ensure that all of the grid lines are in the expected order and that the alignment line is within the column. One set of constraints is required for each pair of grid lines, left and right, that contain a table entry. (Column constraints are used in the examples that follow; row constraints are similar.)
Cright — Cleft e 0
Vleft,right — Cleft e 0
(1)
Cright — Vleft,right e 0 .
A constraint to ensure that the grid lines are sufficiently far apart to contain the width of a table entry is generated for each table box k:
CrightGridk — CleftGridk e leftOffsetk + rightOffsetk .
(2)
In practice, these two sets of constraints are not generated explicitly since they are subsumed by the alignment constraints below.
The alignment constraints vary with the type of alignment requested. Aligning a table box flush left in the column without regard to any other box in
the column generates these two constraints to position the box immediately adjacent to the column grid:
Xk — CleftGridk = leftOffsetk
(3L)
CrightGridk — Xk e rightOffsetk .
Similarly, aligning a table box flush right in the column without regard to any other box switches the equality and inequality constraints from those in (3L):
Xk — CleftGridk e leftOffsetk
(3R)
CrightGridk — Xk = rightOffsetk .
Centering a table box within the column may involve one of two centering concepts. The first forces the box alignment point to be equidistant between the column grid lines:
2ýXk — CleftGridk — CrightGridk = 0 .
(3C)
The second centering concept positions the box to balance the excess whitespace surrounding the box. The excess whitespace is the width of the column (CrightGridk — CleftGridk) less the width of the box (leftOffsetk + rightOffsetk):
Xk — leftOffsetk — CleftGridk =
1/2ý[(CrightGridk — CleftGridk) — (leftOffsetk + rightOffsetk)]
which can be simplified to the form:
2ýXk — CleftGridk — CrightGridk = leftOffsetk — rightOffsetk .
(3C`)
The two centering constraints (3C) and (3C`) are equivalent only if the two offsets are equal, which is when the alignment point is in the center of the box.
Note that up until now none of these alignment constraints involved aligning a set of boxes with each other, only positioning the box within the column. To align several boxes, we need to force the alignment point within a box to be equal to the position of the alignment line within that column. Thus, for each box k in the set, generate an equality constraint:
Xk — VleftGridk,rightGridk = 0
(4)
In fact, if the variable Xk does not appear in any other constraint, then it may be dispensed with and treated as an alias.
The positioning constraints for each box aligned within a set are simpler because they only require that the box fit within the column:
VleftGridk,rightGridk — CleftGridk e leftOffsetk
(5)
CrightGridk — VleftGridk,rightGridk e rightOffsetk .
However, these constraints are not sufficient to force the set of boxes to be flush left, flush right, or centered within the column. This must be accomplished by guiding the constraint solver to a particular desired solution. For example, to force the set of aligned boxes flush left, the objective function to be minimized by the constraint solver must be augmented with a term for the left distance:
Min {(VleftGridk,rightGridk — CleftGridk)} .
(6)
A similar term is necessary to force the set of aligned boxes flush right.
Centering the alignment line for a set of boxes within a column may be accomplished in two ways. The first simply positions the alignment line equidistant between the column grid lines and does not involve an additional term in the objective function:
2ýVleftGridk,rightGridk — CleftGridk — CrightGridk = 0 .
(7)
The second centering technique is to balance the whitespace between the set of aligned boxes and the grid lines. The objective function requires a new variable equal to the maximum whitespace in the column. This was not done in the prototype but is considered later in section 5.5.4 when such `maximum' variables are introduced to handle large tables.
These linear constraints can be generated automatically for a table from the information kept in the grid data structure. A small expression language for constraint inequalities is provided in the prototype for the table designer to describe additional constraints for special effects. For instance, to create two columns of equal-width, say the column between grid lines left and right and the column between left` and right`, the following equality constraint is added to the table specification:
(Cleft` — Cright`) — (Cleft — Cright) = 0 .
(8)
The expression language accepts a standard form of the variable names. Two such constraints were included in the external representation shown in Figure 5-13. A variety of user interfaces to this constraint expression facility are possible. Only the simplest textual interface of typing the constraint equations is supported in the prototype.
====================
H4,5 — R4 e 6.225697
(flush left box 4,0)
R4 — H4,5 e 15.25376
H3,4 — R4 e 6.225697
(flush left box 3,0)
R3 — H3,4 e 14.97279
H4,5 — R5 e 6.0
(flush left box 4,4)
R4 — H4,5 e 12.22937
H4,5 — R5 e 6.0
(flush left box 4,3)
R4 — H4,5 e 12.22937
H4,5 — R5 e 6.0
(flush left box 4,2)
R4 — H4,5 e 12.22937
H4,5 — R5 e 6.0
(flush left box 4,1)
R4 — H4,5 e 12.22937
H3,4 — R4 e 6.0
(flush left box 3,4)
R3 — H3,4 e 12.22937
H3,4 — R4 e 6.0
(flush left box 3,3)
R3 — H3,4 e 12.22937
H3,4 — R4 e 6.0
(flush left box 3,2)
R3 — H3,4 e 12.22937
H3,4 — R4 e 6.0
(flush left box 3,1)
R3 — H3,4 e 12.22937
H2,3 — R3 e 6.0
(flush left box 2,4)
R2 — H2,3 e 15.25376
H2,3 — R3 e 8.257013
(flush left box 2,3)
R2 — H2,3 e 15.25376
H2,3 — R3 e 6.0
(flush left box 2,2)
R2 — H2,3 e 15.25376
H2,3 — R3 e 8.257013
(flush left box 2,1)
R2 — H2,3 e 15.25376
H1,2 — R2 e 8.482721
(flush left box 1,3)
R1 — H1,2 e 15.25376
H1,2 — R2 e 8.482721
(flush left box 1,1)
R1 — H1,2 e 15.25376
H0,1 — R1 e 8.482721
(flush left box 0,1)
R0 — H0,1 e 15.25376
Figure 5-18. THE ROW CONSTRAINTS GENERATED for the table in Figure 5-6. The variables for the row grid line positions are R0, R1, R2, R3, R4, R5 and the horizontal alignment line positions are H0,1, H1,2, H2,3, H3,4, H4,5.
====================
====================
2.0ýC1 — C0 — C3 = 0
2.0ýC2 — C1 — C3 = 0
C0 — V0,1 e 3.0
(flush left box 4,0)
C1 — V0,1 e 69.31976
C0 — V0,1 e 3.0
(flush left box 3,0)
C1 — V0,1 e 55.72097
C5 — C4 e 24.0675
(center box 4,4)
2.0ýV4,5 — C4 — C5 = 0
C4 — C3 e 60.2025
(center box 4,3)
2.0ýV3,4 — C3 — C4 = 0
C3 — C2 e 24.0675
(center box 4,2)
2.0ýV2,3 — C2 — C3 = 0
C2 — C1 e 60.2025
(center box 4,1)
2.0ýV1,2 — C1 — C2 = 0
C5 — C4 e 24.0675
(center box 3,4)
2.0ýV4,5 — C4 — C5 = 0
C4 — C3 e 60.2025
(center box 3,3)
2.0ýV3,4 — C3 — C4 = 0
C3 — C2 e 24.0675
(center box 3,2)
2.0ýV2,3 — C2 — C3 = 0
C2 — C1 e 60.2025
(center box 3,1)
2.0ýV1,2 — C1 — C2 = 0
C5 — C4 e 30.86088
(center box 2,4)
2.0ýV4,5 — C4 — C5 = 0
C4 — C3 e 63.23784
(center box 2,3)
2.0ýV3,4 — C3 — C4 = 0
C3 — C2 e 30.86088
(center box 2,2)
2.0ýV2,3 — C2 — C3 = 0
C2 — C1 e 63.23784
(center box 2,1)
2.0ýV1,2 — C1 — C2 = 0
C5 — C3 e 88.15895
(center box 1,3)
2.0ýV3,5 — C3 — C5 = 0
C3 — C1 e 73.83745
(center box 1,1)
2.0ýV1,3 — C1 — C3 = 0
C5 — C1 e 159.6822
(center box 0,1)
2.0ýV1,5 — C1 — C5 = 0
Figure 5-18 (continued). THE COLUMN CONSTRAINTS GENERATED for the table in Figure 5-6. The first two constraints are the auxiliary constraints to force the equal column widths; the rest are generated by the table layout algorithm. The variables for the column grid line positions are C0, C1, C2, C3, C4, C5 and the vertical alignment line positions are V0,1, V1,2, V1,3, V1,5, V2,3, V3,4, V3,5, V4,5.
====================
5.5.4 Handling Large Tables
The constraint scheme just outlined suffers from rapid growth in the problem size as the tables grow larger. Several strategies can greatly reduce the number of constraints generated.
The first strategy eliminates redundant variables whenever they appear as aliases of other variables. For example, the box position Xk is often an alias for VleftGridk,rightGridk when they are set equal and therefore Xk can be eliminated.
In many table layouts, a simplifying assumption may be made to solve the row and column constraints separately. Treating the two sets of constraints independently reduces the number of constraints and the size of the corresponding constraint tableau. It is worth assessing the necessity of this assumption and the situations in which it is violated.
The independence assumption does not hold when one wants to create grid designs with modules that are square or have specific aspect ratios. A square module results from constraining the row height to equal the column width. Obviously, in this situation the sets of row and column constraints are not independent. The assumption is also not true when trying to distribute whitespace within a table, for example, by folding wide horizontally-oriented table entries to trade off more vertical depth for less horizontal width. In this situation, decreasing the column width increases the row height and the constraints are again not independent.
The independence assumption can be tested automatically by examining the variables in each constraint. Constraints that mix row and column variables, such as one specifying that a row height equals a column width, are interdependent and must be solved simultaneously. Constraints that do not mix variables are independent and can be solved separately as smaller problems. The prototype currently assumes that the row and column constraints are independent, but one could easily check the explicitly supplied constraints for violations of this assumption and thus determine automatically whether to solve the table layout constraints independently or not.
What is the cost of solving interdependent row and column constraints? When the two sets are combined into a single constraint system the problem size is doubled. Since the constraint solver takes O(n3) time on average, the combined constraint layout would require about four times as much as the sum of the two smaller independent computations.
A reduction in the number of constraints can also be achieved by observing the structure of the constraint inequalities. The constraints that determine the grid positions surrounding a particular table entry are all similar:
VleftGridk,rightGridk — CleftGridk e leftOffsetk
(5)
CrightGridk — VleftGridk,rightGridk e rightOffsetk .
For the set of table entries within a particular column, these inequalities are dominated by a single maximum value of the right hand side. The maximum value could be determined by simpler means than expressing so many redundant constraints. We can discover the value by a linear preprocessing pass through all the table entries in that particular column to determine the maximum left and right offsets. The two maximum values are assigned to new variables used by the constraint solver:
maxLeftleft,right = max{leftOffsetk for all boxes k in column left,right}
maxRightleft,right = max{rightOffsetk for all boxes k in column left,right} .
With these maximum values known by these variable names, the set of inequalities per column (one or more constraint for each table entry) can be replaced by one inequality per column. This vastly reduces the number of constraints from the product of the number of entries per column times the number of columns to simply the number of columns:
Vleft,right — Cleft e maxLeftleft,right
(5`)
Cright — Vleft,right e maxRightleft,right .
A further optimization in the linear constraint solver can be made based on the observation that most of the constraint inequalities have only two variable terms. Thus, sparse matrix techniques might reduce the space requirements of the solver at the expense of more overhead in the constraint solver. The prototype implementation uses a conventional matrix structure for the constraint tableau.