Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BONMIN options not working #53

Closed
JO-WTF opened this issue Nov 25, 2016 · 14 comments
Closed

BONMIN options not working #53

JO-WTF opened this issue Nov 25, 2016 · 14 comments

Comments

@JO-WTF
Copy link

JO-WTF commented Nov 25, 2016

using JSON
using JuMP,AmplNLWriter

data={"P":1.0,"I":4,"J":2,"Bandwidth":[1.25,1.25,1.25,1.25],"Noise":[5.1E-8,9.65714E-8,7.6164E-8,2.33161E-8],"ell":[45,55]}
data=JSON.parse(data)

P=data["P"]
I=data["I"]
J=data["J"]
bw=data["Bandwidth"]
ns=data["Noise"]
el=data["ell"]

solver = BonminNLSolver([
		"halt_on_ampl_error=yes";
		"bonmin.bb_log_level=0"
		])

m = Model(solver=solver)


@variable(m,x[1:I,1:J],Bin)
@variable(m,p[1:I,1:J]>=0)
@variable(m,r[1:I,1:J]>=0)

@constraint(m,sum(p)<=P)

@constraint(m,[i=1:I],sum(x[i,j] for j=1:J)<=1)

@constraint(m,[i=1:I,j=1:J],p[i,j]<=P*x[i,j])

@constraint(m,[j=1:J],sum(r[i,j] for i=1:I)>=el[j])

@NLconstraint(m,[i=1:I,j=1:J],r[i,j]<=bw[i]*log2(1+p[i,j]/ns[i]))

@objective(m,Max,sum(r))

status=solve(m)

print(getvalue(x))
print(getvalue(p))
getvalue(r)

In the solution given by the solver above, some variables are set to 1.0e-8 instead of 0. Because of the nature of this problem, precision of 1.0e-8 is far from enough for us. So I tried to set BONMIN options including:

bonmin.integer_tolerance                     1e-18
bonmin.cutoff_decr                           1e-18
bonmin.oa_rhs_relax                          1e-18     	#Value by which to relax OA cut
bonmin.tiny_element                          1e-18     	#Value for tiny element in OA cut
bonmin.very_tiny_element                     1e-27     	#Value for very tiny element in OA cut

However, they didn't affect the result at all.

I also tried to set:
bonmin.milp_solver Cplex

However, the result&output were exactly the same with Cbc_D.

So I think some options are not taking effect.

odow: formatting

@mlubin
Copy link
Member

mlubin commented Nov 25, 2016

It's my experience that options in Bonmin are terribly broken. I've had to go in and modify the source code on multiple occasions. https://github.com/mlubin/Pajarito.jl is a julia version of bonmin (and much more) that may be worth playing around with.

@JO-WTF
Copy link
Author

JO-WTF commented Nov 25, 2016

Thanks @mlubin

I have formulated the same problem in C callable library from BONMIN.

The tolerances, no matter how I change them, stay at 1e-08 all the time.

However, the MILP solver was set successfully(at least I saw some differnces in iterations and nodes).

While I try to set subsolver for amplnlwriter, results are all the same. Do you think there is any mistake in the code?

Thanks.

@mlubin
Copy link
Member

mlubin commented Nov 25, 2016 via email

@JackDunnNZ
Copy link
Collaborator

It's not clear to me from your description, but have you also tried setting the options using the .opt file approach as described here? I know there are a number of options that only work via that interface and not via command line options

@JO-WTF
Copy link
Author

JO-WTF commented Nov 25, 2016

@JackDunnNZ

I firstly tried to set options using command line, it didnt work so I then used the bonmin.opt file as you linked.

But it seems they didnt work anyway.

@JackDunnNZ
Copy link
Collaborator

Okay, then Miles is almost certainly correct that it is Bonmin itself causing the problem

@JO-WTF
Copy link
Author

JO-WTF commented Nov 25, 2016

While my question is: I tried to do the same set ups in BONMIN C library, it did work...Why's that?

Even if that's Bonmin's problem, is there any work around?

@mlubin
Copy link
Member

mlubin commented Nov 25, 2016

@JO-WTF, look into Bonmin's code for interfacing with the AMPL solver interface. The code path for options when reading .nl files is likely different from the path for options passed through the C interface.

@JO-WTF
Copy link
Author

JO-WTF commented Nov 25, 2016

I have put the opt file in the directory of my julia file. It was successfully read and some options have been applied but some are not.

@JO-WTF
Copy link
Author

JO-WTF commented Nov 27, 2016

