[ojAlgo-user] Possible bug in ExpressionBasedModel: setMinimisation/setMaximisation
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Nico P. <Nic...@gm...> - 2014-11-20 12:19:10
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div> <div>Hi,</div> <div> </div> <div>I use the newest version of ojAlgo (v37.0) and just tried the ExpressionBasedModel for linear optimization.</div> <div>The solver seems to minimize independently of the configuration via setMinimisation/setMaximisation.</div> <div>Here's a simple example:</div> <div> </div> <div name="quoted-content"> <div><br/> int n = 4;<br/> Variable[] tmpVariables = new Variable[n];<br/> for(int i=0; i<n; i++) {<br/> tmpVariables[i] = new Variable("x"+i).lower(BigMath.ZERO);<br/> }<br/> <br/> <br/> ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);<br/> <br/> <br/> Expression tmpExpr = tmpModel.addExpression("Objective");<br/> tmpExpr.setLinearFactor(0, 10); <br/> tmpExpr.setLinearFactor(1, 1); <br/> tmpExpr.setLinearFactor(2, 1); <br/> tmpExpr.setLinearFactor(3, 1);<br/> tmpExpr.weight(BigMath.ONE);<br/> <br/> <br/> tmpExpr = tmpModel.addExpression("Normalization").level(BigMath.ONE);<br/> for(int i=0; i<n; i++) {<br/> tmpExpr.setLinearFactor(i, BigMath.ONE);<br/> }<br/> </div> <div> tmpModel.setMinimisation(false);<br/> tmpModel.setMaximisation(true);<br/> Result result = tmpModel.minimise();<br/> System.out.println("optimal value: "+result.getValue());<br/> for(int i=0; i<n; i++) {<br/> System.out.println("x"+i+": "+result.get(i));<br/> }</div> <div> </div> <div> </div> <div> </div> <div>We maximize 10*x0 + x1 + x2 +x3 subject to non-negativity and normalization to 1. The output is</div> <div> <div> </div> <div> <div> optimal value: 1.0<br/> x0: 0<br/> x1: 1.00000000000000<br/> x2: 0<br/> x3: 0</div> <div> </div> <div> </div> <div>but in fact the optimal value is 10 and x0 should be 1 instead of x1. It seems that the solver always minimizes</div> <div>the function. Do I use the solver in a wrong way or is there a bug?</div> <div> </div> <div>Best,</div> <div>Nico</div> </div> </div> </div> </div></div></body></html> |