]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/ineq-constrained-qp.hh
3b23cb898f2d4a86df817911859fe1f913ec1c06
[lilypond.git] / lily / include / ineq-constrained-qp.hh
1 /*
2   ineq-constrained-qp.hh -- declare Ineq_constrained_qp
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 INEQ_CONSTRAINED_QP_HH
11 #define INEQ_CONSTRAINED_QP_HH
12
13
14
15 #include "matrix.hh"
16
17 /// inequality constrained quadratic program
18 class Ineq_constrained_qp {
19     friend class Active_constraints;
20
21     Array<Vector> cons_;
22     Array<Real> consrhs_;
23 public:
24     Matrix quad_;
25     Vector lin_;
26     Real const_term_;
27
28
29     /**
30       use a KKT method to assert optimality of sol
31       */
32     void assert_solution (Vector sol) const;
33     /// solve the problem using a projected gradient method
34     Vector constraint_solve (Vector) const;
35     /**
36       Solve it. First try it the easy way.
37      */
38     Vector solve (Vector start) const;
39     
40     /**
41       @return the number of variables in the problem
42       */
43     int dim() const;
44
45     /**
46       add a constraint
47
48
49         c*vars >= r
50
51       PRE
52       c.dim() == dim ();
53         
54       */
55     void add_inequality_cons (Vector c, double r);
56     
57     /** set up matrices to go with the problem. */
58     Ineq_constrained_qp (int novars);
59     
60     /**
61     evaluate the quadratic function for input #v#
62     */
63     Real eval (Vector v);
64
65     void eliminate_var (int idx, Real value);
66     void OK() const;
67     void print() const;
68
69 };
70
71 // ugh
72 const Real EPS=1e-7;            
73
74 #endif // INEQ_CONSTRAINED_QP_HH