-->

AbstractModel VS ConcreteModel of pyomo? how does

2019-08-18 09:07发布

问题:

I have an AbstractModel and a ConcreteModel solving the same problem, but they are performing differently. It is mainly about initial value of a variable and tolerance of ipopt.

  1. When I initialize my variable model.x as 10 and opt.options["tol"] = 1E-64: ConcreteModel can find optimal solution, while abstract model "Solved To Acceptable Level". (But the solutions they find are actually the same)

  2. When I initialize my variable model.x as 100 and opt.options["tol"] = 1E-64: ConcreteModel can find the optimal solution, while abstract model sometimes "Solved To Acceptable Level" and sometimes "Cannot load a SolverResults object with bad status: error".

  3. If I just use the ipopt's default value of the tolerance, both ConcreteModel and AbstractModel can find the same optimal solution no matter how I initialize the variable model.x.

So I wonder how opt.options["tol"] makes a difference? Why is ConcreteModel always able to find an optimal solution in this case while AbstractModel not?

Variable

model.x = Var(model.Crops, model.Inputs, initialize = 100, within=NonNegativeReals)

solve script of AbstractModel

instance = model.create_instance(data="AbstractCDFarm.dat")
opt = SolverFactory("ipopt")
opt.options["tol"] = 1E-64
results = opt.solve(instance, tee=True) 
instance.display()

solve script of ConcreteModel

opt = SolverFactory('ipopt')
opt.solve(model, tee=True) 
opt.options["tol"] = 1E-64
results = opt.solve
model.display()

回答1:

You're calling solve twice for the ConcreteModel and it looks like the output you're seeing is for the default Ipopt tolerance not for the tolerance of 1E-64. Why are you setting such a low tolerance? 1E-64 is smaller than machine precision so it's an impossibly small tolerance to converge to.