10 /// helper struct for #Spacing_problem#
20 Real
minright()const { return col
->width().max
; }
21 Real
minleft()const { return -col
->width().min
; }
25 /// spacing for one line.
26 class Spacing_problem
{
27 svec
<const Idealspacing
*> ideals
;
30 /// the index of #c# in #cols#
31 int col_id(const PCol
*c
) const;
33 /// generate an (nonoptimal) solution
34 Vector
find_initial_solution() const;
36 /// check if problem is too tight
37 bool check_feasible() const;
38 /// does #this# contain the column #w#?
39 bool contains(const PCol
*w
);
41 /// make the energy function
42 void make_matrices(Matrix
&quad
, Vector
&lin
,Real
&) const;
44 /// generate the LP constraints
45 void make_constraints(Optimisation_problem
& lp
) const;
48 /// solve the spacing problem
49 svec
<Real
> solve() const;
51 return the column positions, and the energy (last element)
53 /// add a idealspacing to the problem.
54 void add_ideal(const Idealspacing
*i
);
57 One pair of columns can have no, one or more idealspacings,
58 since they can be "summed" if the columns to which #i# refers are
59 not in this problem, the spacing is ignored.
63 /// add a col to the problem
64 void add_column(const PCol
*, bool fixed
=false, Real fixpos
=0.0);
65 /** columns have to be added left to right. The column contains
66 info on it's minimum width.
70 bool check_constraints(Vector v
) const;
72 Vector
try_initial_solution() const;
75 void print_ideal(const Idealspacing
*)const;
79 /** the problem, given by the columns (which include constraints) and
80 intercolumn spacing. The problem is:
82 Generate a spacing which
85 Satisfies spacing constraints (notes can't be printed through each other)
87 Looks good, ie tries to conform to an ideal spacing as much as possible.
89 This is converted by regarding idealspacing as "springs" attached
90 to columns. The equilibrium of one spring is the ideal
91 distance. The columns have a size, this imposes "hard" constraints
92 on the distances. This transforms the problem into a quadratic
93 programming problem with linear constraints.
95 The quality is given by the total potential energy in the
96 springs. The lower the energy, the better the configuration.