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 commercial solvers. 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, your license needs to include the commercial solver.

Main categories

Authors

The notebooks in this repository are contributed by the following authors:

Your name can be here too! Just make a pull request to https://github.com/ampl/amplcolab.

Notebooks

AMPL Model Colaboratory Template

colab.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Basic notebook template for the AMPL Colab repository

Book Example: Economic equilibria

economic_eq_lecture.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: economic model using complementarity conditions from Chapter 19 AMPL book

Book Example: Transshipment problem

net1.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: book example with general transshipment model (net1.mod)

Book Example: diet

diet.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: book example autogenerated using diet.mod, diet.dat, and diet.run

Book Example: prod

prod.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: book example autogenerated using prod.mod, prod.dat, and prod.run
Author: N/A

Book Example: steel

steel.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: book example autogenerated using steel.mod, steel.dat, and steel.run
Author: N/A

Book Example: transp

transp.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
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

sched_numberof.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
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.

Capacity expansion of power generation

capacity_expansion.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
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.

Diet lecture

diet_case_study.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Diet case study

Diet model with Google Sheets

gspread.ipynb Open In Colab
Description: Diet model using Google Sheets

Efficient Frontier with Google Sheets

efficient_frontier.ipynb Open In Colab
Description: Efficient Frontier example using Google Sheets

Financial Portfolio Optimization with amplpy

amplpyfinance_vs_amplpy.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Financial Portfolio Optimization with amplpy and amplpyfinance

Google Hashcode 2022

practice_problem.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Google Hashcode 2022 Practice Problem

Hospitals-Residents MIP

hospitals_residents.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: hospitals-residents problem with ties problem solved with ampl and highs

Jupyter Notebook Integration

magics.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Jupyter Notebook Integration with amplpy

Multicommodity transportation problem

multmip1.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Multicommodity transportation model with binary variables

Network design with redundancy

electric_grid_with_redundancy.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
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.

Nonlinear transportation model

nltrans_lecture.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: book example autogenerated using nltransd.mod, nltrans.dat, and nltrans.run

Nonlinear transportation problem example

nltrans.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: book example autogenerated using nltransd.mod, nltrans.dat, and nltrans.run

Optimization Methods in Finance: Chapter 3

finance_opt_example_3_1.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Optimization Methods in Finance: Bond Dedication Problem.

Pattern Enumeration

pattern_enumeration.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Pattern enumeration example with amplpy

Pattern Generation

pattern_generation.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Pattern generation example with amplpy

Pricing and target-market

pricing_and_target_market.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Formulate a pricing optimization and target-market problem as a MILP.

Production model

production_model.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: generic model for production problem

Roll Cutting - Revision 1 & 2

pattern_tradeoff.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Pattern tradeoff example with amplpy

Simple sudoku solver using logical constraints (with GUI)

sudoku.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Simple sudoku solver using the alldiff operator; needs a solver supporting constraints programming or a MIP solver with automatic reformulation support (see [here](https://amplmp.readthedocs.io/) for more information). A little GUI implemented using ipywidgets helps with data visualization and specification.

Solving a nonogram puzzle

nonogram.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Model for solving nonogram puzzles autogenerated using nonogram.mod, nonogram.dat and nonogram.run.
Tags: ampl-only, mip

Steel industry problem

steel_lecture.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: model for steel production problem

Transportation problem

transp_lecture.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: an AMPL model for the transportation problem

Travelling Salesman Problem with subtour elimination

tsp_simple_cuts_generic.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: this example shows how to solve a TSP by eliminating subtours using amplpy and ampls
Tags: callbacks, tsp

VPSolver: Cutting & Packing Problems

vpsolver.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Solving cutting & packing problems using arc-flow formulations

amplpy setup & Quick Start

quickstart.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: amplpy setup and quick start

Tag list