summaryrefslogtreecommitdiff
path: root/qlp.hh
blob: b539fe6b865798de9a309e9a10c961ec75d72360 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef QLP_HH
#define QLP_HH

#include "matrix.hh"

/// inequality constrained quadratic program
class Ineq_constrained_qp {
    friend class Active_constraints;

    svec<Vector> cons;
    svec<Real> consrhs;
public:
    Matrix quad;
    Vector lin;
    Real const_term;

    ///
    void assert_solution(Vector sol) const;
    /**
      use a KKT method to assert optimality of sol
      */
    /// solve the problem using a projected gradient method
    Vector solve(Vector start) const;
    
    int dim() const{
	return lin.dim();
    }
    /** return the number of variables in the problem */
    ///
    void add_inequality_cons(Vector c, double r);
    /**
      add a constraint


        c*vars >= r

      PRE
      c.dim() == dim();
	
      */
    ///
    Ineq_constrained_qp(int novars);
    /** set up matrices to go with the problem. */

    Real eval(Vector v);
    /**
    evaluate the quadratic function for input #v#
    */

    void eliminate_var(int idx, Real value);
    void OK()const;
    void print() const;

};

/// Quadratic programming with mixed linear constraints
class Mixed_qp :public Ineq_constrained_qp {
    svec<int> eq_cons;
    svec<Real> eq_consrhs;
public:
    Mixed_qp(int n);
    void OK() const;
    void print() const;

    Vector solve(Vector start) const;
    void add_fixed_var(int i , Real value);
    
    ///
    void add_equality_cons(Vector c, double r);
    /**
      add a constraint,

        c*vars == r

      PRE
      c.dim()==dim();
     */

};
/**
  problem definition of a quadratic optimisation problem with linear
  inequality and equality constraints


    x^T QUAD x /2 + b^T x 
*/


#endif