lilypond-0.0.4
[lilypond.git] / linespace.hh
blobe5b23ca7f0504a829424cd54c1a47187695de3a3
1 #ifndef PROBLEM_HH
2 #define PROBLEM_HH
4 #include "glob.hh"
5 #include "list.hh"
6 #include "vray.hh"
7 #include "pcol.hh"
8 #include "matrix.hh"
10 /// helper struct for #Spacing_problem#
11 struct Colinfo {
12 const PCol *col;
13 bool fixed;
14 Real fixpos;
15 Colinfo();
16 void print() const;
17 Real minright()const { return col->width().max; }
18 Real minleft()const { return -col->width().min; }
22 /// spacing for one line.
23 class Spacing_problem {
24 svec<const Idealspacing*> ideals;
25 svec<Colinfo> cols;
27 /// the index of #c# in #cols#
28 int col_id(const PCol *c) const;
30 /// generate an (nonoptimal) solution
31 Vector find_initial_solution() const;
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);
38 /// make the energy function
39 void make_matrices(Matrix &quad, Vector &lin,Real&) const;
41 /// generate the LP constraints
42 void make_constraints(Mixed_qp& lp) const;
44 public:
45 /// solve the spacing problem
46 svec<Real> solve() const;
47 /**
48 return the column positions, and the energy (last element)
50 /// add a idealspacing to the problem.
51 void add_ideal(const Idealspacing *i);
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.
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.
67 bool check_constraints(Vector v) const;
69 Vector try_initial_solution() const;
70 void OK() const;
71 void print() const;
72 void print_ideal(const Idealspacing*)const;
76 /** the problem, given by the columns (which include constraints) and
77 intercolumn spacing. The problem is:
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.
92 The quality is given by the total potential energy in the
93 springs. The lower the energy, the better the configuration.
95 #endif