Fixing and unfixing a series of variables before a second solve

Good afternoon,

Lately I have been working on a model that requires me to, after a first optimization, fix a series of variables and unfix some according to a certain condition and after that, perform a second solve.

During testing, after fixing some variables to value 0 then unfixing those variables that meet the requirements to be restored for the second solve, they keep their fixed value (0) instead of participating in the optimization.

Is there a problem with fixing and then unfixing values? Is there a way to check if the conditions I am setting for the unfix sentence are correct and AMPL is not discarding them, or that maybe I am setting fixes that are too strict?

Thank you so much for your help,

marnie2k

I would begin by checking that the second solve returns an “optimal solution” message from the solver. If not, the second problem may not have any feasible solution, or some non-optimal termination condition may be indicated. If you need more help, post the complete result message from the solver.

If the solver does indicate that it found an optimal solution to the second solve, then here are some other things to consider:

  • The unfixed variables might actually be zero in at least one optimal solution. (There can be more than one solution that is optimal.) How can you tell that the unfixed variables have to be positive in all optimal solutions?
  • If you are defining “named problems” for your AMPL model, they also use fix and unfix, with results that can be different from what you expect.
  • Just before and just after solving, you can use the suffix .astatus on variables to determine whether they properly have the status of fix (fixed) or in (not fixed).

To get further help, it will be helpful if you can share the AMPL model and the AMPL script or amplpy program that you are running.