# AMPL Model Colaboratory¶

## Introduction¶

AMPL Model Colaboratory is a collection of AMPL models in Jupyter Notebooks that run on platforms such as Google Colab, Kaggle, Gradient, and AWS SageMaker.

In order to be use AMPL on these platforms you just need to following two code blocks at the beginning of your notebook:

```
# Install dependencies
!pip install -q amplpy
```

```
# Google Colab & Kaggle integration
MODULES=['ampl', 'coin', 'highs', 'gokestrel']
from amplpy import tools
ampl = tools.ampl_notebook(modules=MODULES, globals_=globals()) # instantiate AMPL object and register magics
```

In the list `MODULES`

you can specify the AMPL solvers you want to use in your notebook.
As a quick-start you can use our template notebook: template.
You can contribute to this repository by making pull requests to https://github.com/ampl/amplcolab and following the instructions in the README file.

Note

In these notebooks there are `%%ampl_eval`

cells that allow you to run AMPL code directly from the notebook.
They are equivalent to `ampl.eval("""cell content""")`

.

Warning

Some notebooks require a license to run due to the problem size. You can use a free AMPL Community
Edition license with an open-source solver (e.g., HiGHS, CBC, Couenne, Ipopt, Bonmin)
or with a commercial solver from the NEOS Server as described in <https://dev.ampl.com/solvers/kestrel.html>.
In the list `MODULES`

you need to include
`"gokestrel"`

to use the kestrel driver;
`"highs"`

for the HiGHS solver;
`"coin"`

for the COIN-OR solvers.
To use other commercial solvers without NEOS, you need to use a cloud license that includes the commercial solver.

## Main categories¶

## Notebooks¶

### AMPL Model Colaboratory Template¶

Description: Basic notebook template for the AMPL Colab repository

Tags: ampl-only, template, industry

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### Book Example: Economic equilibria¶

Description: economic model using complementarity conditions from Chapter 19 AMPL book

Tags: ampl-only, ampl-book, finance, complementarity_problem

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Book Example: Transshipment problem¶

Description: book example with general transshipment model (net1.mod)

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Book Example: diet¶

Description: book example autogenerated using diet.mod, diet.dat, and diet.run

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Book Example: prod¶

Description: book example autogenerated using prod.mod, prod.dat, and prod.run

Author: N/A

### Book Example: steel¶

Description: book example autogenerated using steel.mod, steel.dat, and steel.run

Author: N/A

### Book Example: transp¶

Description: book example autogenerated using transp.mod, transp.dat, and transp.run

Author: N/A

### CP-style scheduling model with the *numberof* operator, solved by a MIP solver¶

Description: Scheduling model with the Constraint Programming *numberof* operator, solved with a MIP solver. New MIP solver drivers based on the [MP library](https://amplmp.readthedocs.io/) enable CP-style modeling.

Tags: ampl-only, constraint-programming

Author: Gleb Belov (1 notebook) <gleb@ampl.com>

### Capacity expansion of power generation¶

Description: Models the extensive form of a deterministic multi-stage capacity expansion problem. In this model we can have multiple resources of the same type which have identical properties. The model can be further developed into a stochastic one.

Tags: ampl-only, planning, mip, power-generation

Author: Gyorgy Matyasfalvi (2 notebooks) <gyorgy@ampl.com>

### Diet lecture¶

Description: Diet case study

Tags: ampl-only, ampl-lecture

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Diet model with Google Sheets¶

Description: Diet model using Google Sheets

Tags: amplpy, google-sheets, example

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### Efficient Frontier with Google Sheets¶

Description: Efficient Frontier example using Google Sheets

Tags: amplpy, google-sheets, example

Author: Christian Valente (2 notebooks) <ccv@ampl.com>

### Financial Portfolio Optimization with amplpy¶

Description: Financial Portfolio Optimization with amplpy and amplpyfinance

Tags: amplpy, amplpyfinance, finance

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### Google Hashcode 2022¶

Description: Google Hashcode 2022 Practice Problem

Tags: amplpy, heuristics, engineering, scheduling, complexity

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Hospitals-Residents MIP¶

Description: hospitals-residents problem with ties problem solved with ampl and highs

Tags: amplpy, assignment, mip, data-structures, graphs

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Jupyter Notebook Integration¶

Description: Jupyter Notebook Integration with amplpy

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### Multicommodity transportation problem¶

Description: Multicommodity transportation model with binary variables

Tags: ampl-only, ampl-book, mixed-integer-linear

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Network design with redundancy¶

Description: Design of an electricity transportation network provides enough redundancy, so that a break of one component does not prevent any user from receiving electricity. The approach also works for similar distribution networks and can potentially be used in the design of military logistic networks.

Tags: electric-grid, military

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### Nonlinear transportation model¶

Description: book example autogenerated using nltransd.mod, nltrans.dat, and nltrans.run

Tags: ampl-only, ampl-book, nonlinear

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Nonlinear transportation problem example¶

Description: book example autogenerated using nltransd.mod, nltrans.dat, and nltrans.run

Tags: ampl-only, ampl-book, nonlinear

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Optimization Methods in Finance: Chapter 3¶

Description: Optimization Methods in Finance: Bond Dedication Problem.

Tags: amplpy, example, finance

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Pattern Enumeration¶

Description: Pattern enumeration example with amplpy

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### Pattern Generation¶

Description: Pattern generation example with amplpy

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### Pricing and target-market¶

Description: Formulate a pricing optimization and target-market problem as a MILP.

Tags: industry, pricing, milp, mip

Author: Gyorgy Matyasfalvi (2 notebooks) <gyorgy@ampl.com>

### Production model¶

Description: generic model for production problem

Tags: ampl-only, ampl-book, industry

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Roll Cutting - Revision 1 & 2¶

Description: Pattern tradeoff example with amplpy

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### Solving a nonogram puzzle¶

Description: Model for solving nonogram puzzles autogenerated using **nonogram.mod**, **nonogram.dat** and **nonogram.run**.

Author: Juan Jesús Losada del Olmo (1 notebook) <juanjesus.losada@gmail.com>

### Steel industry problem¶

Description: model for steel production problem

Tags: ampl-only, ampl-lecture, industry

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Transportation problem¶

Description: an AMPL model for the transportation problem

Tags: ampl-only, ampl-lecture

Author: Marcos Dominguez Velad (13 notebooks) <marcos@ampl.com>

### Travelling Salesman Problem with subtour elimination¶

Description: this example shows how to solve a TSP by eliminating subtours using amplpy and ampls

Author: Christian Valente (2 notebooks) <ccv@ampl.com>

### VPSolver: Cutting & Packing Problems¶

Description: Solving cutting & packing problems using arc-flow formulations

Tags: industry, cutting-stock, bin-packing, vector-packing

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

### amplpy setup & Quick Start¶

Description: amplpy setup and quick start

Author: Filipe Brandão (10 notebooks) <fdabrandao@gmail.com>

## Tag list¶

- Tags
- ampl-book
- ampl-lecture
- ampl-only
- amplpy
- amplpyfinance
- assignment
- bin-packing
- callbacks
- complementarity_problem
- complexity
- constraint-programming
- cutting-stock
- data-structures
- electric-grid
- engineering
- example
- finance
- google-sheets
- graphs
- heuristics
- industry
- military
- milp
- mip
- mixed-integer-linear
- nonlinear
- planning
- power-generation
- pricing
- scheduling
- template
- tsp
- vector-packing