Book Example: steel#
Description: book example autogenerated using steel.mod, steel.dat, and steel.run
Tags: ampl-only, ampl-book
Notebook author: N/A
Model author: N/A
# Install dependencies
%pip install -q amplpy
# Google Colab & Kaggle integration
from amplpy import AMPL, ampl_notebook
ampl = ampl_notebook(
modules=["coin"], # modules to install
license_uuid="default", # license to use
) # instantiate AMPL object and register magics
Example: steel#
autogenerated using steel.mod, steel.dat, and steel.run
%%writefile steel.mod
set PROD; # products
param rate {PROD} > 0; # tons produced per hour
param avail >= 0; # hours available in week
param profit {PROD}; # profit per ton
param market {PROD} >= 0; # limit on tons sold in week
var Make {p in PROD} >= 0, <= market[p]; # tons produced
maximize Total_Profit: sum {p in PROD} profit[p] * Make[p];
# Objective: total profits from all products
subject to Time: sum {p in PROD} (1/rate[p]) * Make[p] <= avail;
# Constraint: total of hours used by all
# products may not exceed hours available
%%writefile steel.dat
data;
set PROD := bands coils;
param: rate profit market :=
bands 200 25 6000
coils 140 30 4000 ;
param avail := 40;
%%ampl_eval
model steel.mod;
data steel.dat;
option solver cbc;
solve;
display Make;
assert ampl.solve_result == "solved", ampl.solve_result