From: fred Date: Sun, 24 Mar 2002 19:42:55 +0000 (+0000) Subject: lilypond-0.0.62 X-Git-Tag: release/1.5.59~4752 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=21100205821c7593e6ae3e53bbb9379766eb0fae;p=lilypond.git lilypond-0.0.62 --- diff --git a/lily/break.cc b/lily/break.cc index 8a07b02344..8a9a426657 100644 --- a/lily/break.cc +++ b/lily/break.cc @@ -27,6 +27,23 @@ Break_algorithm::find_breaks() const return retval; } + +Col_hpositions +Break_algorithm::stupid_solution(Line_of_cols curline)const +{ + Spacing_problem sp; + sp.add_column(curline[0], true, 0.0); + for (int i=1; i< curline.size()-1; i++) + sp.add_column(curline[i]); + sp.add_column(curline.top(), true, linelength); + Col_hpositions colhpos; + colhpos.cols = curline; + colhpos.energy = INFTY; + colhpos.ugh_b_ = true; + colhpos.config = sp.try_initial_solution(); + return colhpos; +} + /// construct an appropriate Spacing_problem and solve it. Col_hpositions Break_algorithm::solve_line(Line_of_cols curline) const @@ -42,11 +59,14 @@ Break_algorithm::solve_line(Line_of_cols curline) const for (iter_top(pscore_.suz,i); i.ok(); i++) { sp.add_ideal(i); } + sp.prepare(); + Array the_sol=sp.solve(); Col_hpositions col_hpos; col_hpos.cols = curline; col_hpos.energy = the_sol.pop(); col_hpos.config = the_sol; + col_hpos.error_col_l_arr_ = sp.error_pcol_l_arr(); col_hpos.OK(); return col_hpos; } diff --git a/lily/linespace.cc b/lily/linespace.cc index aed6c407eb..c2fec09918 100644 --- a/lily/linespace.cc +++ b/lily/linespace.cc @@ -5,15 +5,16 @@ #include "qlp.hh" #include "unionfind.hh" #include "idealspacing.hh" +#include "pointer.tcc" const Real COLFUDGE=1e-3; - +template class P; // ugh. bool Spacing_problem::contains(PCol const *w) { for (int i=0; i< cols.size(); i++) - if (cols[i].pcol_ == w) + if (cols[i].pcol_l_ == w) return true; return false; } @@ -22,7 +23,7 @@ int Spacing_problem::col_id(PCol const *w)const { for (int i=0; i< cols.size(); i++) - if (cols[i].pcol_ == w) + if (cols[i].pcol_l_ == w) return i; assert(false); return -1; @@ -32,6 +33,19 @@ void Spacing_problem::OK() const { #ifndef NDEBUG + for (int i = 1; i < cols.size(); i++) + assert(cols[i].rank_i_ > cols[i-1].rank_i_); + for (int i = 1; i < loose_col_arr_.size(); i++) + assert(loose_col_arr_[i].rank_i_ > loose_col_arr_[i-1].rank_i_); +#endif +} + +/** + Make sure no unconnected columns happen. + */ +void +Spacing_problem::handle_loose_cols() +{ Union_find connected(cols.size()); Array fixed; for (int i=0; i < ideals.size(); i++) { @@ -43,23 +57,73 @@ Spacing_problem::OK() const for (int i = 0; i < cols.size(); i++) if (cols[i].fixed()) fixed.push(i); - for (int i = 0; i < cols.size(); i++) { - bool c=false; - for (int j =0; j fix_b_arr; + fix_b_arr.set_size(cols.size() + loose_col_arr_.size()); + Real utter_right_f=-INFTY; + Real utter_left_f =INFTY; + for (int i=0; i < loose_col_arr_.size(); i++) { + fix_b_arr[loose_col_arr_[i].rank_i_] = false; + } + for (int i=0; i < cols.size(); i++) { + int r= cols[i].rank_i_; + fix_b_arr[r] = true; + utter_right_f = utter_right_f >? sol_vec(i); + utter_left_f = utter_left_f 0) ?sol_vec(j-1) : utter_left_f; + Real right_pos_f = + (j < sol_vec.dim()) ? sol_vec(j) : utter_right_f; + int left_rank = (j>0) ? cols[j-1].rank_i_ : 0; + int right_rank = (j left_rank && r < right_rank); + + v(i) = (r - left_rank)*left_pos_f/ d_r + + (right_rank - r) *right_pos_f /d_r; + } + } + sol_vec = v; +} + bool Spacing_problem::check_constraints(Vector v) const { int dim=v.dim(); + assert(dim == cols.size()); + for (int i=0; i < dim; i++) { if (cols[i].fixed()&& @@ -84,6 +148,12 @@ Spacing_problem::check_constraints(Vector v) const return true; } +void +Spacing_problem::prepare() +{ + handle_loose_cols(); +} + bool Spacing_problem::check_feasible() const { @@ -91,7 +161,7 @@ Spacing_problem::check_feasible() const return check_constraints(sol); } -// generate a solution which obeys the min distances and fixed positions +/// generate a solution which obeys the min distances and fixed positions Vector Spacing_problem::try_initial_solution() const { @@ -99,21 +169,30 @@ Spacing_problem::try_initial_solution() const Vector initsol(dim); for (int i=0; i < dim; i++) { if (cols[i].fixed()) { - initsol(i)=cols[i].fixed_position(); + initsol(i)=cols[i].fixed_position(); + + if (i > 0) { + Real r =initsol(i-1) + cols[i-1].minright(); + if (initsol(i) < r ) { + warning("overriding fixed position"); + initsol(i) =r; + } + } + } else { Real mindist=cols[i-1].minright() +cols[i].minleft(); - assert(mindist >= 0.0); + if (mindist < 0.0) + warning("Excentric column"); initsol(i)=initsol(i-1)+mindist; - - //nog niet - //if (i>0) - // assert(initsol(i) > initsol(i-1)); } } return initsol; } + + + Vector Spacing_problem::find_initial_solution() const { @@ -170,9 +249,8 @@ Spacing_problem::make_constraints(Mixed_qp& lp) const Array Spacing_problem::solve() const { - print(); - OK(); assert(check_feasible()); + print(); Mixed_qp lp(cols.size()); make_matrices(lp.quad,lp.lin, lp.const_term); @@ -182,10 +260,12 @@ Spacing_problem::solve() const if (!check_constraints(sol)) { WARN << "solution doesn't satisfy constraints.\n" ; } - + Real energy_f =lp.eval(sol); + position_loose_cols(sol); Array posns(sol); - posns.push(lp.eval(sol)); + + posns.push(energy_f); return posns; } @@ -193,12 +273,50 @@ Spacing_problem::solve() const add one column to the problem. */ void -Spacing_problem::add_column(PCol const *col, bool fixed, Real fixpos) +Spacing_problem::add_column(PCol *col, bool fixed, Real fixpos) { Colinfo c(col,(fixed)? &fixpos : 0); + if (cols.size()) + c.rank_i_ = cols.top().rank_i_+1; + else + c.rank_i_ = 0; cols.push(c); } +Array +Spacing_problem::error_pcol_l_arr()const +{ + Array retval; + for (int i=0; i< cols.size(); i++) + if (cols[i].ugh_b_) + retval.push(cols[i].pcol_l_); + for (int i=0; i < loose_col_arr_.size(); i++) { + retval.push(loose_col_arr_[i].pcol_l_); + } + return retval; +} + +void +Spacing_problem::loosen_column(int i) +{ + Colinfo c=cols.get(i); + for (int i=0; i < ideals.size(); ) { + Idealspacing const *i_l =ideals[i]; + if (i_l->left == c.pcol_l_ || i_l->right == c.pcol_l_) + ideals.del(i); + else + i++; + } + c.ugh_b_ = true; + + int i=0; + for (; i < loose_col_arr_.size(); i++) { + if (loose_col_arr_[i].rank_i_ > c.rank_i_) + break; + } + loose_col_arr_.insert(c,i); +} + void Spacing_problem::add_ideal(Idealspacing const *i) { @@ -247,41 +365,24 @@ Colinfo::print() const mtor << "column { "; if (fixed()) mtor << "fixed at " << fixed_position()<<", "; - assert(pcol_); + assert(pcol_l_); mtor << "[" << minleft() << ", " << minright() << "]"; mtor <<"}\n"; #endif } -Colinfo::Colinfo(Colinfo const&c) +Colinfo::Colinfo(PCol *col_l, Real const *fixed_C) { - fixpos = (c.fixpos)?new Real(*c.fixpos):0; - pcol_ = c.pcol_; - width = c.width; + if (fixed_C) + fixpos_p_.set_l(fixed_C); + ugh_b_ = false; + pcol_l_ = col_l; + width = pcol_l_->width(); } -Colinfo::Colinfo(PCol const *col_p, Real const *fixed_r_p ) -{ - fixpos = (fixed_r_p)? new Real(*fixed_r_p) : 0; - pcol_ = col_p; - width = pcol_->width(); -} - -Colinfo::~Colinfo() -{ - delete fixpos; -} Colinfo::Colinfo() { - pcol_=0; - fixpos = 0; -} -void -Colinfo::operator=(Colinfo const&c ) -{ - delete fixpos; - fixpos = (c.fixpos)?new Real(*c.fixpos):0; - pcol_ = c.pcol_; - width = c.width; + ugh_b_ = false; + pcol_l_ =0; }