]> git.donarmstrong.com Git - lilypond.git/blob - hdr/qlp.hh
release: 0.0.32
[lilypond.git] / hdr / qlp.hh
1 /*
2   qlp.hh -- declare Ineq_constrained_qp, Mixed_qp
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #ifndef QLP_HH
10 #define QLP_HH
11
12 #include "matrix.hh"
13
14 /// inequality constrained quadratic program
15 class Ineq_constrained_qp {
16     friend class Active_constraints;
17
18     Array<Vector> cons;
19     Array<Real> consrhs;
20 public:
21     Matrix quad;
22     Vector lin;
23     Real const_term;
24
25
26     /**
27       use a KKT method to assert optimality of sol
28       */
29     void assert_solution(Vector sol) const;
30     /// solve the problem using a projected gradient method
31     Vector solve(Vector start) const;
32     
33     /**
34       @return the number of variables in the problem
35       */
36     int dim() const{
37         return lin.dim();
38     }
39
40     /**
41       add a constraint
42
43
44         c*vars >= r
45
46       PRE
47       c.dim() == dim();
48         
49       */
50     void add_inequality_cons(Vector c, double r);
51     
52     /** set up matrices to go with the problem. */
53     Ineq_constrained_qp(int novars);
54     
55     /**
56     evaluate the quadratic function for input #v#
57     */
58     Real eval(Vector v);
59
60     void eliminate_var(int idx, Real value);
61     void OK()const;
62     void print() const;
63
64 };
65
66
67 /**
68    Quadratic programming with mixed linear constraints.
69   problem definition of a quadratic optimisation problem with linear
70   inequality and equality constraints
71
72
73     x^T QUAD x /2 + b^T x 
74 */
75 class Mixed_qp :public Ineq_constrained_qp {
76     Array<int> eq_cons;
77     Array<Real> eq_consrhs;
78 public:
79     Mixed_qp(int n);
80     void OK() const;
81     void print() const;
82
83     Vector solve(Vector start) const;
84     void add_fixed_var(int i , Real value);
85     
86
87     /**
88       add a constraint,
89
90         c*vars == r
91
92       PRE
93       c.dim()==dim();
94      */
95     void add_equality_cons(Vector c, double r);
96 };
97 #endif