2 qlpsolve.cc -- implement Active_constraints, Inactive_iter
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 try fixed point arithmetic, to speed up lily.
12 #include "ineq-constrained-qp.hh"
13 #include "qlpsolve.hh"
16 #include "choleski.hh"
18 const Real TOL=1e-2; // roughly 1/10 mm
21 Active_constraints::status() const
23 String s("Active|Inactive [");
24 for (int i=0; i< active.size(); i++) {
25 s += String(active[i]) + " ";
29 for (int i=0; i< inactive.size(); i++) {
30 s += String(inactive[i]) + " ";
38 Active_constraints::OK()
43 assert(active.size() +inactive.size() == opt->cons.size());
44 assert(H.dim() == opt->dim());
45 assert(active.size() == A.rows());
48 for (int i=0; i < opt->cons.size(); i++)
50 for (int i=0; i < active.size(); i++) {
54 for (int i=0; i < inactive.size(); i++) {
58 for (int i=0; i < allcons.size(); i++)
59 assert(allcons[i] == 1);
64 Active_constraints::get_lagrange(Vector gradient)
72 Active_constraints::add(int k)
78 inactive.swap(k,inactive.size()-1);
81 Vector a( opt->cons[cidx] );
85 Vector addrow(Ha.dim());
88 a != 0, so if Ha = O(EPS), then
89 Ha * aH / aHa = O(EPS^2/EPS)
91 if H*a == 0, the constraints are dependent.
93 H -= Matrix(Ha/aHa , Ha);
97 sorry, don't know how to justify this. ..
101 A -= Matrix(A*a, addrow);
102 A.insert_row(addrow,A.rows());
104 WARN << "degenerate constraints";
108 Active_constraints::drop(int k)
110 int q=active.size()-1;
113 inactive.push(active[k]);
119 if (a.norm() > EPS) {
123 Real q = a*opt->quad*a;
125 A -= A*opt->quad*Matrix(a,a/q);
127 WARN << "degenerate constraints";
129 Vector rem_row(A.row(q));
130 assert(rem_row.norm() < EPS);
137 Active_constraints::Active_constraints(Ineq_constrained_qp const *op)
142 for (int i=0; i < op->cons.size(); i++)
144 Choleski_decomposition chol(op->quad);
149 /** Find the optimum which is in the planes generated by the active
153 Active_constraints::find_active_optimum(Vector g)