+ All Categories
Home > Documents > Springer Optimization and Its...

Springer Optimization and Its...

Date post: 08-Jun-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
15
Transcript
Page 1: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,
Page 2: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

For further volumes:http://www.springer.com/series/7393

Springer Optimization and Its Applications

VOLUME 67

Managing EditorPanos M. Pardalos (University of Florida)

Editor–Combinatorial OptimizationDing-Zhu Du (University of Texas at Dallas)

Advisory BoardJ. Birge (University of Chicago)C.A. Floudas (Princeton University)F. Giannessi (University of Pisa)H.D. Sherali (Virginia Polytechnic and State University)T. Terlaky (Lehigh University)Y. Ye (Stanford University)

Aims and ScopeOptimization has been expanding in all directions at an astonishing rateduring the last few decades. New algorithmic and theoretical techniqueshave been developed, the diffusion into other disciplines has proceeded ata 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 opti-mization is the constantly increasing emphasis on the interdisciplinary na-ture of the field. Optimization has been a basic tool in all areas of appliedmathematics, 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 andalso study applications involving such problems. Some of the topics coveredinclude nonlinear optimization (convex and nonconvex), network flow prob-lems, stochastic optimization, optimal control, discrete optimization, multi-objective programming, description of software packages, approximationtechniques and heuristic approaches.

Page 3: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,
Page 4: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

William E. Hart • Carl Laird • Jean-Paul WatsonDavid L. Woodruff

Pyomo—OptimizationModeling in Python

Page 5: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

permission of the publisher (Springer Science+Business Media, LLC, 233 Spring Street, New York, NY10013, USA), except for brief excerpts in connection with reviews or scholarly analysis. Use in connectionwith any form of information storage and retrieval, electronic adaptation, computer software, or by similaror dissimilar methodology now known or hereafter developed is forbidden.The use in this publication of trade names, trademarks, service marks, and similar terms, even if they arenot identified as such, is not to be taken as an expression of opinion as to whether or not they are subjectto proprietary rights.

Printed on acid-free paper

Springer is part of Springer Science+Business Media (www.springer.com)

ISSN 1931-6828

Springer New York Dordrecht Heidelberg London

ISBN 978-1-4614- - e-ISBN 978-1-4614- -DOI 10.1007/978-1-4614- -

© Springer Science+Business Media, LLC 201All rights reserved. This work may not be translated or copied in whole or in part without the written

L

2

William E. HartData Analysis and Informatics DepartmentSandia National LaboratoriesAlbuquerque, NM [email protected]

Department of Chemical Engineering

USA

Carl Laird

Texas A&MCollege Station, TX 77843

[email protected]

Discrete Mathematics and Complex Systems

Albuquerque, NM 87185USA

USA

Jean-Paul Watson

Department Sandia National Laboratories

[email protected]

David L. WoodruffGraduate School of ManagementUniversity of California, DavisDavis, CA 95616

[email protected]

3225 8 3226 53226 5

ibrary of Congress Control Number: 2012930924

Page 6: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

For Valerie, Christy, Michelle and Barbara.Thank you for your support and patienceduring the many nights and weekends that wehave spent on Pyomo and this book.

Page 7: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,
Page 8: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

Preface

This book describes a new tool for mathematical modeling: the Python OptimizationModeling Objects (Pyomo) software. Pyomo supports the formulation and analysisof mathematical models for complex optimization applications. This capability iscommonly associated with algebraic modeling languages (AMLs), which supportthe description and analysis of mathematical models with a high-level language.Although most AMLs are implemented in custom modeling languages, Pyomo’smodeling 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 resources hasmade the numerical analysis of mathematical models a commonplace activity. Fur-thermore, AMLs have emerged as a key capability for robustly formulating largemodels for complex, real-world applications [40]. AMLs simplify the process offormulating complex models by simplifying the management of sparse data andsupporting the natural expression of model components. Additionally, AMLs likePyomo support scripting with model objects which facilitates rapid development ofnew analysis tools.

