Stylesheet style.css not found, please contact the developer of "arctic" template.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
personal:blog:2014:0904_pyomo_for_gams_users [2015/01/12 14:35] – [Creation of the Model] antonellopersonal:blog:2014:0904_pyomo_for_gams_users [2025/05/02 09:41] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== A Pyomo tutorial for GAMS users ====== ====== A Pyomo tutorial for GAMS users ======
 +
 +**Updates:**
 +
 +  * **2015.01.12: Updated to run under Pyomo 4. See previous revisions if you still use Pyomo 3.**
 +
 +
  
 [[https://software.sandia.gov/trac/coopr|Pyomo]] (Python Optimisation Modeling Object) is an Algebraic Modelling Language (AML) that allows to write optimisation problems using a concise mathematical formulation, acting as interface to the specific solver engine API. For non-linear optimisation problems it allows to keep a high-level approach that doesn't require the modeller to compute the Jacobian or the Hessian.\\ [[https://software.sandia.gov/trac/coopr|Pyomo]] (Python Optimisation Modeling Object) is an Algebraic Modelling Language (AML) that allows to write optimisation problems using a concise mathematical formulation, acting as interface to the specific solver engine API. For non-linear optimisation problems it allows to keep a high-level approach that doesn't require the modeller to compute the Jacobian or the Hessian.\\
Line 22: Line 28:
 ===== Installation ===== ===== Installation =====
  
-**Important: Pyomo requires python 2.x. While python 3.x support is work in progress, at the moment only python 2.x is supported.**+**<del>Important: Pyomo requires python 2.x. While python 3.x support is work in progress, at the moment only python 2.x is supported.</del>** 
 + 
 +//This isn't true any more with Pyomo 4, where support for Python 3.x has been added..//
  
 ==== Ubuntu ==== ==== Ubuntu ====
Line 129: Line 137:
 def demand_rule(model, j): def demand_rule(model, j):
   return sum(model.x[i,j] for i in model.i) >= model.b[j]     return sum(model.x[i,j] for i in model.i) >= model.b[j]  
-model.demand = Constraint(model.j, doc='Satisfy demand at market j')+model.demand = Constraint(model.j, rule=demand_rule, doc='Satisfy demand at market j')
 </code> </code>
 The above code take advantage of [[https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions|List Comprehensions]], a powerful feature of the python language that provides a concise way to loop over a list. The above code take advantage of [[https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions|List Comprehensions]], a powerful feature of the python language that provides a concise way to loop over a list.
Line 180: Line 188:
 If you want advanced features and debugging capabilities you can use a dedicated Python IDE, like e.g. [[https://code.google.com/p/spyderlib/|Spyder]]. If you want advanced features and debugging capabilities you can use a dedicated Python IDE, like e.g. [[https://code.google.com/p/spyderlib/|Spyder]].
  
-You will normally run the script as ''pyomo --solver=glpk transport.py''. You can output solver specific output adding the option ''--stream-output''.\\+You will normally run the script as ''pyomo solve --solver=glpk transport.py''. You can output solver specific output adding the option ''--stream-output''.\\
 If you want to run the script as ''python transport.py'' add the following lines at the end:\\ If you want to run the script as ''python transport.py'' add the following lines at the end:\\
 <code python> <code python>
Line 187: Line 195:
 if __name__ == '__main__': if __name__ == '__main__':
     #This replicates what the pyomo command-line tools does     #This replicates what the pyomo command-line tools does
-    from coopr.opt import SolverFactory +    from pyomo.opt import SolverFactory 
-    import coopr.environ+    import pyomo.environ
     opt = SolverFactory("glpk")     opt = SolverFactory("glpk")
     instance = model.create()     instance = model.create()
personal/blog/2014/0904_pyomo_for_gams_users.1421073329.txt.gz · Last modified: (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0