lilypond-0.0.3
[lilypond.git] / qlpsolve.hh
blob4d29bcc4a0cf6c566e2888cdae75f2f08d8c9ec3
1 #include "qlp.hh"
2 #include "matrix.hh"
5 class Active_constraints {
6 friend class Inactive_iter;
9 Matrix A,H;
10 svec<int> active;
11 svec<int> inactive; // actually this is a set, not an array.
12 const Ineq_constrained_qp *opt;
14 public:
15 String status()const;
17 Vector vec(int k) const { return opt->cons[k]; }
18 Real rhs(int k) const { return opt->consrhs[k]; }
20 /// drop constraint
21 void drop (int k);
22 /** drop constraint k from the active set. k is the index of the
23 constraint in #active#
27 /// add constraint j
28 void add(int j);
29 /**
30 add constraint j to the active set j is the index of the
31 constraint in #inactive#
34 /// exchange in and out.
35 void exchange(int in, int out) { add(in); drop (out); }
37 ///
38 Vector find_active_optimum(Vector g);
40 /// get lagrange multipliers.
41 Vector get_lagrange(Vector v);
43 Active_constraints(Ineq_constrained_qp const *op);
44 /** construct: no constraints active, n vars. Put the equalities
45 into the constraints. */
47 /// check invariants
48 void OK();
51 /**
52 This class represents the set of active (binding) constraints
53 which can be active while the QLP algorithm is in a feasible
54 point. The active constraints are numbered.
55 If the constraints are of the form
57 A^T*x >= b
59 then the binding constraints are those where the >= is equality.
63 ///
64 class Inactive_iter {
65 int j;
66 Active_constraints const* ac;
67 public:
68 Inactive_iter(Active_constraints const &c) { ac=&c; j=0; }
69 int idx() const { return j; }
70 void operator ++(int) { j++; }
71 int constraint_id() const { return ac->inactive[j]; }
72 Vector vec() const { return ac->vec(constraint_id()); }
73 Real rhs() const { return ac->rhs(constraint_id()); }
74 bool ok() const { return j < ac->inactive.sz(); }
76 /**
77 loop through the inactive constraints.