Hi Guys,

I have done some more test and got some results. Thought you might be interested in it:

I wrote a model in AMPL and converted it into .nl file, then I use bonmin to solve the .nl file with options "bonmin.milp_solver Cbc_D" and "bonmin.milp_solver Cplex" respectively. The model was solved successfully but because sub-solvers are different, they took different numbers of iterations and time.

Then I wrote the same model in Julia, using AmplNLWriter to call BONMIN to solve it. Although I have used the same bonmin.opt file to set the sub-solver to Cplex, the results showing it was solved by Cbc_D (number of iterations and every output were exactly the same with the one solved the BONMIN+Cbc_D).

That means:

the option file had no problem;
bonmin itself can pick up those options correctly;
bonmin could not pick up the option passed by AmplNLWriter.

Any idea please?

Thanks.

@JackDunnNZ
Copy link
Collaborator

It is working for me if I create the bonmin.opt file in the current directory. This is running from ~/.julia/v0.4/AmplNLWriter using one of the included examples:

julia> include("examples/jump_minlp.jl")
  > example: jump_minlp
Bonmin 1.8.4 using Cbc 2.9.7 and Ipopt 3.12.4
bonmin:

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************

NLP0012I
              Num      Status      Obj             It       time                 Location
NLP0014I             1         OPT 0.75928418        9 0.005656
NLP0014I             2         OPT 9.9999996        9 0.004086
NLP0012I
              Num      Status      Obj             It       time                 Location
NLP0014I             1         OPT 9.9999996        9 0.003783
Cbc0012I Integer solution of 9.9999996 found by FPump after 0 iterations and 0 nodes (0.02 seconds)
NLP0014I             2         OPT 5.1713201       11 0.005914
NLP0014I             3         OPT 6.0097585        7 0.003296
NLP0014I             4         OPT 3.8208866       10 0.004227
NLP0014I             5         OPT 7.0927311        8 0.003684
Cbc0010I After 0 nodes, 1 on tree, 9.9999996 best solution, best possible 0.75928418 (0.04 seconds)
NLP0014I             6         OPT 5.1713201       11 0.005483
NLP0014I             7         OPT 6.0097585        7 0.003182
NLP0014I             2         OPT 6.0097587        8 0.003789
Cbc0004I Integer solution of 6.0097587 found after 18 iterations and 2 nodes (0.05 seconds)
NLP0014I             8         OPT 7.0927314        8 0.004916
NLP0014I             9         OPT 9.9999995        8 0.00535
Cbc0001I Search completed - best objective 6.009758719300063, took 34 iterations and 4 nodes (0.06 seconds)
Cbc0032I Strong branching done 2 times (36 iterations), fathomed 0 nodes and fixed 0 variables
Cbc0035I Maximum depth 1, 0 variables fixed on reduced cost

 	"Finished"
Success :: (line:507) :: fact was true
  Expression: getobjectivevalue(m) --> roughly(6.00975,1.0e-5)
    Expected: 6.00975
    Occurred: 6.00975878926541
shell> echo "milp_solver cplex" > bonmin.opt
julia> include("examples/jump_minlp.jl")
  > example: jump_minlp
Bonmin 1.8.4 using Cbc 2.9.7 and Ipopt 3.12.4
bonmin:
WARNING: Variable value not defined for component of x. Check that the model was properly solved.
WARNING: Variable value not defined for entry of y. Check that the model was properly solved.
Failure :: (line:507) :: fact was false
  Expression: getobjectivevalue(m) --> roughly(6.00975,1.0e-5)
    Expected: 0  6.00975

I don't have bonmin set up to use cplex, so it doesn't solve, but this is indication that the option file is being respected. Can you try using the same approach to check it works?

@JackDunnNZ
Copy link
Collaborator

Also for what it's worth, this package does nothing more than create the .nl file from the JuMP model and then use your specified solver to solve the .nl file, exactly as you would have done for solving the .nl file created by AMPL. There is no reason the options behavior should be different between these two approaches.

@JO-WTF
Copy link
Author

JO-WTF commented Nov 27, 2016

I have just tried to modify the code and it seems to be working now.

Originally I set up BONMIN as:

solver = BonminNLSolver()

And it didn't work.

Then I changed to:

solver = AmplNLSolver("bonmin")

and options now are working.

Not sure why tho.

@odow
Copy link
Member

odow commented Nov 24, 2017

Closing as this doesn't appear to be an AmplNLWriter issue.

@odow odow closed this as completed Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants