2 spring-spacer.hh -- declare Spring_spacer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #ifndef SPRING_SPACER_HH
11 #define SPRING_SPACER_HH
13 #include "line-spacer.hh"
15 #include "col-info.hh"
22 Determine positions of columns connected by springs and held apart by rods.
25 Generate a spacing which
28 Satisfies spacing constraints (notes can't be printed through each other)
30 Looks good, ie tries to conform to an ideal spacing as much as possible.
33 This is converted by regarding idealspacing as "springs" attached
34 to columns. The equilibrium of one spring is the ideal
35 distance. The columns have a size, this imposes "hard" constraints
36 on the distances. This transforms the problem into a quadratic
37 programming problem with linear constraints.
39 The quality is given by the total potential energy in the
40 springs. The lower the energy, the better the configuration.
43 TODO: too complicated. Revise.
44 Use force iso. energy. Also optimise for uniform density
47 class Spring_spacer : public Line_spacer {
48 friend class Durations_iter;
50 Cons<Idealspacing> *ideal_p_list_;
51 Array<Column_info> cols_;
52 Array<Column_info> loose_col_arr_;
55 /// mark column #i# as being loose.
56 void loosen_column (int i);
57 /// the index of #c# in #cols#
58 int col_id (Paper_column const *c) const;
60 /// generate an (nonoptimal) solution
61 Vector find_initial_solution() const;
63 /// does #this# contain the column #w#?
64 bool contains_b (Paper_column const *w);
66 /// make the energy function
67 void make_matrices (Matrix &quad, Vector &lin,Real&) const;
70 /// generate the LP constraints
71 void make_constraints (Mixed_qp& lp) const;
74 void handle_loose_cols();
75 void position_loose_cols (Vector &) const;
76 bool try_initial_solution_and_tell (Vector&)const;
77 Vector try_initial_solution() const;
79 void set_fixed_cols (Mixed_qp&) const;
81 Score_column* scol_l (int);
82 void connect (int i,int j, Real,Real);
83 Line_of_cols error_pcol_l_arr() const;
84 Real calculate_energy_f (Vector) const;
86 static Line_spacer *constructor();
87 Real energy_normalisation_f_;
89 virtual void solve (Column_x_positions*) const;
90 virtual void lower_bound_solution (Column_x_positions*) const;
91 virtual void add_column (Paper_column *, bool fixed=false, Real fixpos=0.0);
93 virtual Vector default_solution() const;
94 virtual bool check_constraints (Vector v) const;
95 virtual void OK() const;
96 virtual void print() const;
97 virtual void prepare();
98 virtual ~Spring_spacer(){}
101 #endif // SPRING_SPACER_HH