This series of articles will show you how to use Pyomo's ability to integrate Python to model and optimize your application. The first article in this series will introduce http://www.aliyun.com/zixun/aggregation/22929.html "> basics. Part 2nd will describe how to add more tools and build a scalable architecture. Part 3rd will provide practical examples of investment analysis and statistical analysis using IPython and pandas.
Modeling is a powerful way to solve complex problems. Based on the description of the book Modeling Languages in Mathematical optimization (see Resources), the model is used to:
Interpretation of the phenomenon to predict the critical factors to identify the limit analysis compromise method
In the industry, spreadsheet software such as Microsoft®excel is often the first choice for modeling problems. Spreadsheets are now often very intuitive, but they have limitations in solving large problems. If you are a developer, you may find it more efficient to write scripts to solve modeling problems because you can easily integrate scripts into other systems. This article will introduce the basics of using the Pyomo library to achieve linear optimization in Python applications.
Started
First, install the Pyomo. Pyomo is a central component of COOPR, and Coopr is a collection of Python software packages. You can download the Coopr_install script, which creates a Python virtual environment when you run it with the Python interpreter.
Create a relative directory named "COOPR":
noahs-macbook-air% python Coopr_install
Start Pyomo with the following command, which places the relative directory and its executable file in your path:
noahs-macbook-air% Source Coopr/bin/activate
Use the Pyomo--help command to get help using Pyomo:
(COOPR) noahs-macbook-air% Pyomo--help
You need a compiler to use the virtual Python Environment Builder (VIRTUALENV) and Pyomo. On OS X, use the XCode Developer Tools command line tool. On Linux, use the GNU Compiler Collection (GCC). After initializing this virtual environment, you can use Pyomo to solve the problem in one of the following two ways:
Use the Pyomo command-line tool: (COOPR) noahs-macbook-air% Pyomo my_problem.py--solver=glpk or, embed the initialization code in your script and run it through the Python interpreter:
Listing 1. Call Pyomo in a script
#This is a optional code path that allows the script to be run Òoutsideó Of#pyomo command-line. For Example:python wyndor.pyif __name__ = ' __main__ ': #This replicates what the Pyomo command-line tools does from coopr.opt Import solverfactory opt = solverfactory ("glpk") instance = model.create () results = Opt.solve (instance) #sends results to StdOut Results.write ()
Pyomo assume that you have at least one solution (Solver) installed. The GNU Linear programming Kit (GLPK) is the default solution. See the installation instructions for the solution you want to use. Then make sure Pyomo can find the solution on its path.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.