Pyomo is a popular Python library for formulating and solving optimization problems. It uses an object-oriented approach where variables, objective functions, and constraints are defined as attributes of model classes (e.g., model.x = Var(), model.obj = Objective(expr=…), model.con1 = Constraint(expr=…)). This approach provides a structured and modular way to define and solve complex optimization problems. However, I am curious about how one could structure a similar optimization program using only functions and avoiding classes entirely. Is it possible to maintain the same functionality with a function-based approach? How would one go about defining variables, the objective function, and constraints purely with functions, and then solve the model? What are the implications in terms of simplicity, modularity, structure, scalability, performance, and functionality compared to the class-based approach used by Pyomo? Any insights or examples would be greatly appreciated!
I have considered defining variables, objectives, and constraints as entries in dictionaries and lists, and then using functions to manipulate these data structures. I expected this approach to be simpler and more intuitive for those not familiar with object-oriented programming. However, I am concerned about how well this method would scale for more complex models and whether it would maintain the same level of functionality and performance as the class-based approach. I am looking for insights, potential pitfalls, and examples from those who might have tried a similar approach or have experience in designing optimization frameworks.
elo98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.