[ojAlgo-user] using quadratic solver
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: David J. <dav...@bu...> - 2010-10-05 23:17:18
|
Hi, I'm new to ojalgo, and trying to work out the exact syntax needed to configure the quadratic solver. Specifically, I'm trying to solve a standard quadratic minimization problem: min(1/2*transpose(alpha)*H*alpha - sum(alpha)), given 0 <= alphai <= C (where C is a constant), for each element in alpha. Alpha will be initialized to 0s (or uninitialized, if no initial input is needed) and H to a given input matrix. I'm unclear on exactly what I need to configure in the QuadraticExpressionsModel versus what is handled by the builder. I also can't seem to find a current example of how to configure an expression-based model (except for the one in MarkowitzModel, which helped, but didn't entirely clarify the logic). My current (very rough) code skeleton looks like this: final Variable[] vars = new Variable[2]; vars[0] = new Variable("alpha"); vars[0].setLowerLimit(new BigDecimal(0)); vars[0].setUpperLimit(new BigDecimal(C)); vars[0].setContributionWeight(BigMath.ONE); vars[1] = new Variable("H"); final QuadraticExpressionsModel qem = new QuadraticExpressionsModel(vars); qem.setMinimisation(true); final QuadraticSolver.Builder build = new QuadraticSolver.Builder(qem); I can't tell if alpha and H should even be listed as variables (as opposed to expressions), how to associate my input matrices with them if they should be, and how to describe range limits on alpha if they should not. I'm also not certain how to define my objective function - is the basic format handled by the builder, or do I need to describe it in the model somehow? Should I be using the inequalities(...) and objective(...) functions in the builder, or defining those via the model? Also, I know I can represent sum(alpha) in my equation by just setting C (the vector in the basic equation format, not my constant) to be a singular 1 vector, but is there any way to ensure that the solver will then treat C as a constant? Thanks David Johnson |