AMPL Model Colaboratory

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. [See our Highlights]

You can use the Christmas notebook written by ChatGPT to get started:

Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
BTW: you can even ask ChatGPT to write models for you! If it makes mistakes you can ask for help in our new Discourse Forum!
the only 3 lines you need to use AMPL on Colab

Contents

Notebooks

AMPL - solve multiple models in parallel

multiproc.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Solve multiple AMPL models in parallel in Python with amplpy and the multiprocessing modules.

AMPL - spreadsheet handling with amplxl

amplxl.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Basic example of reading/writing data into/from a .xlsx spreadsheet with amplxl

AMPL Bin Packing Problem with GCG

bpp.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Dantzig-Wolfe decomposition for Bin Packing Problem with GCG

AMPL Capacitated p-Median Problem with GCG

cpmp.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Dantzig-Wolfe decomposition for Capacitated p-Median Problem with GCG

AMPL Christmas Model created by ChatGPT

AMPL Development Tutorial 1/6 – Capacitated Facility Location Problem

AMPL Development Tutorial 2/6 – Stochastic Capacitated Facility Location Problem

AMPL Development Tutorial 3/6 – Benders Decomposition via AMPL scripting

3_benders_stoch_floc.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: In this third installment of our six-part series, we continue our exploration by addressing the complexities introduced by the stochastic programming formulation presented in part two.

AMPL Development Tutorial 4/6 – Benders Decomposition via PYTHON scripting

4_benders_in_python_stoch_floc.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: In this fourth installment of our six-part series, we advance our exploration by demonstrating how to adapt our AMPL script for use with AMPL’s Python API.

AMPL Development Tutorial 5/6 – Parallelizing Subproblem Solves in Benders Decomposition

5_benders_parallel_stoch_floc.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: In the fifth installment of our six-part series, we delve deeper by showing how to evolve our Benders decomposition Python script from a serial execution to one that solves subproblems in parallel.

AMPL Development Tutorial 6/6 – Implementing Benders Decomposition with ampls

6_benders_ampls_stoch_floc.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: This concluding notebook in our six-part series delves into enhancing the efficiency of our decomposition algorithm by utilizing AMPL Solver Libraries (ampls).

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

Aircrew trainee scheduling with seniority constraints

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.

Containers scheduling

containers_scheduling.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Scheduling model for harbor operations. It is a problem with dependences between containers, which should be dispatch the fastest possible. We are using the MP solver interfaces to model a complex system using techniques from Constraint Programming, such as indicator constraints, and logical or and forall operators. After the model is written, a couple instances are presented and Highs/Gurobi MIP solvers are used to tackle the problem.

Debugging Model Infeasibility

debug_infeas.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: This notebook offers a concise guide on troubleshooting model infeasibility using AMPL’s presolve feature and other language capabilities.

Diet lecture

Diet model with Google Sheets

Dual-Donor Organ Exchange problem

Dual-Donor_Organ_Exchange.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Most transplants from living donors require only one donor for each procedure. There are, however, exceptions, including dual-graft liver transplantation, bilateral living-donor lobar lung transplantation, and simultaneous liver-kidney transplantation. For each of these procedures, grafts from two compatible living donors are transplanted. As such, these procedures are more involved from an organizational perspective than those with only one donor. Unfortunately, one or both of the donors can often be biologically incompatible with the intended recipient, precluding the transplantation.

Dynamic routing example

Dynamic_routing_example.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Example of interactive optimization with GUI using AMPL and Google Maps
Tags: amplpy, gui

Efficient Frontier with Google Sheets

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

Employee Scheduling Optimization

Employee_Scheduling.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Employee scheduling model from the Analytical Decision Modeling course at the Arizona State University.

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

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

Hydrothermal Scheduling Problem with Conic Programming

Introduction to Linear and Integer Programming

intro_to_linear_prorgramming.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Basic introduction to linear programming and AMPL via a lemonade stand example

Introduction to Mathematical Optimization

intro_to_optimization.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Basic introduction to optimization and AMPL via unconstrained optimization

Jupyter Notebook Integration

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

Largest small polygon

largest_small_polygon.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: lecture about models for the Largest Small Polygon Problem

Logistic Regression with amplpy

Magic sequences

magic_sequences.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Solving magic sequences through reinforced formulations and constrained programming. Some comparison between models and solvers is done, and we look into the “Another solution” problem for these sequences.

Multicommodity transportation problem

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

N-Queens

nqueens.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: How can N queens be placed on an NxN chessboard so that no two of them attack each other?

NFL Team Rating

NFL_Team_Rating.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: NFL Team Rating problem from the Analytical Decision Modeling course at the Arizona State University.

Network Linear Programs

network.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Basic introduction to network linear programms and AMPL via max flow and shortest path problems

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.

Optimization of an advertising campaign for launching a new product on the market

Advertising_campaign_colab.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: The modern world is unthinkable without advertising. Advertising is the engine of progress.

Optimize your Christmas Tree to Global Optimality

P-Median problem

p_median.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: this notebook states the p-median problem with a simple example, and a MIP formulation in amplpy. The problem is parametrized with a class, so it is easier to sample and replicate experiments. A graphical solution is plotted.

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

Plot feasible region

plot_feasible_region.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Plot the feasible region and optimal solution for a simple two variable model using AMPL’s Python API.
Tags: lecture, lp, simple

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: Basic introduction to AMPL’s indexed entities and the Pygwalker Python package via a lemonade stand example

Production model

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

Quick Start using Pandas dataframes

pandasdiet.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Quick Start using Pandas dataframes to load and retrieve data

Quick Start using lists and dictionaries

nativediet.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Quick Start using lists and dictionaries to load and retrieve data

Robust Linear Programming with Ellipsoidal Uncertainty

tip6_robust_linear_programming.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: AMPL Modeling Tips #6: Robust Linear Programming

Roll Cutting - Revision 1 & 2

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

Scheduling Multipurpose Batch Processes using State-Task Networks in Python

batch_processessing.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: The State-Task Network (STN) is an approach to modeling multipurpose batch process for the purpose of short term scheduling. It was first developed by Kondili, et al., in 1993, and subsequently developed and extended by others.

Simple sudoku solver using logical constraints (with GUI)

sudoku.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Simple sudoku model with two formulations: as a Constraint Programming problem using the alldiff operator and as a MIP. Note that the CP formulation is more natural but it needs a solver supporting logical constraints or a MIP solver with automatic reformulation support (see [here](https://amplmp.readthedocs.io/) for more information).

Solution check: discontinuous objective function

sol-check.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Pathological examples to illustrate MP solution checker and settings

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

Solving simple stochastic optimization problems with AMPL

newsvendor.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Examples of the Sample Average Approximation method and risk measures in AMPL

Steel industry problem

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

Sudoku Generator

sudoku_gen.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Generate Sudoku boards with unique solution via iterative method and mip formulation.

Supply chain network

supply_chain_simple_routes.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: Compute optimal routes to connect suppliers/demanding nodes in a network. Routes have an associated fixed and variable cost. There are different products to ship. The problem is formulated as a MIP with binary variables. Python data structures are used to load the data into the model.

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

Unit Commitment for Electrical Power Generation

unit_commitment.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab
Description: This notebook illustrates the power generation problem using AMPL. The original version featured the Gurobi solver. By default, this notebook uses the HiGHS and CBC solvers.

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