]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/qlpsolve.hh
dc2aaa5663d6f0d01e41a17f2b6bf75513b4a02e
[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@stack.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   String status() const;
39     
40   Vector vec (int k) const { return opt->cons_[k]; }
41   Real rhs (int k) const { return opt->consrhs_[k]; }
42     
43
44   /** drop constraint. drop constraint k from the active set. k is the index of the
45     constraint in #active#
46     
47     */
48   void drop (int k);
49     
50
51   /** add constraint j.
52     add constraint j to the active set j is the index of the
53     constraint in #inactive#   
54     */
55   void add (int j);
56
57   /// exchange in and out.
58   void exchange (int in, int out) { add (in); drop (out); }
59     
60
61   Vector find_active_optimum (Vector g);
62
63   /// get lagrange multipliers.
64   Vector get_lagrange (Vector v);
65
66   Active_constraints (Ineq_constrained_qp const *op);
67   /** construct: no constraints active, n vars. Put the equalities
68     into the constraints.  */
69
70   /// check invariants
71   void OK();
72 };
73
74
75 /**
76     loop through the inactive constraints.
77   */
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 (); }
89 };
90
91 #endif // QLPSOLVE_HH