Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion Material/Dynamic Exercises.md
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
# Dynamic Exercises
# Dynamic Optimization Exercises

## Overview of Dynamic Optimization

**Dynamic optimization** deals with optimization problems that evolve over time or space. Unlike static optimization problems where all decisions are made at once, dynamic optimization involves finding optimal strategies or trajectories over a time horizon or spatial domain.

### Key Characteristics

Dynamic optimization problems typically involve:

1. **Time-dependent variables**: Variables that change over time $x(t)$
2. **Differential equations**: Mathematical relationships describing how variables evolve
3. **Boundary conditions**: Initial and/or final conditions that must be satisfied
4. **Integral objectives**: Objectives that accumulate value over time

### Types of Dynamic Optimization

**Optimal Control Problems:**
- Find optimal control inputs $u(t)$ to steer a dynamic system
- Objective: $\min \int_0^T L(x(t), u(t), t) dt + \phi(x(T))$
- Subject to: $\frac{dx}{dt} = f(x(t), u(t), t)$

**Parameter Estimation Problems:**
- Estimate unknown parameters in dynamic models from experimental data
- Match model predictions to observed data
- Critical for model validation and system identification

**Dynamic Programming:**
- Break complex problems into simpler subproblems
- Solve recursively using Bellman's principle of optimality

### Solution Methods

1. **Direct Methods**: Discretize the problem and solve as a large NLP
2. **Indirect Methods**: Derive optimality conditions and solve boundary value problems
3. **Collocation Methods**: Use polynomial approximations on finite elements

### Applications

