lilypond-0.1.57
[lilypond.git] / hdr / qlpsolve.hh
blob7c9b8da341b57342033d9bf97c71bdd45efb213f
1 /*
2 qlpsolve.hh -- declare Active_constraints, Inactive_iter
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
10 #ifndef QLPSOLVE_HH
11 #define QLPSOLVE_HH
12 #include "qlp.hh"
13 #include "matrix.hh"
16 /**
17 This class represents the set of active (binding) constraints
18 which can be active while the QLP algorithm is in a feasible
19 point. The active constraints are numbered.
20 If the constraints are of the form
22 A^T*x >= b
24 then the binding constraints are those where the >= is equality.
28 class Active_constraints {
29 friend class Inactive_iter;
32 Matrix A,H;
33 Array<int> active;
34 Array<int> inactive; // actually this is a set, not an array.
35 const Ineq_constrained_qp *opt;
37 public:
38 String status()const;
40 Vector vec(int k) const { return opt->cons[k]; }
41 Real rhs(int k) const { return opt->consrhs[k]; }
44 /** drop constraint. drop constraint k from the active set. k is the index of the
45 constraint in #active#
48 void drop (int k);
51 /** add constraint j.
52 add constraint j to the active set j is the index of the
53 constraint in #inactive#
55 void add(int j);
57 /// exchange in and out.
58 void exchange(int in, int out) { add(in); drop (out); }
61 Vector find_active_optimum(Vector g);
63 /// get lagrange multipliers.
64 Vector get_lagrange(Vector v);
66 Active_constraints(Ineq_constrained_qp const *op);
67 /** construct: no constraints active, n vars. Put the equalities
68 into the constraints. */
70 /// check invariants
71 void OK();
75 /**
76 loop through the inactive constraints.
78 class Inactive_iter {
79 int j;
80 Active_constraints const* ac;
81 public:
82 Inactive_iter(Active_constraints const &c) { ac=&c; j=0; }
83 int idx() const { return j; }
84 void operator ++(int) { j++; }
85 int constraint_id() const { return ac->inactive[j]; }
86 Vector vec() const { return ac->vec(constraint_id()); }
87 Real rhs() const { return ac->rhs(constraint_id()); }
88 bool ok() const { return j < ac->inactive.size(); }
91 #endif // QLPSOLVE_HH