Re: [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 21:31:53
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div> <div>Yes, sorry, this should solve my problem ;)</div> <div> </div> <div>Best regards</div> <div>Nico</div> <div> </div> <div> <div> </div> <div> </div> <div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"> <div style="margin:0 0 10px 0;"><b>Gesendet:</b> Donnerstag, 20. November 2014 um 21:41 Uhr<br/> <b>Von:</b> "Anders Peterson" <an...@op...><br/> <b>An:</b> "ojAlgo ojAlgo" <oja...@li...><br/> <b>Betreff:</b> Re: [ojAlgo-user] Possible bug in ExpressionBasedModel: setMinimisation/setMaximisation</div> <div name="quoted-content">I haven't tried your code (yet) but I see something strange:<br/> <br/> > tmpModel.setMinimisation(false);<br/> > tmpModel.setMaximisation(true);<br/> > Result result = tmpModel.minimise();<br/> <br/> <br/> Essentially you should just do either<br/> <br/> Result result = tmpModel.minimise();<br/> <br/> or<br/> <br/> Result result = tmpModel.maximise();<br/> <br/> <br/> If you look inside those methods they do:<br/> <br/> {<br/> this.setMinimisation(true);<br/> final Result tmpSolverResult = this.solve();<br/> return this.handleResult(tmpSolverResult);<br/> }<br/> <br/> and<br/> <br/> {<br/> this.setMaximisation(true);<br/> final Result tmpSolverResult = this.solve();<br/> return this.handleResult(tmpSolverResult);<br/> }<br/> <br/> <br/> Is this something that would explain/solve your problem?<br/> <br/> <br/> /Anders<br/> <br/> <br/> <br/> <br/> > On 20 nov 2014, at 13:18, Nico Potyka <Nic...@gm...> wrote:<br/> ><br/> > Hi,<br/> ><br/> > I use the newest version of ojAlgo (v37.0) and just tried the ExpressionBasedModel for linear optimization.<br/> > The solver seems to minimize independently of the configuration via setMinimisation/setMaximisation.<br/> > Here's a simple example:<br/> ><br/> ><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/> ><br/> > 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/> > }<br/> ><br/> ><br/> ><br/> > We maximize 10*x0 + x1 + x2 +x3 subject to non-negativity and normalization to 1. The output is<br/> ><br/> > optimal value: 1.0<br/> > x0: 0<br/> > x1: 1.00000000000000<br/> > x2: 0<br/> > x3: 0<br/> ><br/> ><br/> > but in fact the optimal value is 10 and x0 should be 1 instead of x1. It seems that the solver always minimizes<br/> > the function. Do I use the solver in a wrong way or is there a bug?<br/> ><br/> > Best,<br/> > Nico<br/> > ------------------------------------------------------------------------------<br/> > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server<br/> > from Actuate! Instantly Supercharge Your Business Reports and Dashboards<br/> > with Interactivity, Sharing, Native Excel Exports, App Integration & more<br/> > Get technology previously reserved for billion-dollar corporations, FREE<br/> > <a href="http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk_______________________________________________" target="_blank">http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk_______________________________________________</a><br/> > ojAlgo-user mailing list<br/> > ojA...@li...<br/> > <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a><br/> <br/> <br/> ------------------------------------------------------------------------------<br/> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server<br/> from Actuate! Instantly Supercharge Your Business Reports and Dashboards<br/> with Interactivity, Sharing, Native Excel Exports, App Integration & more<br/> Get technology previously reserved for billion-dollar corporations, FREE<br/> <a href="http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk" target="_blank">http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk</a><br/> _______________________________________________<br/> ojAlgo-user mailing list<br/> ojA...@li...<br/> <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a></div> </div> </div> </div></div></body></html> |