2 qlp.cc -- implement Mixed_qp
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
14 Mixed_qp::add_equality_cons (Vector
, double)
20 Mixed_qp::add_fixed_var (int i
, Real r
)
28 eliminate appropriate variables, until we have a Ineq_constrained_qp
32 cons should be ascending
35 Mixed_qp::solve (Vector start
) const
41 Ineq_constrained_qp
pure (*this);
43 for (int i
= eq_cons
.size()-1; i
>=0; i
--)
45 pure
.eliminate_var (eq_cons
[i
], eq_consrhs
[i
]);
46 start
.del (eq_cons
[i
]);
48 Vector sol
= pure
.solve (start
);
49 for (int i
= 0; i
< eq_cons
.size(); i
++)
51 sol
.insert (eq_consrhs
[i
],eq_cons
[i
]);
58 Ineq_constrained_qp::assert_solution (Vector sol
) const
61 for (int i
=0; i
< cons_
.size(); i
++)
63 Real R
=cons_
[i
] * sol
- consrhs_
[i
];
73 Ineq_constrained_qp::print() const
76 DOUT
<< "Quad " << quad_
;
77 DOUT
<< "lin " << lin_
<<"\n"
78 << "const " << const_term_
<<"\n";
79 for (int i
=0; i
< cons_
.size(); i
++)
81 DOUT
<< "constraint["<<i
<<"]: " << cons_
[i
] << " >= " << consrhs_
[i
];
87 Mixed_qp::Mixed_qp (int n
)
88 : Ineq_constrained_qp (n
)
96 Ineq_constrained_qp::OK();
97 assert (eq_consrhs
.size() == eq_cons
.size ());
102 Mixed_qp::print() const
105 Ineq_constrained_qp::print();
106 for (int i
=0; i
< eq_cons
.size(); i
++)
108 DOUT
<< "eq cons "<<i
<<": x["<<eq_cons
[i
]<<"] == " << eq_consrhs
[i
]<<"\n";