7 Mixed_qp::add_equality_cons(Vector
, double )
13 Mixed_qp::add_fixed_var(int i
, Real r
)
20 Ineq_constrained_qp::add_inequality_cons(Vector c
, double r
)
26 Ineq_constrained_qp::Ineq_constrained_qp(int novars
):
34 Ineq_constrained_qp::OK() const
37 assert(cons
.size() == consrhs
.size());
38 Matrix Qdif
= quad
- quad
.transposed();
39 assert(Qdif
.norm()/quad
.norm() < EPS
);
45 Ineq_constrained_qp::eval (Vector v
)
47 return v
* quad
* v
+ lin
* v
+ const_term
;
50 Mixed_qp::solve(Vector start
) const
53 Ineq_constrained_qp
pure(*this);
55 for (int i
= eq_cons
.size()-1; i
>=0; i
--) {
56 pure
.eliminate_var(eq_cons
[i
], eq_consrhs
[i
]);
57 start
.del(eq_cons
[i
]);
59 Vector sol
= pure
.solve(start
);
60 for (int i
= 0; i
< eq_cons
.size(); i
++) {
61 sol
.insert( eq_consrhs
[i
],eq_cons
[i
]);
67 assume x(idx) == value, and adjust constraints, lin and quad accordingly
70 Ineq_constrained_qp::eliminate_var(int idx
, Real value
)
72 Vector
row(quad
.row(idx
));
77 quad
.delete_column(idx
);
83 for (int i
=0; i
< cons
.size(); i
++) {
84 consrhs
[i
] -= cons
[i
](idx
) *value
;
92 Ineq_constrained_qp::assert_solution(Vector sol
) const
95 for (int i
=0; i
< cons
.size(); i
++) {
96 Real R
=cons
[i
] * sol
- consrhs
[i
];
106 Ineq_constrained_qp::print() const
109 mtor
<< "Quad " << quad
;
110 mtor
<< "lin " << lin
<<"\n"
111 << "const " << const_term
<<"\n";
112 for (int i
=0; i
< cons
.size(); i
++) {
113 mtor
<< "constraint["<<i
<<"]: " << cons
[i
] << " >= " << consrhs
[i
];
119 /* *************** */
122 eliminate appropriate variables, until we have a Ineq_constrained_qp
126 cons should be ascending
130 Mixed_qp::Mixed_qp(int n
)
131 : Ineq_constrained_qp(n
)
139 Ineq_constrained_qp::OK();
140 assert(eq_consrhs
.size() == eq_cons
.size());
145 Mixed_qp::print() const
148 Ineq_constrained_qp::print();
149 for (int i
=0; i
< eq_cons
.size(); i
++) {
150 mtor
<< "eq cons "<<i
<<": x["<<eq_cons
[i
]<<"] == " << eq_consrhs
[i
]<<"\n";