The towers of Hanoi problem [1] is a famous puzzle demonstrating recursion. The task is to move a stack of disks from one peg to another. We can only move one disk at a time, and we need to obey the rule that larger disks can never be on top of a smaller disk. The moves for the 3 disk problem are:
I am a full-time consultant and provide services related to the design, implementation and deployment of mathematical programming, optimization and data-science applications. I also teach courses and workshops. Usually I cannot blog about projects I am doing, but there are many technical notes I'd like to share. Not in the least so I have an easy way to search and find them again myself. You can reach me at erwin@amsterdamoptimization.com.
Tuesday, April 1, 2025
Friday, March 21, 2025
Wolf, goat and cabbage problem: MIP and network model
The Wolf, goat, and cabbage problem can be stated as [1]:
A farmer with a wolf, a goat, and a cabbage must cross a river by boat. The boat can carry only the farmer and a single item. If left unattended together, the wolf would eat the goat, or the goat would eat the cabbage. How can they cross the river without anything being eaten?
A long transcontinental flight was a good opportunity to try to attack this problem. Here are some approaches to model this. Not at all a very useful or practical model, but still interesting, I think (although I may be in a small minority here).
Inventory model
In this model, we keep track of the inventory of items (wolf, goat, cabbage). We assume the starting inventory is: all items are on the left bank of the river. The final inventory should be: all items are on the right bank. In this model, I assume the following numbering scheme:
---- 31 SET trip trips trip1 , trip2 , trip3 , trip4 , trip5 , trip6 , trip7 , trip8 , trip9 , trip10 ---- 31 SET dir direction of trip L->R, R->L ---- 31 SET tripDir trip direction combos L->R R->L trip1 YES trip2 YES trip3 YES trip4 YES trip5 YES trip6 YES trip7 YES trip8 YES trip9 YES trip10 YES
Tuesday, February 25, 2025
Small MIP, proving optimality is difficult
I have grid of dimensions H and W of boolean variables. The only constraint is that if a variable is false then at least one of the adjacent variables (top, right, left, bottom, diagonals don't count) must be true. The goal is to minimize the number of true values in the grid.
High-level model |
---|
min |
Monday, February 24, 2025
Programming vs Modeling
- Implement Dijkstra's shortest path algorithm in GAMS,
- implement Dijkstra's shortest path algorithm in Python and
- use a simple LP model.
Saturday, February 15, 2025
Network models with node capacities
Min-cost flow network model
Model 1: standard min-cost flow network model |
---|
\begin{align}\min& \sum_{(i,j)\in A}\color{darkblue}c_{i,j}\cdot\color{darkred}f_{i,j}\\ & \sum_{j|(j,i)\in A}\color{darkred}f_{j,i} + \color{darkblue}{\mathit{supply}}_i = \sum_{j|(i,j)\in A}\color{darkred}f_{i,j} + \color{darkblue}{\mathit{demand}}_i && \forall i \\ & \color{darkred}f_{i,j} \in [0,\color{darkblue}{\mathit{capacity}}_{i,j}] \end{align} |