vii

Page 9: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

viii Preface

Goals of the Book

In this book, we provide an introduction to the Pyomo modeling software. A keygoal of this book is to provide a comprehensive reference that will enable the user todevelop optimization models with Pyomo. The book contains many example mod-els, and the presentation of Pyomo’s capabilities highlights different techniques thatcan be used to formulate models. The presentation in the book is roughly brokendown into three parts:

1. Introduction - Introducing mathematical modeling and Pyomo, an overview of Pyomo’sdesign, and an illustration of Pyomo with increasingly complex models.

2. Modeling Components - Detailed descriptions of the core modeling components that aresupported by Pyomo.

3. Advanced Capabilities - Presentations of advanced features, including modeling of non-linear and stochastic programs, as well as high-level scripting with Python.

Another goal of this book is to illustrate the breadth of the modeling and anal-ysis capabilities that are supported by Pyomo. Pyomo supports the formulationand analysis of common optimization models, including linear programs, mixed-integer linear programs, nonlinear programs, mixed-integer nonlinear programs andstochastic programs. Additionally, Pyomo includes solver interfaces for a varietyof widely used optimization software packages, including CBC, CPLEX, GLPK,GUROBI, and PICO. Additionally, Pyomo can execute optimizers that employ theAMPL Solver Library interface.

Finally, this book provides the information needed to install and get started withPyomo. Pyomo is a component of the Coopr software project. This book doc-uments the capabilities of the Coopr 3.1 release, which includes version 3.0 ofcoopr.pyomo, which defines Pyomo. Appendix A describes installation optionsfor Coopr. Coopr leverages a variety of third-party Python packages, and installa-tion options described in the appendix include the installation of these auxilliarypackages.

Who Should Read This Book

This book is intended to be a reference for students, academic researchers and prac-titioners. The design of Pyomo is simple enough that it has been effectively usedin the classroom with undergraduate and graduate students. However, we assumethat the reader is generally familiar with optimization and mathematical modeling.Although this book does not contain a glossary, we recommend the MathematicalProgramming Glossary [35] as a reference for the reader.

A goal of this book is to help users get started with Pyomo even if they have littleknowledge of Python. Appendix B provides a quick introduction to Python, butwe have been impressed with how well standard Python reference texts support newPyomo users. Although Pyomo introduces Python objects and a process for applying

Page 10: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

Preface ix

them, the expression of models with Pyomo strongly reflects Python’s clean, concisesyntax.

Note that our discussion of Pyomo’s advanced modeling capabilities assumessome background in object-oriented design and features of the Python program-ming language. For example, our discusion of modeling components distinguishesbetween class definitions and class instances. Similarly, our discussion of Pyomoexpressions requires a description of how operator overloading is used. We havenot attempted to describe these advanced features of Python in the book. Thus, auser should expect to develop some familiarity with Python in order to effectivelyunderstand and use advanced modeling features.

Pyomo is also a valuable tool for academic researchers and practitioners. A keyfocus of Pyomo development has been on the ability to support the formulationand analysis of real-world applications. Pyomo supports our work with complex,real-world applications, so key issues like run-time performance and robust solverinterfaces are a priority.

Additionally, we believe that researchers will find that Coopr provides an effec-tive framework for developing high-level optimization and analysis tools. For ex-ample, Pyomo supports stochastic programming with extensions that are defined inCoopr’s PySP package. PySP provides generic solvers for stochastic programming,and it leverages the fact that Pyomo’s modeling objects are embedded within a full-featured high-level programming language. This allows for transparent paralleliza-tion of sub-problems using Python parallel communication libraries. This ability tosupport generic solvers for complex models is very powerful, and we believe that itcan be used with many other optimization analysis techniques.

Page 11: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

x Preface

Comments and Questions

Further information about Pyomo and Coopr is available on the Coopr wiki:https://software.sandia.gov/trac/coopr

Coopr is also hosted at COIN-OR:https://projects.coin-or.org/Coopr

