]> git.donarmstrong.com Git - lilypond.git/blob - hdr/linespace.hh
release: 0.0.20
[lilypond.git] / hdr / linespace.hh
1 #ifndef PROBLEM_HH
2 #define PROBLEM_HH
3
4 #include "glob.hh"
5 #include "plist.hh"
6 #include "vray.hh"
7 #include "pcol.hh"
8 #include "matrix.hh"
9
10 /// helper struct for #Spacing_problem#
11 struct Colinfo {
12     const PCol *pcol_;
13     bool fixed;
14     Real fixpos;
15     Colinfo();
16     void print() const;
17     Real minright() const { return pcol_->width().right; }
18     Real minleft() const { return -pcol_->width().left; }
19 };
20
21
22 /// spacing for one line.
23 class Spacing_problem {
24     svec<const Idealspacing*> ideals;
25     svec<Colinfo> cols;
26
27     /// the index of #c# in #cols#
28     int col_id(const PCol *c) const;
29
30     /// generate an (nonoptimal) solution
31     Vector find_initial_solution() const;
32
33     /// check if problem is too tight
34     bool check_feasible() const;
35     /// does #this# contain the column #w#? 
36     bool contains(const PCol *w);
37
38     /// make the energy function
39     void make_matrices(Matrix &quad, Vector &lin,Real&) const;
40
41     /// generate the LP constraints
42     void make_constraints(Mixed_qp& lp) const;
43
44 public:
45     /// solve the spacing problem
46     svec<Real> solve() const;
47     /**
48     return the column positions, and the energy (last element)
49     */
50     /// add a idealspacing to the problem.
51     void add_ideal(const Idealspacing *i);
52     
53     /**
54     One pair of columns can have no, one or more idealspacings,
55     since they can be "summed" if the columns to which #i# refers are
56     not in this problem, the spacing is ignored.
57     */
58     
59     
60     /// add a col to the problem
61     void add_column(const PCol *, bool fixed=false, Real fixpos=0.0);
62     /** columns have to be added left to right. The column contains
63       info on it's minimum width.
64     */
65
66
67     bool check_constraints(Vector v) const;
68
69     Vector try_initial_solution() const;
70     void OK() const;
71     void print() const;
72     void print_ideal(const Idealspacing*)const;
73 };
74
75
76 /** the problem, given by the columns (which include constraints) and
77     intercolumn spacing. The problem is:
78
79     Generate a spacing which
80     \begin{itemize}
81     \item
82     Satisfies spacing constraints (notes can't be printed through each other)
83     \item
84     Looks good, ie tries to conform to  an ideal spacing as much as possible.
85     \end{itemize}
86     This is converted by regarding idealspacing as "springs" attached
87     to columns. The equilibrium of one spring is the ideal
88     distance. The columns have a size, this imposes "hard" constraints
89     on the distances. This transforms the problem into a quadratic
90     programming problem with linear constraints.
91
92     The quality is given by the total potential energy in the
93     springs. The lower the energy, the better the configuration.
94 */
95 #endif