martinbiel / StochasticPrograms.jl

Julia package for formulating and analyzing stochastic recourse models.
MIT License
75 stars 25 forks source link

Solver hangs even when dual and primal problem gaps are set #36

Closed victorgarcia98 closed 2 years ago

victorgarcia98 commented 2 years ago

Hi Martin, last week I've been working on a stochastic program using the L-Shaped implementation that you made. I've encountered an issue related with the issue #34, the optimization is not finishing, getting frozen, even when the gap is lower than one defined. I add the code snippet + the L-Shaped last status, I hope it is useful.

  set_optimizer_attribute(model, PrimalTolerance(), 1e-1)
  set_optimizer_attribute(model, DualTolerance(), 1e-1)

  sp = instantiate(model, program.scenarios, optimizer=LShaped.Optimizer)

  set_optimizer_attribute(sp, MasterOptimizer(),  GLPK.Optimizer)
  set_optimizer_attribute(sp, SubProblemOptimizer(),  GLPK.Optimizer)

  set_optimizer_attribute(sp, IntegerStrategy(), Convexification(strategy = Gomory()))
  set_optimizer_attribute(sp, FeasibilityStrategy(), FeasibilityCuts())

  StochasticPrograms.optimize!(sp)
L-Shaped Gap  Time: 0:03:35 (34 iterations)
  Objective:       40.998703442835755
  Gap:             1.7330858687984428e-16
  Number of cuts:  330
  Iterations:      34

Thanks in advanced 😄

martinbiel commented 2 years ago

For L-shaped, the relevant attribute you should set is RelativeTolerance. It should be set after instantiation (I should probably show an error message if you try to set these on the model object). So adding set_optimizer_attribute(sp, RelativeTolerance(), 1e-1 should do what you want. Sorry for the confusion.

martinbiel commented 2 years ago

Also, the reason for the procedure not finishing is that you are running an integer program. When the gap reaches the chosen relative tolerance, the algorithm will continue with the convexification procedure until the second-stage solution is integer where required. This could probably be reflected better in the printout. Note that the integer extensions available are experimental, so there are probably more usability issues and unsolvable instances.

victorgarcia98 commented 2 years ago

Oh, you were totally right! Removing the 2nd stage problem integer variables made the L-shape to converge. Thanks a lot Martin!