lilypond-1.1.23
[lilypond.git] / hdr / qlp.hh
blobccfba72bb83c76abf9901a5c20c447b894d89983
1 /*
2 qlp.hh -- declare Ineq_constrained_qp, Mixed_qp
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #ifndef QLP_HH
10 #define QLP_HH
12 #include "matrix.hh"
14 /// inequality constrained quadratic program
15 class Ineq_constrained_qp {
16 friend class Active_constraints;
18 Array<Vector> cons;
19 Array<Real> consrhs;
20 public:
21 Matrix quad;
22 Vector lin;
23 Real const_term;
26 /**
27 use a KKT method to assert optimality of sol
29 void assert_solution(Vector sol) const;
30 /// solve the problem using a projected gradient method
31 Vector solve(Vector start) const;
33 /**
34 @return the number of variables in the problem
36 int dim() const{
37 return lin.dim();
40 /**
41 add a constraint
44 c*vars >= r
46 PRE
47 c.dim() == dim();
50 void add_inequality_cons(Vector c, double r);
52 /** set up matrices to go with the problem. */
53 Ineq_constrained_qp(int novars);
55 /**
56 evaluate the quadratic function for input #v#
58 Real eval(Vector v);
60 void eliminate_var(int idx, Real value);
61 void OK()const;
62 void print() const;
67 /**
68 Quadratic programming with mixed linear constraints.
69 problem definition of a quadratic optimisation problem with linear
70 inequality and equality constraints
73 x^T QUAD x /2 + b^T x
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;
83 Vector solve(Vector start) const;
84 void add_fixed_var(int i , Real value);
87 /**
88 add a constraint,
90 c*vars == r
92 PRE
93 c.dim()==dim();
95 void add_equality_cons(Vector c, double r);
97 #endif