- Chemical process control and design
- Robotics and trajectory planning
- Economics and finance (dynamic programming)
- Biomedical engineering (pharmacokinetics)
- Energy systems optimization
26 changes: 24 additions & 2 deletions Material/Dynamic Exercises/param_est2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,31 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Parameter Estimation 2\n",
"# Parameter Estimation Example 2: Kinetic Parameter Estimation\n",
"\n",
"Here we work through an example of Kinetic Parameter Estimation.\n",
"This example demonstrates kinetic parameter estimation for chemical reaction systems.\n",
"\n",
"## Mathematical Formulation\n",
"\n",
"For a chemical reaction system, we typically have:\n",
"\n",
"**Material Balance:**\n",
"$$\\frac{dC_i}{dt} = \\sum_j \\nu_{ij} r_j(C, T, k)$$\n",
"\n",
"**Rate Expression:**\n",
"$$r_j = k_j f_j(C, T)$$\n",
"\n",
"**Parameter Estimation Objective:**\n",
"$$\\min_{k} \\sum_{i,t} w_{i,t} \\left(C_{i,\\text{exp}}(t) - C_{i,\\text{model}}(t)\\right)^2$$\n",
"\n",
"where:\n",
"- $C_i$ = concentration of species $i$\n",
"- $\\nu_{ij}$ = stoichiometric coefficient \n",
"- $r_j$ = reaction rate\n",
"- $k_j$ = kinetic parameters (to be estimated)\n",
"- $w_{i,t}$ = weighting factors\n",
"\n",
"Here we work through an example of kinetic parameter estimation.\n",
"\n",
"First we simulate the kinematic behaviour"
]
Expand Down
24 changes: 23 additions & 1 deletion Material/Dynamic Exercises/small_colloc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,29 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Small collocation example"
"# Small Collocation Example\n",
"\n",
"This example demonstrates orthogonal collocation methods for solving dynamic optimization problems.\n",
"\n",
"## Mathematical Formulation\n",
"\n",
"Orthogonal collocation approximates the state trajectory using orthogonal polynomials:\n",
"\n",
"$$x(t) \\approx \\sum_{j=0}^{K} \\alpha_j \\Phi_j(t)$$\n",
"\n",
"where $\\Phi_j(t)$ are orthogonal basis functions (e.g., Legendre polynomials) and $\\alpha_j$ are coefficients to be determined.\n",
"\n",
"**Collocation Points**: The differential equation is enforced exactly at specific collocation points within each finite element.\n",
"\n",
"**Advantages:**\n",
"- High accuracy with fewer discretization points\n",
"- Natural handling of continuous variables\n",
"- Efficient for smooth solutions\n",
"\n",
"**Learning Objectives:**\n",
"- Understand orthogonal collocation principles\n",
"- Compare with finite difference methods\n",
"- Learn when collocation is most effective"
]
},
{
Expand Down
18 changes: 17 additions & 1 deletion Material/Dynamic Exercises/small_dae.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Small Dae Example"
"# Small DAE Example\n",
"\n",
"This example demonstrates solving a simple Differential Algebraic Equation (DAE) system using Pyomo.DAE.\n",
"\n",
"## Mathematical Formulation\n",
"\n",
"We consider a DAE system of the form:\n",
"\n",
"$$\\frac{dx}{dt} = f(x, y, t)$$\n",
"$$0 = g(x, y, t)$$\n",
"\n",
"where $x(t)$ are differential variables and $y(t)$ are algebraic variables.\n",
"\n",
"**Learning Objectives:**\n",
"- Understand DAE formulation in Pyomo\n",
"- Learn to handle both differential and algebraic variables\n",
"- See discretization methods for continuous-time problems"
]
},
{
Expand Down
21 changes: 20 additions & 1 deletion Material/Dynamic Exercises/small_findiff.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Small Find Diff example"
"# Small Finite Difference Example\n",
"\n",
"This example demonstrates the finite difference method for solving differential equations in optimization problems.\n",
"\n",
"## Mathematical Formulation\n",
"\n",
"The finite difference method approximates derivatives using discrete differences:\n",
"\n",
"**Forward Difference:**\n",
"$$\\frac{dx}{dt} \\approx \\frac{x_{i+1} - x_i}{\\Delta t}$$\n",
"\n",
"**Central Difference:**\n",
"$$\\frac{dx}{dt} \\approx \\frac{x_{i+1} - x_{i-1}}{2\\Delta t}$$\n",
"\n",
"The number of discretization points affects solution accuracy and computational cost. A balance must be struck between precision and efficiency.\n",
"\n",
"**Learning Objectives:**\n",
"- Understand finite difference discretization\n",
"- Learn trade-offs between accuracy and computational cost\n",
"- See practical implementation in Pyomo.DAE"
]
},
{
Expand Down
68 changes: 67 additions & 1 deletion Material/GDP Exercises.md
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
# GDP Exercises
# Generalized Disjunctive Programming (GDP) Exercises

## Overview of Generalized Disjunctive Programming

**Generalized Disjunctive Programming (GDP)** is a modeling framework that extends traditional mixed-integer programming to handle logical relationships and discrete choices more naturally. GDP provides an intuitive way to model complex decision-making problems involving both continuous and discrete variables.

### What is GDP?

GDP stands for **Generalized Disjunctive Programming**, a mathematical programming paradigm that:

- **Combines continuous and discrete decisions** in a unified framework
- **Uses logical propositions** to represent discrete choices
- **Employs disjunctions** to model alternative scenarios or operating modes
- **Provides natural problem formulation** for complex systems with operational choices

### Key Components of GDP

**1. Disjunctions**: Logical OR relationships representing mutually exclusive alternatives
$$\begin{bmatrix}
Y_1 \\
g_1(x) \leq 0 \\
\Omega_1(x) = 0
\end{bmatrix} \vee \begin{bmatrix}
Y_2 \\
g_2(x) \leq 0 \\
\Omega_2(x) = 0
\end{bmatrix} \vee \ldots \vee \begin{bmatrix}
Y_K \\
g_K(x) \leq 0 \\
\Omega_K(x) = 0
\end{bmatrix}$$

**2. Boolean Variables**: $Y_k \in \{True, False\}$ indicate which disjunctive term is active

**3. Logic Constraints**: Additional logical relationships between Boolean variables

### GDP vs. Traditional MIP

| Aspect | GDP | Traditional MIP |
|--------|-----|----------------|
| **Modeling** | Intuitive logical structure | Requires manual big-M formulations |
| **Readability** | Clear representation of choices | Obscured by binary variable tricks |
| **Flexibility** | Easy to modify logical structure | Difficult to change formulations |
| **Solution** | Automatic reformulation to MIP | Direct MIP solving |

### Solution Methods

GDP problems are typically solved by:

1. **Big-M Reformulation**: Convert disjunctions to inequalities with large constants
2. **Hull Reformulation**: Use convex hull representation for tighter relaxations
3. **Hybrid Methods**: Combine different reformulation techniques

### Applications

- **Process Design**: Equipment selection and sizing
- **Scheduling**: Resource allocation with setup decisions
- **Supply Chain**: Facility location and capacity decisions
- **Engineering Design**: Configuration and topology optimization
- **Logic-based Planning**: Manufacturing and operations research

### Why Use GDP?

- **Natural Modeling**: Express decisions as they occur in real problems
- **Automatic Reformulation**: Pyomo.GDP handles conversion to solvable forms
- **Enhanced Readability**: Models are easier to understand and maintain
- **Flexible Solving**: Multiple solution strategies available
11 changes: 9 additions & 2 deletions Material/Pyomo Fundamentals/1.1 Knapsack Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1.1 Knapsack example: \n",
"Below is the knapsack problem. Which items are acquired in the optimal solution? What is the value of the selected items?"
"# Knapsack: Exercise 1.1 - Basic Example\n",
"\n",
"Below is the knapsack problem. Which items are acquired in the optimal solution? What is the value of the selected items?\n",
"\n",
"**Learning Objectives:**\n",
"- Understand basic Pyomo model structure\n",
"- Learn how to define binary variables\n",
"- See how to formulate constraints and objectives\n",
"- Interpret optimization results"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.2 Knapsack with improved printing: \n",
"The knapsack.py example shown\n",
"in the tutorial uses `model.pprint()` to see the value of the solution\n",
"variables. Note that the Pyomo value function should be used to get the floating point value of Pyomo modeling components (e.g., `print(value(model.x[i])`). We can also\n",
"print the value of the items selected (the objective), and the total\n",
"weight."
"# Knapsack: Exercise 1.2 - Improved Solution Display\n",
"\n",
"The knapsack.py example shown in the tutorial uses `model.pprint()` to see the value of the solution variables. Note that the Pyomo value function should be used to get the floating point value of Pyomo modeling components (e.g., `print(value(model.x[i]))`). We can also print the value of the items selected (the objective), and the total weight.\n",
"\n",
"**Learning Objectives:**\n",
"- Learn to extract and display solution values using `value()` function\n",
"- Understand how to interpret optimization results\n",
"- Practice accessing decision variable values\n",
"- See better formatting for solution output"
]
},
{
Expand Down
11 changes: 9 additions & 2 deletions Material/Pyomo Fundamentals/1.3 Changing data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.3 Changing data: \n",
"When we increase the value of the wrench, at what point would it become selected as part of the optimal solution?"
"# Knapsack: Exercise 1.3 - Sensitivity Analysis\n",
"\n",
"When we increase the value of the wrench, at what point would it become selected as part of the optimal solution?\n",
"\n",
"**Learning Objectives:**\n",
"- Understand sensitivity analysis in optimization\n",
"- Learn how parameter changes affect optimal solutions\n",
"- Practice modifying data in Pyomo models\n",
"- Explore the concept of shadow prices and breakpoints"
]
},
{
Expand Down
11 changes: 9 additions & 2 deletions Material/Pyomo Fundamentals/1.4 Loading data from Excel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.4 Loading data from Excel: \n",
"In the knapsack example shown in the tutorial slides, the data is hardcoded at the top of the file. Instead of hard-coding the data, we can Python to load the data from a different source."
"# Knapsack: Exercise 1.4 - Loading Data from Excel\n",
"\n",
"In the knapsack example shown in the tutorial slides, the data is hardcoded at the top of the file. Instead of hard-coding the data, we can use Python to load the data from a different source.\n",
"\n",
"**Learning Objectives:**\n",
"- Learn to read external data sources (Excel files)\n",
"- Understand data integration with Pyomo models\n",
"- Practice using pandas for data manipulation\n",
"- See how to make models more flexible and reusable"
]
},
{
Expand Down
11 changes: 9 additions & 2 deletions Material/Pyomo Fundamentals/1.5 NLP vs MIP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.5 NLP vs MIP: \n",
"Here we solve the knapsack problem with Ipopt instead of cbc. What happened? Why?\n"
"# Knapsack: Exercise 1.5 - NLP vs MIP Solvers\n",
"\n",
"Here we solve the knapsack problem with Ipopt instead of CBC. What happened? Why?\n",
"\n",
"**Learning Objectives:**\n",
"- Understand different solver types (NLP vs MIP)\n",
"- Learn when to use continuous vs discrete solvers\n",
"- See the effects of solver choice on solution quality\n",
"- Understand the importance of matching problem type to solver type"
]
},
{
Expand Down
46 changes: 45 additions & 1 deletion Material/Pyomo Fundamentals/Exercises 1.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# Exercises 1
# Knapsack Problem: Exercises 1

## Overview of the Knapsack Problem

The **knapsack problem** is a classic optimization problem that serves as an excellent introduction to mathematical programming and Pyomo. This problem demonstrates fundamental concepts including decision variables, constraints, and objective functions in a practical context.

### Problem Description

Imagine you are a hiker preparing for a trip and need to pack your knapsack (backpack). You have a collection of items you'd like to bring, but your knapsack has limited capacity. Each item has:
- A **weight** (or volume)
- A **value** (utility or importance to you)

**Goal**: Select which items to pack to maximize the total value while staying within the weight capacity of your knapsack.

### Mathematical Formulation

The knapsack problem can be formulated as follows:

**Decision Variables:**
- $x_i \in \{0, 1\}$ for each item $i$, where:
- $x_i = 1$ if item $i$ is selected (packed)
- $x_i = 0$ if item $i$ is not selected

**Objective Function:**
$$\max \sum_{i} v_i x_i$$
where $v_i$ is the value of item $i$.

**Constraints:**
$$\sum_{i} w_i x_i \leq W$$
where $w_i$ is the weight of item $i$ and $W$ is the knapsack capacity.

### Problem Characteristics

- **Type**: Integer Programming (specifically, Binary Integer Programming)
- **Complexity**: NP-hard (no known polynomial-time algorithm for large instances)
- **Applications**: Resource allocation, capital budgeting, cargo loading, portfolio selection

### Why Start with the Knapsack Problem?

1. **Intuitive**: Easy to understand conceptually
2. **Fundamental**: Demonstrates core optimization concepts
3. **Practical**: Has many real-world applications
4. **Scalable**: Can be simple or complex depending on the variant

The following exercises will guide you through implementing and solving knapsack problems using Pyomo, starting with basic formulations and progressing to more advanced techniques.
Loading