Download Pyomo — Optimization Modeling in Python PDF

TitlePyomo — Optimization Modeling in Python
File Size2.1 MB
Total Pages280
Table of Contents
	Goals of the Book
	Who Should Read This Book
	Revisions for the Second Edition
	Comments and Questions
Chapter 1 Introduction
	1.1 Modeling Languages for Optimization
	1.2 Modeling with Pyomo
		1.2.1 Simple Examples
		1.2.2 Graph Coloring Example
		1.2.3 Key Pyomo Features
			Customizable Capability
			Command-Line Tools and Scripting
			Concrete and Abstract Model Definitions
			Object-Oriented Design
			Expressive Modeling Capability
			Solver Integration
			Open Source
	1.3 Getting Started
	1.4 Book Summary
	1.5 Discussion
Part I An Introduction to Pyomo
	Chapter 2 Mathematical Modeling and Optimization
		2.1 Mathematical Modeling
			2.1.1 Overview
			2.1.2 A Modeling Example
		2.2 Optimization
		2.3 Linear and Nonlinear Optimization Models
			2.3.1 Definition
			2.3.2 A Linear Approximation
		2.4 Modeling with Pyomo
			2.4.1 An Abstract Formulation
			2.4.2 A Concrete Formulation
			2.4.3 Linear Version
		2.5 Solving the Pyomo Model
			2.5.1 Solvers
			2.5.2 The pyomo Command
			2.5.3 Python Scripts
	Chapter 3 Pyomo Overview
		3.1 Introduction
		3.2 The Warehouse Location Problem
		3.3 Pyomo Models
			3.3.1 Components for Variables, Objectives and Constraints
			3.3.2 Indexed Components
			3.3.3 Construction Rules
			3.3.4 Abstract and Concrete Models
			3.3.5 A Concrete Model for the Warehouse Location Problem
			3.3.6 Modeling Components for Sets and Parameters
			3.3.7 An Abstract Model for the Warehouse Location Problem
		3.4 Solving the Pyomo Model
			3.4.1 Using the pyomo Command
			3.4.2 Scripting the Solution Process
	Chapter 4 Pyomo Models and Components: An Introduction
		4.1 An Object-Oriented AML
		4.2 Common Component Paradigms
			4.2.1 Indexed Components
		4.3 Variables
			4.3.1 Var Declarations
			4.3.2 Working with Var Objects
		4.4 Objectives
			4.4.1 Objective Declarations
			4.4.2 Working with Objective Objects
		4.5 Constraints
			4.5.1 Constraint Declarations
			4.5.2 Working with Constraint Objects
		4.6 Set Data
			4.6.1 Set Declarations
			4.6.2 Working with Set Objects
		4.7 Parameter Data
			4.7.1 Param Declarations
			4.7.2 Working with Param Objects
		4.8 Named Expressions
			4.8.1 Expression Declarations
			4.8.2 Working with Expression Objects
		4.9 Suffix Components
			4.9.1 Suffix Declarations
			4.9.2 Working with Suffixes
		4.10 Build Components
		4.11 Other Modeling Components
	Chapter 5 The Pyomo Command
		5.1 Overview
		5.2 The check Subcommand
		5.3 The convert Subcommand
		5.4 The help Subcommand
		5.5 The solve Subcommand
			5.5.1 Specifying the Model Object
			5.5.2 Selecting Data with Namespaces
			5.5.3 Customizing Pyomo’s Workflow
			5.5.4 Customizing Solver Behavior
			5.5.5 Analyze Solver Results
			5.5.6 Managing Diagnostic Output
		5.6 Discussion
	Chapter 6 Data Command Files
		6.1 Model Data
		6.2 The set Command
			6.2.1 Simple Sets
			6.2.2 Sets of Tuple Data
			6.2.3 Set Arrays
		6.3 The param Command
			6.3.1 One-dimensional Parameter Data
			6.3.2 Multi-Dimensional Parameter Data
		6.4 The table Command
		6.5 The load Command
			6.5.1 Simple Load Examples
			6.5.2 Load Syntax Options
			6.5.3 Interpreting Tabular Data
			6.5.4 Loading from Spreadsheets and Relational Databases
		6.6 The include Command
		6.7 Data Namespaces
		6.8 Discussion
