Re: [ojAlgo-user] Possible bug in ExpressionBasedModel: setMinimisation/setMaximisation
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2014-11-20 20:41:21
|
I haven't tried your code (yet) but I see something strange: > tmpModel.setMinimisation(false); > tmpModel.setMaximisation(true); > Result result = tmpModel.minimise(); Essentially you should just do either Result result = tmpModel.minimise(); or Result result = tmpModel.maximise(); If you look inside those methods they do: { this.setMinimisation(true); final Result tmpSolverResult = this.solve(); return this.handleResult(tmpSolverResult); } and { this.setMaximisation(true); final Result tmpSolverResult = this.solve(); return this.handleResult(tmpSolverResult); } Is this something that would explain/solve your problem? /Anders > On 20 nov 2014, at 13:18, Nico Potyka <Nic...@gm...> wrote: > > Hi, > > I use the newest version of ojAlgo (v37.0) and just tried the ExpressionBasedModel for linear optimization. > The solver seems to minimize independently of the configuration via setMinimisation/setMaximisation. > Here's a simple example: > > > int n = 4; > Variable[] tmpVariables = new Variable[n]; > for(int i=0; i<n; i++) { > tmpVariables[i] = new Variable("x"+i).lower(BigMath.ZERO); > } > > > ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables); > > > Expression tmpExpr = tmpModel.addExpression("Objective"); > tmpExpr.setLinearFactor(0, 10); > tmpExpr.setLinearFactor(1, 1); > tmpExpr.setLinearFactor(2, 1); > tmpExpr.setLinearFactor(3, 1); > tmpExpr.weight(BigMath.ONE); > > > tmpExpr = tmpModel.addExpression("Normalization").level(BigMath.ONE); > for(int i=0; i<n; i++) { > tmpExpr.setLinearFactor(i, BigMath.ONE); > } > > tmpModel.setMinimisation(false); > tmpModel.setMaximisation(true); > Result result = tmpModel.minimise(); > System.out.println("optimal value: "+result.getValue()); > for(int i=0; i<n; i++) { > System.out.println("x"+i+": "+result.get(i)); > } > > > > We maximize 10*x0 + x1 + x2 +x3 subject to non-negativity and normalization to 1. The output is > > optimal value: 1.0 > x0: 0 > x1: 1.00000000000000 > x2: 0 > x3: 0 > > > but in fact the optimal value is 10 and x0 should be 1 instead of x1. It seems that the solver always minimizes > the function. Do I use the solver in a wrong way or is there a bug? > > Best, > Nico > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |