# Fixing the amount of variable in Gurobi - Python as a parameter for another model

I have solved a very simple mathematical model ( 2 variables) using Gurobi in Python and now I want to fix the amount of the variable in another model and solve it, for example, consider the variable $$x_2$$ is solved and it is equal to $$2$$, and now I want to add it to another mathematical programming as an input (parameter) the problem is, Gurobi expects the $$x_2$$ to be a variable, not a parameter wich finally gives the error "Variable not in model", I would appreciate it if anyone can help me with this issue.

• What I can suggest is to define $x_2$ in the second model as a parameter, rather than a variable. If you post the code we can see how you are doing this and help you. – Mostafa Feb 6 at 13:31

Let $$x_2^1$$ be the variable in the first model, and $$x_2^2$$ be the corresponding variable in the second model. Also, let $$\hat{x}_2^1$$ be the optimal value of $$x_2^1$$, after solving the first model.
So if you want to add the optimal value of $$x_2^1$$ in the second model, use the constraint $$x_2^2 = \hat{x}_2^1$$