Reputation: 1
I have a non-linear non-convex optimization problem to solve using Pyomo. When I was working on the problem, there are several questions that I encountered:
When using multistart ipopt to solve for a "global" optima (increasing the chances for a global solution probably although I am aware that ipopt returns local optima), I noticed that Pyomo returns optimal results with some constraints violated. Specifically, I defined the constraints in two ways: 1) using expr = (lower bound, y, upper bound) in Pyomo Constraint, where y represents invoking a function involving defined Pyomo Vars (x_i 's), i.e., y = f(x_i 's), and 2) defining a calculated variable y as another bounded Pyomo Var and placing y = f(x_i 's) as a hard equality in Pyomo Constraint. Both scenarios have the define constraints violated sometimes, which is not my expected result. Any suggestions to achieve optimization results without the defined constraints violated?
In my problem, I also tried to use Baron for non-linear non-convex global optimization solution. However, Baron seems to complain about using Pyomo expr_if expressions. Since there are if-else-condition-based expressions defined in my optimization problem, Baron did not exit the optimization normally. I tried to convert expr_if into standard if-else conditions, but it popped up the following errors:
This error is usually caused by using a Var, unit, or mutable Param in a
Boolean context such as an "if" statement, or when checking container
membership or equality. For example,
>>> m.x = Var()
>>> if m.x >= 1:
... pass
and
>>> m.y = Var()
>>> if m.y in [m.x, m.y]:
... pass
would both cause this exception.
So I used Pyomo value method to evaluate the value of the expression just in time, however, it returns infeasible optimization results, meaning that optimization results are not consistent with my manual calculation even if I configured the optimized decision variables returned from Baron. Want to ask any suggestions/best practices to troubleshoot this kind of problem?
I am still new to Pyomo and learning.
# get_density is a density calculation function based on defined decision variables.
# Scenario 1
self.model.stream1_density_con = pyomo.Constraint(expr=(lower_bound_value, self.get_pb_density("stream1"), None))
# Scenario 2
self.model.stream1_density = pyomo.Var(domain=pyomo.NonNegativeReals, bounds=[lower_bound_value, None])
self.model.stream1_density_con = pyomo.Constraint(expr=(self.model.stream1_density == self.get_density("stream1")))
Pyomo Solver
options = {
"bound_relax_factor": 0,
"halt_on_ampl_error": "yes",
"tol": 1.0e-12,
"constr_viol_tol": 1.0e-5,
"acceptable_constr_viol_tol": 1.0e-5,
"honor_original_bounds": "yes"
}
opt = pyomo.SolverFactory("multistart")
solver = opt.solve(
self.model,
solver="ipopt",
strategy="rand",
suppress_unbounded_warning=True,
solver_args={"options": options},
iterations=200
)
Errors and warning when running
ERROR: Unable to clone Pyomo component attribute. Component
'receipt_variables_index' contains an uncopyable field '_init_values'
(<class 'pyomo.core.base.set.TuplizeValuesInitializer'>)
WARNING: Loading a SolverResults object with a warning status into
model.name="unknown";
- termination condition: maxIterations
- message from solver: Ipopt 3.11.1\x3a Maximum Number of Iterations
Exceeded.
I am not quite sure how to avoid the errors and warnings even though the optimization could run through and meaningful results are returned.
Upvotes: 0
Views: 597
Reputation: 11903
You have about 17 questions packed into one there, so you may need to add some focus to this question or ask separate questions.
Also, if you are getting errors (or what you think are constraint violations) it is most helpful if you provide the exact code that generates the error in a minimally reproducible example.
A proper solution from ipopt
or other solver will not violate constraints. So either (a) the solver returned some error (infeasible, unbounded, etc.) and in that case the results are junk. Did you check the solver status? Or (b) your constraint isn't constructed properly.
In pyomo
and most other frameworks, you cannot make an if statement as part of an expression that is dependent on the value of a variable. The values of the variables are unknown when the model is constructed, and that is all pyomo
is doing.... constructing and handing the legal equations over to a solver. You will need to reformulate your model to exclude such statements, probably adding "indicator variables" or other LP concepts.
Upvotes: 2