2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ – Mostafa Feb 6 at 13:31
2
$\begingroup$

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 $$

$\endgroup$
1
  • $\begingroup$ Thanks for answering, the point is, it actually expects x22 being implemented as something in the model, if I implement it as a variable, it gives an error of not being a PSD ( Positive Semi Definite ), because the structure is somehow Nonlinear, so now I want to add it as a parameter in the model, and I don't know-how. $\endgroup$ – ehsan mirzaei Feb 6 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.