Describe the bug
The behavior of the function model.get_var_by_name() is unexpected when using Gurobi as solver. According to the docstring, the function should return None if no variable with that name exists. However, when using it with Gurobi, I get an error ParameterNotAvailable when using the function on a model without any variables.
To Reproduce
- Create an instance of a model with Gurobi as solver
- Use the
model.var_by_name(name="randomname") function.
model = mip.Model(solver_name=mip.GUROBI)
variable = model.var_by_name(name="variablename")
Expected behavior
From the docstring, None should be returned.
Desktop (please complete the following information):
- Operating System, version: WSL2 on Windows 11
- Python version: 3.13.11
- Python-MIP version (we recommend you to test with the latest version):
Additional context
The behavior of Gurobi is different than for example HiGHS here, which does not throw the error. In my opinion the behavior of Model.var_by_name() should not be solver dependent.
The exact same problem exists for the constraint version of this function, namely model.constrs_by_name()
Describe the bug
The behavior of the function
model.get_var_by_name()is unexpected when using Gurobi as solver. According to the docstring, the function should return None if no variable with that name exists. However, when using it with Gurobi, I get an errorParameterNotAvailablewhen using the function on a model without any variables.To Reproduce
model.var_by_name(name="randomname")function.Expected behavior
From the docstring, None should be returned.
Desktop (please complete the following information):
Additional context
The behavior of Gurobi is different than for example HiGHS here, which does not throw the error. In my opinion the behavior of
Model.var_by_name()should not be solver dependent.The exact same problem exists for the constraint version of this function, namely
model.constrs_by_name()