Part II Advanced Features and Extensions
	Chapter 7 Nonlinear Programming with Pyomo
		7.1 Introduction
		7.2 Building Nonlinear Programming Formulations
			7.2.1 Nonlinear Expressions
			7.2.2 The Rosenbrock Problem
		7.3 Solving Nonlinear Programming Formulations
			7.3.1 Nonlinear Solvers
			7.3.2 Additional Tips for Nonlinear Programming
				Variable Initialization
				Undefined Evaluations
				Model Singularities and Problem Scaling
		7.4 Nonlinear Programming Examples
			7.4.1 Variable Initialization for a Multimodal Function
			7.4.2 Optimal Quotas for Sustainable Harvesting of Deer
			7.4.3 Estimation of Infectious Disease Models
			7.4.4 Reactor Design
	Chapter 8 Structured Modeling with Blocks
		8.1 Introduction
		8.2 Block structures
		8.3 Blocks as Indexed Components
		8.4 Construction Rules within Blocks
		8.5 Extracting values from hierarchical models
		8.6 Blocks Example: Optimal Multi-Period Lot-Sizing
			8.6.1 A Formulation Without Blocks
			8.6.2 A Formulation With Blocks
	Chapter 9 Generalized Disjunctive Programming
		9.1 Introduction
		9.2 Modeling GDP in Pyomo
		9.3 Solving GDP models
			9.3.1 Big-M transformation
			9.3.2 Convex hull transformation
		9.4 A mixing problem with semi-continuous variables
	Chapter 10 Stochastic Programming Extensions
		10.1 Introduction
		10.2 Stochastic Programming: Definition and Notation
		10.3 Modeling in PySP
			10.3.1 The Deterministic Reference Model
			10.3.2 The Scenario Tree
			10.3.3 Scenario Parameter Specification Abstract Models Concrete Models
		10.4 Generating and Solving the Extensive Form
		10.5 Progressive Hedging: A Generic Decomposition Strategy
			10.5.1 The runph Script Variable-specific ρ Linearization of the Proximal Penalty Terms Solution Values Setting Variable Bounds
		10.6 Progressive Hedging Extensions: Advanced Configuration
			10.6.1 Bundling
			10.6.2 Watson and Woodruff Extensions Mipgap Control and Cycle Detection Parameters General Variable Fixing and Slamming Parameters Variable-specific Fixing and Slamming Parameters
			10.6.3 Solving a Constrained Extensive Form
			10.6.4 Alternative Convergence Criteria
			10.6.5 User-Defined Extensions
		10.7 Solving PH Scenario Sub-Problems in Parallel
		10.8 Bounds
	Chapter 11 Differential Algebraic Equations
		11.1 Introduction
		11.2 Pyomo DAE Modeling Components
		11.3 Solving Pyomo Models with DAEs
			11.3.1 Finite Difference Transformation
			11.3.2 Collocation Transformation
		11.4 Additional Features
			11.4.1 Applying Multiple Discretizations
			11.4.2 Restricting Control Input Profiles
			11.4.3 Plotting
	Chapter 12 Mathematical Programs with Equilibrium Constraints
		12.1 Introduction
		12.2 Modeling Equilibrium Conditions
			12.2.1 Complementarity Conditions
			12.2.2 Complementarity Expressions
			12.2.3 Modeling Mixed-Complementarity Conditions
		12.3 MPEC Transformations
			12.3.1 Standard Form
			12.3.2 Simple Nonlinear
			12.3.3 Simple Disjunction
			12.3.4 AMPL Solver Interface
		12.4 Solver Interfaces and Meta-Solvers
			12.4.1 Nonlinear Reformulations
			12.4.2 Disjunctive Reformulations
			12.4.3 PATH and the ASL Solver Interface
		12.5 Discussion
	Chapter 13 Bilevel Programming
		13.1 Introduction
		13.2 Motivating Problems
			13.2.1 Linear Bilevel Programs with Continuous Variables
			13.2.2 Quadratic Min/Max
		13.3 Modeling Bilevel Programs
		13.4 Solving Linear Bilevel Programs
			13.4.1 Global Optimization
			13.4.2 Local Optimization
		13.5 Solving Quadratic Min-Max Bilevel Programs
		13.6 Discussion
	Chapter 14 Scripting
		14.1 Introduction
		14.2 A Basic Optimization Script
		14.3 Creating and Modifying Pyomo Models
			14.3.1 Modifying Model Parameters
			14.3.2 Modifying Model Structure
		14.4 Using Solvers
		14.5 Investigating the Solution
			14.5.1 Solver Results
			14.5.2 Retrieving Variable Values
		14.6 Scripting Examples
			14.6.1 Warehouse Location Loop and Plotting
			14.6.2 A Sudoku Solver
