]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/ineq-constrained-qp.hh
release: 0.1.1
[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 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         return lin.dim();
45     }
46
47     /**
48       add a constraint
49
50
51         c*vars >= r
52
53       PRE
54       c.dim() == dim();
55         
56       */
57     void add_inequality_cons(Vector c, double r);
58     
59     /** set up matrices to go with the problem. */
60     Ineq_constrained_qp(int novars);
61     
62     /**
63     evaluate the quadratic function for input #v#
64     */
65     Real eval(Vector v);
66
67     void eliminate_var(int idx, Real value);
68     void OK()const;
69     void print() const;
70
71 };
72
73 // ugh
74 const Real EPS=1e-7;            
75
76 #endif // INEQ_CONSTRAINED_QP_HH