2 qlp.cc -- implement Mixed_qp
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
13 Mixed_qp::add_equality_cons (Vector
, double)
19 Mixed_qp::add_fixed_var (int i
, Real r
)
27 eliminate appropriate variables, until we have a Ineq_constrained_qp
31 cons should be ascending
34 Mixed_qp::solve (Vector start
) const
40 Ineq_constrained_qp
pure (*this);
42 for (int i
= eq_cons
.size()-1; i
>=0; i
--)
44 pure
.eliminate_var (eq_cons
[i
], eq_consrhs
[i
]);
45 start
.del (eq_cons
[i
]);
47 Vector sol
= pure
.solve (start
);
48 for (int i
= 0; i
< eq_cons
.size(); i
++)
50 sol
.insert (eq_consrhs
[i
],eq_cons
[i
]);
57 Ineq_constrained_qp::assert_solution (Vector sol
) const
60 for (int i
=0; i
< cons
.size(); i
++)
62 Real R
=cons
[i
] * sol
- consrhs
[i
];
72 Ineq_constrained_qp::print() const
75 DOUT
<< "Quad " << quad
;
76 DOUT
<< "lin " << lin
<<"\n"
77 << "const " << const_term
<<"\n";
78 for (int i
=0; i
< cons
.size(); i
++)
80 DOUT
<< "constraint["<<i
<<"]: " << cons
[i
] << " >= " << consrhs
[i
];
86 Mixed_qp::Mixed_qp (int n
)
87 : Ineq_constrained_qp (n
)
95 Ineq_constrained_qp::OK();
96 assert (eq_consrhs
.size() == eq_cons
.size ());
101 Mixed_qp::print() const
104 Ineq_constrained_qp::print();
105 for (int i
=0; i
< eq_cons
.size(); i
++)
107 DOUT
<< "eq cons "<<i
<<": x["<<eq_cons
[i
]<<"] == " << eq_consrhs
[i
]<<"\n";