X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fqlp.cc;h=b7f9eee739c0cd195b4fc40645174e301ccd8e56;hb=13e79c0250d34b6bdfbafbc551ef64e8b59b2991;hp=6625b68babdf7140258b8f8f851c524e5016aa89;hpb=cf393d97985570aaf254a48785ad6eaa737ee4f0;p=lilypond.git diff --git a/lily/qlp.cc b/lily/qlp.cc index 6625b68bab..b7f9eee739 100644 --- a/lily/qlp.cc +++ b/lily/qlp.cc @@ -12,67 +12,71 @@ void Mixed_qp::add_equality_cons (Vector , double) { - assert (false); + assert (false); } void Mixed_qp::add_fixed_var (int i, Real r) { - eq_cons.push (i); - eq_consrhs.push (r); + eq_cons.push (i); + eq_consrhs.push (r); } /** - eliminate appropriate variables, until we have a Ineq_constrained_qp - then solve that. + eliminate appropriate variables, until we have a Ineq_constrained_qp + then solve that. - PRE - cons should be ascending - */ + PRE + cons should be ascending + */ Vector Mixed_qp::solve (Vector start) const { - if (!dim()) + if (!dim()) return Vector (0); - - print(); - Ineq_constrained_qp pure (*this); - - for (int i= eq_cons.size()-1; i>=0; i--) { + + print(); + Ineq_constrained_qp pure (*this); + + for (int i= eq_cons.size()-1; i>=0; i--) + { pure.eliminate_var (eq_cons[i], eq_consrhs[i]); start.del (eq_cons[i]); } - Vector sol = pure.solve (start); - for (int i= 0; i < eq_cons.size(); i++) { + Vector sol = pure.solve (start); + for (int i= 0; i < eq_cons.size(); i++) + { sol.insert (eq_consrhs[i],eq_cons[i]); } - return sol; + return sol; } void Ineq_constrained_qp::assert_solution (Vector sol) const { - Array binding; - for (int i=0; i < cons.size(); i++) { + Array binding; + for (int i=0; i < cons.size(); i++) + { Real R=cons[i] * sol- consrhs[i]; assert (R> -EPS); if (R < EPS) binding.push (i); } - // KKT check... - // todo + // KKT check... + // todo } void Ineq_constrained_qp::print() const { #ifndef NPRINT - DOUT << "Quad " << quad; - DOUT << "lin " << lin <<"\n" + DOUT << "Quad " << quad; + DOUT << "lin " << lin <<"\n" << "const " << const_term<<"\n"; - for (int i=0; i < cons.size(); i++) { + for (int i=0; i < cons.size(); i++) + { DOUT << "constraint["<= " << consrhs[i]; DOUT << "\n"; } @@ -80,7 +84,7 @@ Ineq_constrained_qp::print() const } Mixed_qp::Mixed_qp (int n) - : Ineq_constrained_qp (n) + : Ineq_constrained_qp (n) { } @@ -88,8 +92,8 @@ void Mixed_qp::OK() const { #ifndef NDEBUG - Ineq_constrained_qp::OK(); - assert (eq_consrhs.size() == eq_cons.size ()); + Ineq_constrained_qp::OK(); + assert (eq_consrhs.size() == eq_cons.size ()); #endif } @@ -97,8 +101,9 @@ void Mixed_qp::print() const { #ifndef NPRINT - Ineq_constrained_qp::print(); - for (int i=0; i < eq_cons.size(); i++) { + Ineq_constrained_qp::print(); + for (int i=0; i < eq_cons.size(); i++) + { DOUT << "eq cons "<