]> git.donarmstrong.com Git - lilypond.git/blob - qlpsolve.hh
release: 0.0.6
[lilypond.git] / qlpsolve.hh
1 #include "qlp.hh"
2 #include "matrix.hh"
3
4
5 class Active_constraints {
6     friend class Inactive_iter;
7     
8
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;
13
14 public:
15     String status()const;
16     
17     Vector vec(int k) const { return opt->cons[k]; }
18     Real rhs(int k) const { return opt->consrhs[k]; }
19     
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#
24     
25     */
26     
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#   
32     */
33
34     /// exchange in and out.
35     void exchange(int in, int out) { add(in); drop (out); }
36     
37     /// 
38     Vector find_active_optimum(Vector g);
39
40     /// get lagrange multipliers.
41     Vector get_lagrange(Vector v);
42
43     Active_constraints(Ineq_constrained_qp const *op);
44     /** construct: no constraints active, n vars. Put the equalities
45      into the constraints.  */
46
47     /// check invariants
48     void OK();
49 };
50
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
56
57       A^T*x >= b
58
59     then the binding constraints are those where the >= is equality.
60     
61   */
62
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(); }
75 };
76 /**
77     loop through the inactive constraints.
78   */