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"
15 #include "choleski.hh"
17 const Real TOL=1e-1; // roughly 1/30 mm
20 Active_constraints::status() const
22 String s ("Active|Inactive [");
23 for (int i=0; i< active.size(); i++) {
24 s += String (active[i]) + " ";
28 for (int i=0; i< inactive.size(); i++) {
29 s += String (inactive[i]) + " ";
37 Active_constraints::OK()
42 assert (active.size() +inactive.size () == opt->cons.size ());
43 assert (H.dim() == opt->dim ());
44 assert (active.size() == A.rows ());
47 for (int i=0; i < opt->cons.size(); i++)
49 for (int i=0; i < active.size(); i++) {
53 for (int i=0; i < inactive.size(); i++) {
57 for (int i=0; i < allcons.size(); i++)
58 assert (allcons[i] == 1);
63 Active_constraints::get_lagrange (Vector gradient)
69 Active_constraints::add (int k)
75 inactive.swap (k,inactive.size()-1);
78 Vector a (opt->cons[cidx]);
82 Vector addrow (Ha.dim());
83 if (abs (aHa) > EPS) {
85 a != 0, so if Ha = O(EPS), then
86 Ha * aH / aHa = O(EPS^2/EPS)
88 if H*a == 0, the constraints are dependent.
90 H -= Matrix (Ha/aHa , Ha);
94 sorry, don't know how to justify this. ..
98 A -= Matrix (A*a, addrow);
99 A.insert_row (addrow,A.rows());
101 WARN << "degenerate constraints";
105 Active_constraints::drop (int k)
107 int q=active.size()-1;
110 inactive.push (active[k]);
115 Vector a (A.row (q));
116 if (a.norm() > EPS) {
120 Real q = a*opt->quad*a;
123 A -= A*opt->quad*aaq;
125 WARN << "degenerate constraints";
127 Vector rem_row (A.row (q));
128 assert (rem_row.norm() < EPS);
135 Active_constraints::Active_constraints (Ineq_constrained_qp const *op)
140 for (int i=0; i < op->cons.size(); i++)
142 Choleski_decomposition chol (op->quad);
151 /** Find the optimum which is in the planes generated by the active
155 Active_constraints::find_active_optimum (Vector g)