From: fred Date: Sun, 24 Mar 2002 19:49:49 +0000 (+0000) Subject: lilypond-0.0.78 X-Git-Tag: release/1.5.59~4351 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3bd861f1c84ed515113bd99184b53ff969677c9b;p=lilypond.git lilypond-0.0.78 --- diff --git a/lily/include/ineq-constrained-qp.hh b/lily/include/ineq-constrained-qp.hh new file mode 100644 index 0000000000..161bc51f46 --- /dev/null +++ b/lily/include/ineq-constrained-qp.hh @@ -0,0 +1,72 @@ +/* + ineq-constrained-qp.hh -- declare Ineq_constrained_qp + + source file of the GNU LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + + +#ifndef INEQ_CONSTRAINED_QP_HH +#define INEQ_CONSTRAINED_QP_HH + + + +#include "matrix.hh" + +/// inequality constrained quadratic program +class Ineq_constrained_qp { + friend class Active_constraints; + + Array cons; + Array consrhs; +public: + Matrix quad; + Vector lin; + Real const_term; + + + /** + use a KKT method to assert optimality of sol + */ + void assert_solution(Vector sol) const; + /// solve the problem using a projected gradient method + Vector solve(Vector start) const; + + /** + @return the number of variables in the problem + */ + int dim() const{ + return lin.dim(); + } + + /** + add a constraint + + + c*vars >= r + + PRE + c.dim() == dim(); + + */ + void add_inequality_cons(Vector c, double r); + + /** set up matrices to go with the problem. */ + Ineq_constrained_qp(int novars); + + /** + evaluate the quadratic function for input #v# + */ + Real eval(Vector v); + + void eliminate_var(int idx, Real value); + void OK()const; + void print() const; + +}; + +// ugh +const Real EPS=1e-7; + +#endif // INEQ_CONSTRAINED_QP_HH diff --git a/lily/include/qlpsolve.hh b/lily/include/qlpsolve.hh index c7a54b1eca..56b84e2e16 100644 --- a/lily/include/qlpsolve.hh +++ b/lily/include/qlpsolve.hh @@ -9,7 +9,7 @@ #ifndef QLPSOLVE_HH #define QLPSOLVE_HH -#include "qlp.hh" + #include "matrix.hh" diff --git a/lily/qlp.cc b/lily/qlp.cc index 7eac50596c..833a76f4e4 100644 --- a/lily/qlp.cc +++ b/lily/qlp.cc @@ -1,8 +1,17 @@ +/* + qlp.cc -- implement Mixed_qp + + source file of the GNU LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + #include "debug.hh" #include "const.hh" #include "qlp.hh" #include "choleski.hh" + void Mixed_qp::add_equality_cons(Vector , double ) { @@ -16,36 +25,6 @@ Mixed_qp::add_fixed_var(int i, Real r) eq_consrhs.push(r); } -void -Ineq_constrained_qp::add_inequality_cons(Vector c, double r) -{ - cons.push(c); - consrhs.push(r); -} - -Ineq_constrained_qp::Ineq_constrained_qp(int novars): - quad(novars), - lin(novars), - const_term (0.0) -{ -} - -void -Ineq_constrained_qp::OK() const -{ -#ifndef NDEBUG - assert(cons.size() == consrhs.size()); - Matrix Qdif= quad - quad.transposed(); - assert(Qdif.norm()/quad.norm() < EPS); -#endif -} - - -Real -Ineq_constrained_qp::eval (Vector v) -{ - return v * quad * v + lin * v + const_term; -} /** eliminate appropriate variables, until we have a Ineq_constrained_qp @@ -74,32 +53,6 @@ Mixed_qp::solve(Vector start) const return sol; } -/* - assume x(idx) == value, and adjust constraints, lin and quad accordingly - - TODO: add const_term - */ -void -Ineq_constrained_qp::eliminate_var(int idx, Real value) -{ - Vector row(quad.row(idx)); - row*= value; - - quad.delete_row(idx); - - quad.delete_column(idx); - - lin.del(idx); - row.del(idx); - lin +=row ; - - for (int i=0; i < cons.size(); i++) { - consrhs[i] -= cons[i](idx) *value; - cons[i].del(idx); - } -} - - void Ineq_constrained_qp::assert_solution(Vector sol) const @@ -129,8 +82,6 @@ Ineq_constrained_qp::print() const #endif } -/* *************** */ - Mixed_qp::Mixed_qp(int n) : Ineq_constrained_qp(n) {