Appendix A A Brief Python Tutorial
	A.1 Overview
	A.2 Installing and Running Python
	A.3 Python Line Format
	A.4 Variables and Data Types
	A.5 Data Structures
		A.5.1 Strings
		A.5.2 Lists
		A.5.3 Tuples
		A.5.4 Sets
		A.5.5 Dictionaries
	A.6 Conditionals
	A.7 Iterations and Looping
	A.8 Functions
	A.9 Objects and Classes
	A.10 Modules
	A.11 Python Resources
Document Text Contents
Page 1

Springer Optimization and Its Applications 67

William E. Hart
Carl D. Laird
Jean-Paul Watson
David L. Woodruff
Gabriel A. Hackebeil
Bethany L. Nicholson
John D. Siirola

Pyomo —
in Python
Second Edition

Page 2

Springer Optimization and Its Applications


Managing Editor
Panos M. Pardalos (University of Florida)

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

Advisory Board
J. Birge (University of Chicago)

F. Giannessi (University of Pisa)
H.D. Sherali (Virginia Polytechnic and State University)
T. Terlaky (Lehigh University)
Y. Ye (Stanford University)

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 even more
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

S. Butenko (Texas A&M University)

Page 140

130 7 Nonlinear Programming with Pyomo

7.4.2 Optimal Quotas for Sustainable Harvesting of Deer

Maintaining a healthy deer population relies on both effective habitat development
and a sustainable harvesting policy. Among most hunters there is high demand for
tags that allow them to take bucks. However, harvesting too many bucks within a
population can limit future population growth. The primary goal of this nonlinear
programming formulation is to determine an optimal policy for deer harvesting that
maximizes the value of the harvest while maintaining a strong and sustainable deer

We consider a model adapted from Bailey [5] that describes the dynamics of the
deer population. The deer population in a given area can be divided into three sub-
populations: bucks, does, and fawns. Additionally, each year is divided into four
periods: winter, breeding season, summer, and harvest. The model describing the
population dynamics is based on the following assumptions:

• It is assumed that the sub-populations can be represented by continuous vari-
ables (i.e., population numbers are large enough that this is a good approxima-

• Each season, there is a reduction in the number of bucks, does, and fawns. This
reduction is assumed to be due to natural causes and is proportional to the size
of the sub-populations. This reduction is captured by specifying a fractional
survival rate that depends on the period (winter, breeding, summer, harvest) and
the sub-population in question (bucks, does, fawns).

• New fawns are born each year during the breeding season. Fawns are born from
does and older fawns according to a birth rate that depends on the available
amount of food. Half of them are assumed to be male and half are assumed to
be female. After surviving one year, half of the remaining fawns become bucks
and half become does.

• The total yearly food supply is constant and represents a constraint based on
habitat management.

• All harvesting is based on hunting. Hunting quotas can be set for each sub-
population, and these quotas are assumed to be completely filled (i.e., all hunters
are successful).

The complete derivation of the sub-population model is given in [5], resulting in the
following set of difference equations,

fy+1 = p1bry
( p2

fy + p3dy

+h fy (7.1)

dy+1 = p4dy +

fy −hdy (7.2)

by+1 = p6by +

fy −hby (7.3)

bry = 1.1+0.8
ps − cy


cy = p7by + p8dy + p9 fy (7.5)

Page 141

7.4 Nonlinear Programming Examples 131

where the value for parameters p1 through p9 are calculated from the various sur-
vival rates and food consumption rates. These values are given in Table 7.3. The
variables fy, dy, and by represent the number of fawns, does, and bucks in year y,
respectively. Likewise, h fy , hdy , and h

y are the unknown numbers of fawns, does, and

bucks harvested in year y, respectively. The birth rate bry for does is described by
a nonlinear relationship where cy is the amount of food consumed by the deer (in
pounds) and ps is the total available supply of food (again in pounds).

parameter value parameter value

p1 0.88 p7 2700.0
p2 0.82 p8 2300.0
p3 0.92 p9 540.0
p4 0.84 w f 1.0
p5 0.73 wd 1.0
p6 0.87 wb 10.0
ps 700 000

Table 7.3: Parameter values used by the deer harvesting problem.

In the original reference, this set of difference equations was optimized in the
formulation over a period of 20 years so that a sustainable steady-state policy could
be deduced from the values at later years. Here, we instead include only one year
and add the constraint that the number of fawns, does, and bucks at year y+1 is
equal to those at y. This provides the same steady-state solution with a formulation
that is significantly smaller.

The objective is to maximize the value of the harvest, giving the following non-
linear programming formulation,

max wbh
y +w f h

y +wdh

y (7.6)

fy = p1bry
( p2

fy + p3dy

+h fy (7.7)

dy = p4dy +

fy −hdy (7.8)

by = p6by +

fy −hby (7.9)

bry = 1.1+0.8
ps − cy


cy = p7by + p8dy + p9 fy (7.11)
cy ≤ ps (7.12)
by ≥

(0.4 fy +dy) (7.13)

where w f , wd and wb represent the value of harvesting a fawn, doe, and buck, re-
spectively. As can be seen in Table 7.3, it is assumed that the value of a buck tag
is 10 times the value of a doe or fawn tag. Equation (7.12) ensures that the amount

Page 279

276 Index

argument, --print-results 92
argument, --quiet 96
argument, --save-results 92, 95
argument, --show-results 94
argument, --solver-manager 93
argument, --solver-options 93
argument, --solver-suffixes 93
argument, --solver 93
argument, --stream-output 94
argument, --summary 94
argument, --tempdir 94
argument, --timelimit 93
argument, --verbose 96
argument, --warning 96
callback 89

pyomo.bilevel package 225
pyomo.dae package 202
pyomo.environ package 6
pyomo.gdp package 159
pyomo.mpec package 213
pyomo.pysp package 165
Pyro 197

concrete model 175
convergence criteria 183
iteration limit 182
linearize penalty 185
PH bounds 198
PH variable fixing 193
reference model 168
stage cost 170

python 255
class declaration 265
conditional 262
dictionary data 262
function declaration 264
function decorators 265
generator syntax 34
iteration 263
list comprehension 34
list data 260
module 266
set data 261
string data 260
sum function 6, 34
tuple data 261

PyYAML package 9, 95


RangeSet component 59, 62
reactor design problem 138, 139
Reals virtual set 51
reduced cost 94

relational database see database
relations 16
results object 244
Rosenbrock problem 123
rule 34
runef command 176
runph command 182


scalar 20

data 166, 174
tree 167, 171, 172

ScenarioStructure.dat 172
scripting 44, 235

adding components 240
changing parameters 239
ConstraintList 246

examples 246
fixing variables 240
model creation function 238
modifying models 237
plotting with matplotlib 246
removing components 240
results object 244
solve() method 242

solver options 243
SolverFactory 242

unfixing variables 240
variable values 245

set 59
bounds 62
definition 60
dimen 62
filter element 61
initialize 60
ordered 62
RangeSet component 59, 62
rule 60
Set component 29, 59
SetOf component 59
tuple element 62
unordered 59
validation 61
value 59
virtual 62

Set component 29, 59
set data command see data command, set
SetOf component 59
sin function 123

Page 280

Index 277

singularity 128
sinh function 123
slack value 94
SMPS 165

using pyomo command 43
solve() method 242

CPLEX 10, 11
GLPK 9, 43, 83, 93
Gurobi 11
PATH 219, 221
results object 244
setting options 243
termination condition 252

solver factory 242
solver options 243
SolverFactory 242
spreadsheet 98, 108, 110

Excel 114
range 114

SQL query 109, 115–117
.sqlite file 116
sqrt function 123
stochastic program 165

linear 180, 183
SubModel component 225
Sudoku problem 247
suffix 94

dual 94
rc 94
slack 94


.tab file 108
table data command see data command,

tan function 123
tanh function 123
temporary file 81, 94
bilevel.linear dual 230
bilevel.linear mpec 227

dae.collocation 207
dae.finite difference 205
gdp.bigm 162
gdp.bilinear 230
gdp.chull 163 219
mpec.simple disjunction 218
mpec.simple nonlinear 216, 217
mpec.standard form 217


unfix 240
UnitInterval virtual set 51
unordered set 59


Value at Risk 180
value() function 245
Var component 29
variable 16, 18, 50

auxiliary 172
bounds 52
declaration 50
derived 172
domain 50
index 50
initial value 52
setlb 53
setub 53
Var component 29

getting values 245

virtual set 62


.xls file 114

.xml file 108



Similer Documents