Using Pyomo to solve complex problems

Source: Internet
Author: User

Brief introduction

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:

Explain the phenomenon

To predict

Assess key factors

Identification limit

Analyze Compromise methods

In the industry, spreadsheet software such as Microsoft Excel is often the primary choice for modeling issues. 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.

Entry

The first step is to install 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 using 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:

To use the Pyomo command line tool:

(COOPR) noahs-macbook-air% Pyomo my_problem.py--solver=glpk

Alternatively, 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.py
if __name__ = ' __main__ ':
       
    #This replicates what the Pyomo command-line tools do Es 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 that the Pyomo can find the solution on its path.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.