I have recently started in doing some OR, and have been trying to use Pyomo and NEOS to do some optimation problems. I have been following along with one of the UT Austin Pyomo lectures, and when my GLPT was being difficult to be installed, I moved on to NEOS. I am having some difficulty in now receiving a solved answer from NEOS.
What I have so far is this:
from pyomo import environ as pe import os os.environ['NEOS_EMAIL'] = 'my registered email' model = pe.ConcreteModel() model.x1 = pe.Var(domain=pe.Binary) model.x2 = pe.Var(domain=pe.Binary) model.x3 = pe.Var(domain=pe.Binary) model.x4 = pe.Var(domain=pe.Binary) model.x5 = pe.Var(domain=pe.Binary) obj_expr = 3 * model.x1 + 4 * model.x2 + 5 * model.x3 + 8 * model.x4 + 9 * model.x5 model.obj = pe.Objective(sense=pe.maximize, expr=obj_expr) con_expr = 2 * model.x1 + 3 * model.x2 + 4 * model.x3 + 5 * model.x4 + 9 * model.x5 <= 20 model.con = pe.Constraint(expr=con_expr) solver_manager = pe.SolverManagerFactory('neos') results = solver_manager.solve(model, solver = "minos") print(results)
What I receive in return is number of solutions = 0, while I know for a fact that one exits. I also see that I don’t have any bounds set, so how would I go about doing that? Once again, I am very new to this, and have not been able to find any sort of documentation regarding this elsewhere, or perhaps I just don’t know how to look.
Thanks for any help!
Advertisement
Answer
This is a “problem” with the design of the current results object. For historical reasons, that field reports the number of solutions contained in the results object and is not the number of solutions generated by the solver. By default, Pyomo solvers directly load the solution returned by the solver into the original model (both for convenience and efficiency) and do not return it in the results object. You can change that behavior by providing load_solutions=False
to the solve()
call.
As for the bounds, what bounds are you referring to? Variable bounds are set using either the bounds=
argument to the Var()
declaration, or the domain=
argument. For your example, because the variables are declared to be Binary
, they all have bounds of [0..1]
. Bounds on the objective are gathered by parsing the solver output. This is dependent on bother the solver that you are using (many do not report bounds information), and the interface used to parse the solver results.
As a final note, you are sending a MIP problem to a LP/NLP solver (minos). You will get fractional valies for your binary variables back from the solver.