We strongly encourage feedback from readers, either through direct communica-tion with the authors or with the Coopr Forum:

[email protected]

We hope this will include feedback on typos and errors in our examples. Addition-ally, we welcome comments on the presentation of this material, and suggestionsfor material that we should develop in the other book chapters.

Good Luck!

Albuquerque, New Mexico, USACollege Station, Texas, USAAlbuquerque, New Mexico, USADavis, California, USA

William E. HartCarl Laird

Jean-Paul WatsonDavid L. Woodruff

December, 2011

Page 12: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

Acknowledgements

The development of this book was supported in part by the Office of AdvancedScientific Computing Research within the DOE Office of Science as part of theComplex Interconnected Distributed Systems program. Sandia National Laborato-ries is a multi-program laboratory managed and operated by Sandia Corporation, awholly owned subsidiary of Lockheed Martin Corporation, for the U.S. Departmentof Energy’s National Nuclear Security Administration under contract DE-AC04-94AL85000.

The development of this book was also supported in part by the National ScienceFoundation under Grant CBET#0941313 and CBET#0955205. The authors grate-fully acknowledge this support.

This book would not have been possible without the efforts of many people. Wethank Elizabeth Loew at Springer for helping shepherd this book from an initialconcept to final production; her enthusiasm for publishing is contagious. Also, wethank Madelynne Farber at Sandia National Laboratories for her guidance with thelegal process for releasing open source software and book publishing. Finally, wethank 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 thisbook be successful. Without them, this book would contain many typos and soft-ware bugs. So, thanks to Zev Friedman, Gabriel Hackebeil, Harvey Greenberg, SeanLegg, Angelica Wong, and Daniel Word. Special thanks to Amber Gray-Fenner.

We are particularly grateful to the growing community of Pyomo users. Yourinterest and enthusiasm for Pyomo was the most important factor in our decision towrite this book. We are particularly thankful for the early adopters of Pyomo whohave provided detailed feedback on the design and utility of the software: FernandoBadilla, Steven Chen, Ned Dmitrov, YueYue Fan, Eric Haung, Allen Holder, AndresIroume, Darryl Melander, Carol Meyers, Pierre Nancel-Penard, Mehul Rangwalaand Eva Worminghaus. Your feedback continues to have a major impact on thedesign and capabilities of Pyomo.

We also thank our friends in the COIN-OR project for supporting the Cooprsoftware, which includes Pyomo. Although the main development site for Coopr is

xi

Page 13: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

xii Acknowledgements

hosted at Sandia National Laboratories, our partnership with COIN-OR is a key partof our strategy to ensure that Coopr remains a viable open source software project.

A special thanks goes to our collaborators who have developed Pyomo and otherpackages in Coopr: Timothy Ekl, Gabriel Hackebeil, Kevin Hunter, John Siirola,Patrick Steele, and Daniel Word. We also thank Tom Brounstein, Dave Gay, andNick Benevidas for helping develop Python modules and documentation for Pyomo.

And finally, we would like to thank our families and friends for putting up withour passion for optimization software.

Page 14: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

xiii

Contents

1 Introduction 11.1 Mathematical Modeling . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Modeling Languages for Optimization . . . . . . . . . . . . . . . . 31.3 Modeling Graph Coloring . . . . . . . . . . . . . . . . . . . . . . . 41.4 Motivating Pyomo . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.4.1 Open Source . . . . . . . . . . . . . . . . . . . . . . . . 71.4.2 Customizable Capability . . . . . . . . . . . . . . . . . . 71.4.3 Solver Integration . . . . . . . . . . . . . . . . . . . . . 81.4.4 Modern Programming Language . . . . . . . . . . . . . . 8

1.5 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91.6 Book Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.7 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2 Pyomo Modeling Strategies 132.1 Modeling Components . . . . . . . . . . . . . . . . . . . . . . . . 132.2 Concrete Models: Specifying Components Via Expressions . . . . . 152.3 Concrete Models: Specifying Components Via Rules . . . . . . . . 172.4 Abstract Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.5 Optimizing Models . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.5.1 Optimization with the pyomo Command . . . . . . . . . 192.5.2 Optimization Scripts . . . . . . . . . . . . . . . . . . . . 20

