]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/qlpsolve.hh
bf04b55d843de97cd6d7edad9e61bb319e5967d5
[lilypond.git] / lily / include / qlpsolve.hh
1 /*
2   qlpsolve.hh -- declare  Active_constraints, Inactive_iter
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef QLPSOLVE_HH
11 #define QLPSOLVE_HH
12
13 #include "matrix.hh"
14
15
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
21
22       A^T*x >= b
23
24     then the binding constraints are those where the >= is equality.
25     
26   */
27
28 class Active_constraints {
29   friend class Inactive_iter;
30     
31
32   Matrix A,H;
33   Array<int> active;
34   Array<int> inactive;          // actually this is a set, not an array.
35   Ineq_constrained_qp const *opt;
36
37 public:
38
39   int degenerate_count_i_;
40   String status() const;
41     
42   Vector vec (int k) const { return opt->cons_[k]; }
43   Real rhs (int k) const { return opt->consrhs_[k]; }
44     
45
46   /** drop constraint. drop constraint k from the active set. k is the index of the
47     constraint in #active#
48     
49     */
50   void drop_constraint (int k);
51     
52
53   /** add constraint j.
54     add constraint j to the active set j is the index of the
55     constraint in #inactive#   
56     */
57   void add_constraint (int j);
58
59   /// exchange in and out.
60   void exchange (int in, int out) { add_constraint (in); drop_constraint (out); }
61     
62
63   Vector find_active_optimum (Vector g);
64
65   /// get lagrange multipliers.
66   Vector get_lagrange (Vector v);
67
68   Active_constraints (Ineq_constrained_qp const *op);
69   /** construct: no constraints active, n vars. Put the equalities
70     into the constraints.  */
71
72   /// check invariants
73   void OK();
74 };
75
76
77 /**
78     loop through the inactive constraints.
79   */
80 class Inactive_iter {
81   int j;
82   Active_constraints const* ac;
83 public:
84   Inactive_iter (Active_constraints const &c) { ac=&c; j=0; }
85   int idx() const { return j; }
86   void operator ++(int) { j++; }
87   int constraint_id() const { return ac->inactive[j]; }
88   Vector vec() const { return ac->vec (constraint_id ()); }
89   Real rhs() const { return ac->rhs (constraint_id ()); }
90   bool ok() const { return j < ac->inactive.size (); }
91 };
92
93 #endif // QLPSOLVE_HH