GRB update environment
OngoingI am solving an optimization problem `P := min f(x) : x in X` where `X` has many linear constraints. To speed up the process, I instead consider solving a sequence of problems of the form `P^i := min f(x) : x in X^i` where `X^i \subseteq X^{i+1} \subseteq X`. I would like to solve `P^i` at different tolerances (e.g., tighter tolerance as `i` increases).
I am using (Julia's) C interface and perform the following steps:
- Create GRB environment with `GRBloadenv` with tolerance `tol1`
- Create a model with `GRBnewmodel` based on this enviornment
- Add initial variables and constraints to my model to define `P^1`
- Solve `P^1` to tolerance `tol1`
- Add constraints to my model to define `P^2`
- Solve `P^2` to tolerance `tol1`
- continue...
but I would like to adjust the tolerance in step 6 to `tol2`. One way to do this would be to create a new model based on a new environment with the desired `tol2`. However, if I understand correctly, this would involve building a new model from scratch, which in my case is not insignificant.
So my question is: is there a suggested way for solving related problems with different tolerances? Can I modify the parameters of an environment? When I try modifying the intermediate tolerance `error = GRBsetdblparam(env, "BarConvTol", toli)`, I receive the warning
Warning: parameter changes on this environment will not affect existing models.
which then results in a segfault.
Thanks,
Jake
-
From the documentation for GRBnewmodel:
Note that the new model will get a copy of this environment, so subsequent modifications to the original environment (e.g., parameter changes) won't affect the new model. Use GRBgetenv to modify the environment associated with a model.
Have you tried setting the BarConvTol parameter for environment \(\texttt{GRBgetenv(model)}\) instead of \(\texttt{env}\)?
error = GRBsetdblparam(GRBgetenv(model), "BarConvTol", toli);
I'm also curious about the segfault. Do you have a minimal, self-contained code example that reproduces the segfault?
1 -
Ah thanks so much for the fast reply and info on correct usage. It seems that I didn't understand the relationship between \(\texttt{env}\) and \(\texttt{model}\). Your snippet is now working for me! It might be a moot point now, but let me see if I can get an MWE later today.
0 -
I have a (not-so minimal) MWE, but the code is a bit cumbersome to share here and the formatting is lost in the code block. Is there an alternative way to share it? Although, interestingly, it only seems to be failing for Gurobi v10.0
0
Please sign in to leave a comment.
Comments
3 comments