Table Of ContentSpringer Optimization and Its Applications 67
William E. Hart
Carl D. Laird
Jean-Paul Watson
David L. Woodruf
Gabriel A. Hackebeil
Bethany L. Nicholson
John D. Siirola
Pyomo —
Optimization
Modeling
in Python
Second Edition
Springer Optimization and Its Applications
VOLUME 67
Managing Editor
Panos M. Pardalos (University of Florida)
Editor–Combinatorial Optimization
Ding-Zhu Du (University of Texas at Dallas)
AdvisoryBoard
J.Birge(UniversityofChicago)
S. Butenko (Texas A&M University)
F.Giannessi(UniversityofPisa)
H.D.Sherali(VirginiaPolytechnicandStateUniversity)
T.Terlaky(LehighUniversity)
Y.Ye(StanfordUniversity)
Aims and Scope
Optimization has been expanding in all directions at an astonishing rate
during the last few decades. New algorithmic and theoretical techniques
have been developed, the diffusion into other disciplines has proceeded at a
rapid pace, and our knowledge of all aspects of the field has grown evenmore
profound. At the same time, one of the most striking trends in optimization
is the constantly increasing emphasis on the interdisciplinary nature of the
field. Optimization has been a basic tool in all areas of applied mathematics,
engineering, medicine, economics, and other sciences.
The series Springer Optimization and Its Applications publishes under-
graduate and graduate textbooks, monographs and state-of-the-art exposi-
tory work that focus on algorithms for solving optimization problems and
also study applications involving such problems. Some of the topics covered
include nonlinear optimization (convex and nonconvex), network flow
problems, stochastic optimization, optimal control, discrete optimization,
multi-objective programming, description of software packages, approxima-
tion techniques and heuristic approaches.
More information about this series at http://www.springer.com/series/7393
William E. Hart • Carl D. Laird
Jean-Paul Watson • David L. Woodruff
Gabriel A. Hackebeil • Bethany L. Nicholson
John D. Siirola
Pyomo — Optimization
Modeling in Python
Second Edition
William E. Hart Carl D. Laird
Sandia National Laboratories Sandia National Laboratories
Albuquerque, New Mexico, USA Albuquerque, New Mexico, USA
Jean-Paul Watson David L. Wodruf
Sandia National Laboratories Graduate School of Management
Albuquerque, New Mexico, USA University of California, Davis
Davis, California, USA
Gabriel A. Hackebeil
Department of Industrial Bethany L. Nicholson
and Operations Engineering Sandia National Laboratories
University of Michigan Albuq uerq ue, New Mexic o, USA
Ann Arbor, Michigan, USA
John D. Siirola
Sandia National Laboratories
Albuquerque, New Mexico, USA
ISSN 1931-6828 ISSN 1931-6836 (electronic)
Springer Optimization and its Applications
ISBN 978-3-319-58819-3 ISBN 978-3-319-58821-6 (eBook)
DOI 10.1007/978-3-319-58821-6
Library of Congress Control Number: 2017940404
© Springer International Publishing AG 2012, 2017
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of
the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or
information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this
publication does not imply, even in the absence of a specific statement, that such names are exempt
from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this
book are believed to be true and accurate at the date of publication. Neither the publisher nor the
authors or the editors give a warranty, express or implied, with respect to the material contained herein
or for any errors or omissions that may have been made. The publisher remains neutral with regard to
jurisdictional claims in published maps and institutional affiliations.
Printed on acid-free paper
This Springer imprint is published by Springer Nature
The registered company is Springer International Publishing AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
This book is dedicated to future contributors
to the Pyomo project.
Preface
This book describes a tool for mathematical modeling: the Python Optimization
Modeling Objects (Pyomo) software. Pyomo supports the formulation and analysis
of mathematical models for complex optimization applications. This capability is
commonly associated with algebraic modeling languages (AMLs), which support
the description and analysis of mathematical models with a high-level language.
Although most AMLs are implemented in custom modeling languages, Pyomo’s
modeling objects are embedded within Python, a full-featured high-level program-
ming language that contains a rich set of supporting libraries.
Modeling is a fundamental process in many aspects of scientific research, engi-
neering and business, and the widespread availability of computing has made the
numerical analysis of mathematical models a commonplace activity. Furthermore,
AMLs have emerged as a key capability for robustly formulating large models for
complex, real-world applications [53]. AMLs streamline the process of formulating
models by simplifying the management of sparse data and supporting the natural ex-
pression of model components. Additionally, AMLs like Pyomo support scripting
with model objects, which facilitates the custom analysis of complex problems.
The core of Pyomo is an object-oriented capability for representing optimization
models. Pyomo also contains packages that define modeling extensions and model
reformulations. For example, the pyomo.pysp package defines modeling exten-
sions for stochastic programs as well as solvers that can analyze these problems.
Pyomo also includes packages that define interfaces to solvers like CPLEX and
Gurobi, as well as solver services like NEOS.
Goals of the Book
This second edition provides an updated description of Pyomo’s modeling capabil-
ities. A key goal of this book is to provide a broad description of Pyomo that will
enable the user to develop and optimize models with Pyomo. The book uses many
examples to illustrate different techniques that can be used to formulate models.
vii
viii Preface
Another goal of this book is to illustrate the breadth of Pyomo’s capabilities. Py-
omo supports the formulation and analysis of common optimization models, includ-
ing linear programs, mixed-integer linear programs, nonlinear programs, mixed-
integer nonlinear programs, mathematical programs with equilibrium constraints,
generalized disjunctive programs, bilevel programs, and stochastic programs. Addi-
tionally, Pyomo includes solver interfaces for a variety of widely used optimization
software packages, including CBC, CPLEX, GLPK, and Gurobi. Additionally, Py-
omo models can be optimized with optimizers like IPOPT that employ the AMPL
Solver Library interface.
Finally, a goal of this book is to help users get started with Pyomo even if
they have little knowledge of Python. Appendix A provides a quick introduction
to Python, but we have been impressed with how well Python reference texts sup-
port new Pyomo users. Although Pyomo introduces Python objects and a process
for applying them, the expression of models with Pyomo strongly reflects Python’s
clean, concise syntax.
However, our discussion of Pyomo’s advanced modeling capabilities assumes
some background in object-oriented design and features of the Python program-
ming language. For example, our discussion of modeling components distinguishes
between class definitions and class instances. We have not attempted to describe
these advanced features of Python in the book. Thus, a user should expect to develop
some familiarity with Python in order to effectively understand and use advanced
modeling features.
Who Should Read This Book
This book provides a reference for students, academic researchers and practitioners.
The design of Pyomo is simple enough that it has been effectively used in the class-
room with undergraduate and graduate students. However, we assume that the reader
is generally familiar with optimization and mathematical modeling. Although this
book does not contain a glossary, we recommend the Mathematical Programming
Glossary [45] as a reference for the reader.
Pyomo is also a valuable tool for academic researchers and practitioners. A key
focus of Pyomo development has been on the ability to support the formulation and
analysis of real-world applications. Consequently, issues like run-time performance
and robust solver interfaces are a priority.
Additionally, we believe that researchers will find that Pyomo provides an ef-
fective framework for developing high-level optimization and analysis tools. For
example, Pyomo provides generic solvers for stochastic programming, and it lever-
ages the fact that Pyomo’s modeling objects are embedded within a full-featured
high-level programming language. This allows for transparent parallelization of
sub-problems using Python parallel communication libraries. This ability to sup-
port generic solvers for complex models is very powerful, and we believe that it can
be used with many other optimization analysis techniques.
Preface ix
Revisions for the Second Edition
We have made several major changes while preparing the second edition of this
book. The book was divided into two parts: (1) chapters that provide an introduc-
tion to optimization and Pyomo, and (2) chapters that describe advanced features
and extensions. The introductory chapters were revised to provide a more tutorial
description. In particular, reference material was removed from the first edition,
which will be provided online at the Pyomo website. The chapters describing ad-
vanced features were extended to include new functionality added to Pyomo since
the first edition, including generalized disjunctive programming, mathematical pro-
gramming with equilibrium constraints, and bilevel programming.
Comments and Questions
This book documents the capabilities of the Pyomo 5.1 release. Most examples in
the book work with Pyomo 5.0, but some errors in Pyomo DAT file processing were
resolved in the Pyomo 5.1 release. Further information is available on the Pyomo
website:
http://www.pyomo.org
Pyomo’s open source software is hosted at GitHub:
https://github.com/Pyomo/pyomo
We encourage feedback from readers, either through direct communication with
the authors or with the Pyomo Forum:
Acknowledgments
We are grateful for the efforts of many people who have supported both editions
of this book. We thank Elizabeth Loew at Springer for helping shepherd this book
from an initial concept to final production; her enthusiasm for publishing is con-
tagious. Also, we thank Madelynne Farber at Sandia National Laboratories for her
guidance with the legal process for releasing open source software and book pub-
lishing. Finally, we thank Doug Prout for developing the Pyomo, PySP and Coopr
logos.
We are indebted to our reviewers for the time and effort they put into helping
this book be successful. Without them, this book would contain many typos and
software bugs. So, thanks to Jack Ingalls, Zev Friedman, Harvey Greenberg, Sean
Legg, Angelica Wong, Daniel Word, Deanna Garcia, and Ellis Ozakyol. Special
thanks to Amber Gray-Fenner.
We are particularly grateful to the growing community of Pyomo users. Your
interest and enthusiasm for Pyomo was the most important factor in our decision
to write this book. We thank the early adopters of Pyomo who have provided
detailed feedback on the design and utility of the software, including Fernando
Badilla, Steven Chen, Ned Dmitrov, YueYue Fan, Eric Haung, Allen Holder, An-
dres Iroume, Darryl Melander, Carol Meyers, Pierre Nancel-Penard, Mehul Rang-
wala, Eva Worminghaus and David Alderson. Your feedback continues to have a
major impact on the design and capabilities of Pyomo.
We also thank our friends in the COIN-OR project for supporting the Pyomo
software. Although the main development site for Pyomo is hosted at GitHub, our
partnership with COIN-OR is a key part of our strategy to ensure that Pyomo re-
mains a viable open source software project.
A special thanks goes to our collaborators who have contributed to packages in
Pyomo: Francisco Mun˜oz, Timothy Ekl, Kevin Hunter, Patrick Steele, and Daniel
Word. We also thank Tom Brounstein, Dave Gay, and Nick Benevidas for helping
develop Python modules and documentation for Pyomo.
The authors gratefully acknowledge this support that contributed to the devel-
opment of this book: National Science Foundation under Grant CBET#0941313
and CBET#0955205, and the Office of Advanced Scientific Computing Research
xi
xii Acknowledgments
within the DOE Office of Science, the U.S. Department of Energy ARPA-E under
the Green Electricity Network Integration program, and the Institute for the Design
of Advanced Energy Systems (IDAES) with funding from the Office of Fossil En-
ergy, Cross-Cutting Research, U.S. Department of Energy. This book was supported
in part by Sandia National Laboratories. Sandia National Laboratories is a multi-
mission laboratory managed and operated by Sandia Corporation, a wholly owned
subsidiary of Lockheed Martin Corporation, for the U.S. Department of Energy’s
National Nuclear Security Administration under contract DE-AC04-94AL85000.
And finally, we would like to thank our families and friends for putting up with
our passion for optimization software.