lilypond-1.3.67
[lilypond.git] / lily / mixed-qp.cc
blob25946d444ff1713af55aeac690ebdc8136a39433
1 /*
2 qlp.cc -- implement Mixed_qp
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "debug.hh"
10 #include "qlp.hh"
13 void
14 Mixed_qp::add_equality_cons (Vector , double)
16 assert (false);
19 void
20 Mixed_qp::add_fixed_var (int i, Real r)
22 eq_cons.push (i);
23 eq_consrhs.push (r);
27 /**
28 eliminate appropriate variables, until we have a Ineq_constrained_qp
29 then solve that.
31 PRE
32 cons should be ascending
34 Vector
35 Mixed_qp::solve (Vector start) const
37 if (!dim())
38 return Vector (0);
40 print();
41 Ineq_constrained_qp pure (*this);
43 for (int i= eq_cons.size()-1; i>=0; i--)
45 pure.eliminate_var (eq_cons[i], eq_consrhs[i]);
46 start.del (eq_cons[i]);
48 Vector sol = pure.solve (start);
49 for (int i= 0; i < eq_cons.size(); i++)
51 sol.insert (eq_consrhs[i],eq_cons[i]);
53 return sol;
57 Mixed_qp::Mixed_qp (int n)
58 : Ineq_constrained_qp (n)
62 void
63 Mixed_qp::OK() const
65 #ifndef NDEBUG
66 Ineq_constrained_qp::OK();
67 assert (eq_consrhs.size() == eq_cons.size ());
68 #endif
71 void
72 Mixed_qp::print() const
74 #ifndef NPRINT
75 Ineq_constrained_qp::print();
76 for (int i=0; i < eq_cons.size(); i++)
78 DOUT << "eq cons "<<i<<": x["<<eq_cons[i]<<"] == " << eq_consrhs[i]<< '\n';
80 #endif