-
Notifications
You must be signed in to change notification settings - Fork 15
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
Question: output of objective value using gurobi solver with pymzn.minizinc() function #47
Comments
Hello Dominic, Regarding your first question, the function s = pymzn.minizinc(...)
opt = s[-1] Regarding the Let me know if this solves the issue or if you have further questions. Cheers, |
Hi Paolo, thanks a lot for your very fast reply. Unfortunately, opt = s[-1] delivers the optimal solution, in my case the optimal set of items for the knapsack problem. But it does not give me the objective value I am optimizing for, here: to maximize profit The --relGap was not needed yet, because speed performance is satisfying good with gurobi solver. As I could not figure out above mentioned issue, I instead used a command workaround.
This obviously does not make use of your nice library. :-( I keep you and others posted, if I figure out an more elegant way. For now: Thanks again |
For that you can try using the s = pymzn.minizinc(mzn_file, dzn_file, solver=pymzn.gurobi, output_vars=['knapsack', 'profit'])
opt = s[-1]
I meant something like this: class GurobiWithArgs(pymzn.solvers.Gurobi):
def __init__(self, rel_gap):
self.rel_gap = rel_gap
def args(self, *args, **kwargs):
args = super().args(*args, **kwargs)
args += ['relGap', self.rel_gap]
return args Then calling pymzn.minizinc(..., solver=pymzn.GurobiWithArgs()) Hope this helps. Paolo |
Hello Paolo and other pymzn experts,
this is not an issue but more a question on usability of arguments in pymzn.minizinc() function.
As I could not find a forum, I hope this post here is okay.
When I use following code, I get the objective value printed out:
pymzn.minizinc(mzn_file,dzn_file,solver=pymzn.gecode,output_mode='item')
When I use Gurobi solver instead, I only get informed that the solving is "COMPLETE":
pymzn.minizinc(mzn_file,dzn_file,solver=pymzn.gurobi,output_mode='item')
I have tried several things, but do not get the desired output. For example, I failed to hand over arguments:
pymzn.minizinc(mzn_file,dzn_file,args={'arg1':'-s'},solver=pymzn.gurobi)
In fact, I really just want to have the objective value, ideally including the already outputted items of the optimal solution.
Below you can find my mzn and dzn file.
Furthermore, I might want to make use of --relGap argument. If this is not a hassle, could you please present an example usage of pymzn.minizinc() with the use of gurobi and --relGap argument?
Just equivilant to the windows command line, e.g.:
minizinc --solver gurobi -a --statistics knapsack_1.mzn knapsack_9.dzn
I would be so thankful for a hint as I could not figure out a solution since last thursday.
Info: MiniZinc Version 2.4.3., pymzn Version 18.3, Visual Studio Code Version 1.49.2, Python 3.8.5 x64, Windows 10.0.18363 x64,
Best regards
Dominic
mzn file:
`enum ITEM;
int: wcapacity;
int: vcapacity;
array[ITEM] of int: profits;
array[ITEM] of int: weights;
array[ITEM] of int: volumes;
var set of ITEM: knapsack;
var int: weight = sum (i in knapsack) (weights[i]);
constraint weight <= wcapacity;
var int: volume = sum (i in knapsack) (volumes[i]);
constraint volume <= vcapacity;
var int: profit = sum (i in knapsack) (profits[i]);
solve maximize profit ;
%regardless of using below output line or not
output [show(profit)];`
dzn file:
`wcapacity = 3500;
vcapacity = 20;
ITEM = { AAA, AAB, AAC, AAD, AAE};
profits = [195,150,63,183,20];
weights = [982,124,1144,1507,1009];
volumes = [5,1,8,8,6];`
The text was updated successfully, but these errors were encountered: