Toggle navigation
JUPYTER
FAQ
View as Code
View on GitHub
Execute on Binder
Download Notebook
ND-Pyomo-Cookbook
notebooks
Notebook
ND-Pyomo-Cookbook
¶
Chapter 1.0 Getting Started with Pyomo
¶
Online resources
References
Links
Pyomo
Pyomo home page
Read the Docs
Pyomo Questions on Stack Overflow
Pyomo Forum on Google Groups
Pyomo Examples
Pyomo Github Repository
PyomoGallery
Pyomo – Optimization Modeling in Python. Second Edition.
"Pyomo: modeling and solving mathematical programs in Python."
"pyomo.dae: a modeling and automatic discretization framework for optimization with differential and algebraic equations."
Presentation slides.
"Pyomo Tutorial."
"PySP: modeling and solving stochastic programs in Python."
1.1 Installing a Pyomo/Python Development Environment
¶
Step 1. Install Anaconda
Step 2. Install Pyomo
Step 3. Install solvers
Step 4. Optional: Compile Ipopt with HSL solvers
Step 5. Optional: Install additional solvers
Gurobi
GLPK
Links
CoCalc
Python
Python distributions
Anaconda.com
free download
Anaconda Navigator
conda
uninstall the earlier version
Download
detailed instructions
Verify
terminal window on MacOS
command window on Windows
[COIN-OR CBC]( conda install -c conda-forge glpk)
ipopt
mumps
HSL makes available a collection of high-performance solvers for use with Ipopt
Instructions for downloading, compiling, and installing the necessary software are available from COIN-OR
Gurobi
GLPK
CPLEX
1.2 Running Pyomo on Google Colab
¶
Basic installation of Pyomo
GLPK installation
COIN-OR CBC installation
COIN-OR Ipopt installation
COIN-OR Bonmin installation
COIN-OR Couenne installation
Gecode installation
Links
GLPK
COIN-OR CBC
COIN-OR Ipopt
COIN-OR Bonmin
1.3 Running Pyomo on the Notre Dame CRC Cluster
¶
Preliminaries
Request a CRC account
Install Pyomo on CRC cluster
Running on the CRC
Test problem
Running from the command line
Submitting to a queue
Available solvers
CPLEX
Gurobi
Ipopt
Coin-OR
Clp
Cbc
Bonmin
Couenne
SCIP
Links
register for a CRC account
install a private copy of standalone Python packages
ND CRC wiki instructions for adding
.local/bin
to your PATH
ND CRC wiki Quick Start Guide
free HSL academic license
Ipopt options
1.4 Cross-Platform Installation of Pyomo and Solvers
¶
Imports
Chapter 2.0 Linear Programming
¶
2.1 Production Models with Linear Constraints
¶
Imports
Example: Production plan for a single product plant
Pyomo model
Exercises
Production plan: Product Y
Exercises
Production plan: Mixed product strategy
What are the active constraints?
What is the incremental value of labor?
Theory of constraints
Figures
LP_ProductX.png
LP_ProductY.png
LP_ProductXY.png
Links
Pyomo
COINOR-CBC
2.2 Linear Blending Problem
¶
Imports
Problem Statement (Jenchura, 2017)
Representing Problem Data as a Python Dictionary
Model Formulation
Objective Function
Volume Constraint
Product Composition Constraint
Implementation in Pyomo
2.3 Design of a Cold Weather Fuel for a Camping Stove
¶
Imports
Problem statement
Vapor pressure data
Cold weather product requirements
Optimization model
Pyomo implementation and solution
Figures
alcohol-stove.jpeg
Links
manufacturer's product
2.4 Gasoline Blending
¶
Imports
Gasoline product specifications
Stream specifications
Blending model
Pyomo implementation
Displaying the solution
by refinery stream
by refinery product
Exercises
Expand product list with mid-grade gasoline
Impact of regulatory change
Impact of a change in refinery operations
Figures
CEP-refinery-diagram
Links
pdf available here.
2.5 Model Predictive Control of a Double Integrator
¶
Imports
Model
Discrete time approximation
Model predictive control
Visualization
Interactive use
Google Colaboratory
Model predictive control as a feedback controller
Chapter 3.0 Assignment Problems
¶
3.1 Transportation Networks
¶
Imports
Background
Table of transportation costs, customer demand, and available supplies
Pyomo model
Data File
Model file
Solution
Sensitivity analysis
Analysis by source
Analysis by customer
Exercises
Figures
TransportationNetworksMap.png
TransportNet.png
TransportNet_soln.png
TransportNet_sens.png
Links
"AIMMS Optimization Modeling", AIMMS B. V., 2014
Chapter 4.0 Scheduling with Disjunctive Constraints
¶
4.1 Machine Bottleneck
¶
Imports
Example
The machine scheduling problem
Gantt chart
Key performance indicators
Exercise
Empirical scheduling
First-in first-out
Last-in, first-out
Earliest due date
Shortest processing time
Modeling
Data
Decision variables
Pyomo model
Multiple machines
4.2 Job Shop Scheduling
¶
Imports
Background
Job shop example
Task decomposition
Model formulation
Pyomo implementation
Printing schedules
Visualizing Results with Gantt Charts
Application to the scheduling of batch processes
Single product strategies
Multiple Overlapping tasks
Adding time for unit clean out
Adding a zero wait policy
Solving the LA19 benchmark problem with NEOS
References
Exercises
Task specific cleanout
Computational impact of a zero-wait policy
Figures
jobshopdiagram.jpg
flowshop-Dunn-2013.png
Links
jobshop1.txt
contains 82 benchmark problems
OR-Library maintained by J. E. Beasley
NEOS
CPLEX
"A computational study of the job-shop scheduling problem."
pdf available
"OR-Library: distributing test problems by electronic mail."
OR-Library
"Applications of optimization with Xpress-MP."
"On the job-shop scheduling problem."
4.3 Maintenance Planning
¶
Imports
Problem statement
Modeling with disjunctive constraints
Objective
Constraints
Pyomo solution using the big-M method
Parameter values
Pyomo model
Display results
Pyomo solution using the generalized disjunctive constraints extension
Ramping constraints
Specifying the minimum number of operational days between maintenance periods
Exercises
Links
Generalized Disjunctive Programming
Generalized Disjunctive Programming
4.4 Scheduling Multipurpose Batch Processes using State-Task Networks
¶
Imports
References
Example (Kondili, et al., 1993)
Exercise
Encoding the STN data
Setting a time grid
Creating a Pyomo model
Characterization of tasks
Characterization of states
Characterization of units
Pyomo model
Analysis
Profitability
State inventories
Unit assignment
Unit batch inventories
Gannt chart
Trace of events and states
Figures
Kondili_1993.png
4.5 Unit Commitment
¶
Imports
Problem statement
Model
Demand
Generating Units
Pyomo model 1: Conventional implementation for emi-continuous variables
Pyomo model 2: GDP implementation
There is a problem here!
Links
"Recent advances in mathematical programming with semi-continuous variables and cardinality constraint."
Chapter 5.0 Simulation
¶
5.1 Response of a First Order System to Step and Square Wave Inputs
¶
Imports
First-order differential equation with constant input
Encapsulating into a function
Analytical approximation to a step input
Analytical approximation to a square wave input
5.2 Exothermic CSTR
¶
Imports
Description
Arrehenius law kinetics for a first-order reaction
Modeling and parameter values
Mathematical model
Pyomo model
Simulation and visualization
Visualization function
Simulation
Effect of cooling temperature
Figures
Agitated_vessel.png
5.3 Transient Heat Conduction in Various Geometries
¶
Imports
Rescaling the heat equation
Dimensionless model
Preliminary code
Planar coordinates
Cylindrical coordinates
Spherical coordinates
Chapter 6.0 Differential-Algebraic Equations
¶
6.1 Unconstrained Scalar Optimization
¶
Imports
Application: Maximizing production of a reaction intermediate
Mathematical model for a continuous stirred tank reactor
Analytical solution using calculus
Numerical solution with Pyomo
6.2 Maximizing Concentration of an Intermediate in a Batch Reactor
¶
Imports
Mathematical model
Optimization with
scipy.minimize_scalar
Solution using Pyomo
6.3 Path Planning for a Simple Car
¶
Imports
Mathematical model
Pyomo model
Accessing solution data
Visualizing the car path
Rescaling to incorporate time into the optimization model
Figures
Simple Car
6.4 Soft Landing Apollo 11 on the Moon
¶
Imports
Version 1: Vertical dynamics of a rocket with constant mass
First attempt at a solution
Land on the surface, not above or below the surface.
Make that a soft landing
Restrict fuel flow to engine capacity
Version 2: Rescaled model
How much fuel is burned?
Minimize fuel consumption
Version 3: Rocket model
Figures
https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Eagle_In_Lunar_Orbit_-_GPN-2000-001210.jpg/368px-Eagle_In_Lunar_Orbit_-_GPN-2000-001210.jpg
https://upload.wikimedia.org/wikipedia/commons/thumb/1/13/LM_illustration_02-IT.png/368px-LM_illustration_02-IT.png
Links
Apollo 11 Landing on the Moon, July 20, 1969
SpaceX Falcon Heavy Side Boosters Landing at Kennedy Space Center, February 6, 2018
Blue Origin, November 24, 2014
Apollo 11 Lunar Module
Chapter 7.0 Parameter Estimation
¶
7.1 Parameter estimation
¶
Imports
Steps in model fitting
Step 1. The data
Step 2. Select a model
Step 3. Define a "figure of merit"
Step 4. Find a best fit
Step 5. Evaluate the goodness of fit
Plotting residuals
Separable model
Step 6. Estimate confidence intervals
Step 7. Determine if a better fit is possible
Pyomo model - version 1
Pyomo model - version 2
Pyomo model - version 3
F-ratio test
Levene test
Links
"Model Fitting and Error Estimation", Costa, Kleinstein, Hershberg
Pandas
Levene test
Chapter 8.0 Financial Applications
¶
8.1 Obtaining Historical Stock Data
¶
Imports
Select Stocks to Download
Alpha Vantage
Download selected ticker Symbols
Links
Alpha Vantage
here
8.2 Consolidating and Charting Stock Data
¶
Imports
Loading stock data from data directory
Charting
Consolidating adjusted close data
8.3 Binomial Model for Pricing Options
¶
Imports
Historical data
Trim data series
Binomial model
European call option
Implementing a replicating portfolio with Pyomo
European put option
Early exercise
American put option
Figures
BinomialModel.png
BinomialModel_Options.png
Links
Luenberger (2013)
8.4 MAD Portfolio Optimization
¶
Imports
Investment objectives
Why diversify?
Reduce risk through law of large numbers
Value at risk (VaR)
Import historical stock price data
Select a recent subperiod of the historical data
Return on a portfolio
Equally weighted portfolio
Constant fixed allocation
Continually rebalanced
Component returns
Measuring deviation in component returns
Mean absolute deviation
Comparing mean absolute deviation to standard deviation
Return versus mean absolute deviation for an equally weighted continually rebalanced portfolio
MAD porfolio
Problem 1: Solve for dominating MAD portfolio
Links
Value at risk (VaR)
conditional value at risk
8.5 Real Options
¶
Imports
Implementing a replicating portfolio in Pyomo
Example 1. Value of a fixed cash flow
Example 2. Simplico gold mine
Solution
Example 3. Simplico gold mine capital investment
Example 4. Tree farm harvesting
Price model
Growth model
Figures
TimeLineRealOption.png
BinomialRealOption.png
Links
Real Options analysis by Martin Haugh
Appendix A. Style Guide
¶
Notebook naming and ancillary/generated files
Notebook title and headers
Title
Subheadings
Keywords
External Files
Figures
Data
Design for Portability
Installations and Imports
Markdown
Further reading
Figures
Links
Space Telescope Science Institute Style Guide
Jupyter notebook best practices and style guide
Dataquest: An In-Depth Style Guide for Data Science Projects
ESRI: Coding Standards for Jupyter Notebook