I am doing a loop across year, and for each year I solve an optimization problem. Inside the loop I do:
#Optimization
opt = SolverFactory("ipopt")
results = opt.solve(model3 , keepfiles=False, load_solutions=False)
model3.solutions.load_from(results)
The program works well, but I am having some times (randomly) this problem:
File "", line 47, in results = opt.solve(model3 , keepfiles=False, load_solutions=False)
File "C:\Users\escriva\AppData\Local\Continuum\anaconda3\lib\site-packages\pyomo\opt\base\solvers.py", line 631, in solve result = self._postsolve()
File "C:\Users\escriva\AppData\Local\Continuum\anaconda3\lib\site-packages\pyomo\opt\solver\shellcmd.py", line 282, in _postsolve os.remove(self._soln_file)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\escriva\tmpc2aly83o.pyomo.sol'
Then, I run it again and it works, but it breaks again (randomly) several years later. I think that it's related to the next iteration of the optimization having problems because the past optimization is not totally cleared up.
Any help?
Thanks so much in advance!