2.6 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.A Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.A.1 Concrete Pyomo Model with Explicit Variables . . . . . . 222.A.2 Concrete Pyomo Model with Indexed Variables . . . . . . 222.A.3 Concrete Pyomo Model with External Data . . . . . . . . 232.A.4 Concrete Pyomo Model with Constraint Rules . . . . . . 232.A.5 Concrete Pyomo Model with Abstract Component

. . . . . . . . . . . . . . . . . . . . . . . . 242.A.6 Using a Function to Construct a Concrete Pyomo Model . 252.A.7 Abstract Pyomo Model . . . . . . . . . . . . . . . . . . . 252.A.8 A Python Script that Optimizes a Concrete Pyomo Model 262.A.9 A Python Script that Optimizes an Abstract Pyomo Model 27

Declarations

Page 15: Springer Optimization and Its Applicationsmedia.ebook.de/shop/coverscans/191PDF/19111025_lprob_1.pdfOptimization has been a basic tool in all areas of applied mathematics, engineering,

xiv Contents

3 Model Components: Variables, Objectives, and Constraints 293.1 Modeling with Components . . . . . . . . . . . . . . . . . . . . . 293.2 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

3.2.1 Var Declarations . . . . . . . . . . . . . . . . . . . . . . 313.2.2 Variable Initialization . . . . . . . . . . . . . . . . . . . . 313.2.3 Working with Variables . . . . . . . . . . . . . . . . . . 32

3.3 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333.3.1 Simple Declarations . . . . . . . . . . . . . . . . . . . . 333.3.2 Declarations with Rule Functions . . . . . . . . . . . . . 34

3.4 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353.4.1 Declarations with Logical Expressions . . . . . . . . . . 363.4.2 Declarations with Expression Tuples . . . . . . . . . . . 37

3.5 Constraint Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393.6 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

4 Model Components: Sets and Parameters 434.1 Set Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

4.1.1 Set Declarations . . . . . . . . . . . . . . . . . . . . . . 434.1.2 Set Initialization . . . . . . . . . . . . . . . . . . . . . . 454.1.3 Set Data Validation . . . . . . . . . . . . . . . . . . . . . 474.1.4 Set Options . . . . . . . . . . . . . . . . . . . . . . . . . 484.1.5 RangeSet . . . . . . . . . . . . . . . . . . . . . . . . . . 494.1.6 Discussion of Index Sets . . . . . . . . . . . . . . . . . . 50

4.2 Parameter Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514.2.1 Param Declarations . . . . . . . . . . . . . . . . . . . . . 514.2.2 Parameter Initialization . . . . . . . . . . . . . . . . . . . 524.2.3 Data Validation . . . . . . . . . . . . . . . . . . . . . . . 54

4.3 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

5 Miscellaneous Model Components and Utility Functions 575.1 Miscellaneous Components . . . . . . . . . . . . . . . . . . . . . . 575.2 Advanced Component Indexing . . . . . . . . . . . . . . . . . . . 585.3 Functions to Support Modeling . . . . . . . . . . . . . . . . . . . 59

5.3.1 Generalized Dot Products . . . . . . . . . . . . . . . . . 605.3.2 Generating Sequences . . . . . . . . . . . . . . . . . . . 615.3.3 Helper Functions . . . . . . . . . . . . . . . . . . . . . . 62

5.4 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635.A Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

5.A.1 Error Checks in a Concrete Model . . . . . . . . . . . . . 635.A.2 Error Checks in an Abstract Model . . . . . . . . . . . . 64

6 Initializing Abstract Models with Data Command Files 676.1 Model Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676.2 The set Command . . . . . . . . . . . . . . . . . . . . . . . . . . 68

6.2.1 Simple Sets . . . . . . . . . . . . . . . . . . . . . . . . . 68


Recommended