How do I reset a variable value in a loop?

I am not sure what you really want to do, but I assume you like to solve the model three times for different values of parameter k. If so, you could simply put

model = Model(CPLEX.Optimizer)

inside the for-loop.

If you declare the model outside, clearly, in the second iteration of the for-loop the variables and constraints already exist in your model which causes the error message.

2 Likes