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