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